Please review any and all PUBLIC repositories, groups, and associated files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Commit 47b44889 authored by Norbraten, Terry's avatar Norbraten, Terry
Browse files

[Terry N.] alternative for deprecated Object.finalize

parent 86170c8e
......@@ -12,6 +12,7 @@ package org.web3d.vrml.scripting.external.eai;
*
*****************************************************************************/
// Local imports
import vrml.eai.field.EventOut;
import vrml.eai.*;
import vrml.eai.field.EventIn;
......@@ -28,7 +29,8 @@ import org.web3d.vrml.nodes.VRMLNodeType;
* @version 1.0
*/
public class EAINode extends Node {
public class EAINode extends Node implements Runnable {
/** The VRMLNodeType instance that this node maps to */
VRMLNodeType realNode;
......@@ -56,10 +58,13 @@ public class EAINode extends Node {
realNode=theRealNode;
theNodeFactory=aNodeFactory;
theFieldFactory=aFieldFactory;
Thread t = new Thread(Node.class.getName() + " shutdown");
t.setDaemon(true);
Runtime r = Runtime.getRuntime();
r.addShutdownHook(t);
}
/**
* @return * @see vrml.eai.Node#getEventIn */
@Override
public EventIn getEventIn(String eventName)
throws vrml.eai.field.InvalidEventInException,
......@@ -70,8 +75,6 @@ public class EAINode extends Node {
return theFieldFactory.getEventIn(realNode, eventName);
}
/**
* @return * @see vrml.eai.Node#getEventOut */
@Override
public EventOut getEventOut(String eventName)
throws vrml.eai.field.InvalidEventOutException,
......@@ -82,8 +85,6 @@ public class EAINode extends Node {
return theFieldFactory.getEventOut(realNode, eventName);
}
/**
* @return * @see vrml.eai.Node#getType */
@Override
public String getType() throws vrml.eai.InvalidNodeException {
/* This should work for most of the nodes */
......@@ -98,8 +99,6 @@ public class EAINode extends Node {
return realNode;
}
/** Two EAINode's are equal if they point to the same actual node.
* @return */
@Override
public boolean equals(Object other) {
if (other instanceof EAINode) {
......@@ -112,22 +111,18 @@ public class EAINode extends Node {
return super.equals(other);
}
/** @see vrml.eai.Node#dispose
* Calling dispose gets rid of any resource allocated to this object, and
* releases any references to actual VRML objects. Calling any other
* methods of this object after dispose (including this one) will result in
* vrml.eai.InvalidNodeException being thrown. The only exception is
* equals, because that just seemed silly.
* <p>
*/
@Override
public void dispose() throws vrml.eai.InvalidNodeException {
if (realNode==null)
throw new vrml.eai.InvalidNodeException();
else {
}
realNode=null;
}
@Override
public void run() {
dispose();
}
}
......@@ -12,6 +12,7 @@
package org.web3d.vrml.scripting.external.neteai;
// Local imports
import vrml.eai.InvalidNodeException;
import vrml.eai.Node;
import vrml.eai.field.EventIn;
......@@ -23,7 +24,7 @@ import vrml.eai.field.InvalidEventOutException;
* @author vender
* NetEAINode is the node wrapper for the networked version of the EAI classes.
*/
public class NetEAINode extends Node {
public class NetEAINode extends Node implements Runnable {
/** The type name for the node */
String nodeType;
......@@ -41,10 +42,13 @@ public class NetEAINode extends Node {
NetEAINode(int ID, FieldAndNodeRequestProcessor processor) {
nodeID=ID;
requestProcessor=processor;
Thread t = new Thread(Node.class.getName() + " shutdown");
t.setDaemon(true);
Runtime r = Runtime.getRuntime();
r.addShutdownHook(t);
}
/**
* @return * @see vrml.eai.Node#getType() */
@Override
public String getType() throws InvalidNodeException {
if (nodeType==null)
......@@ -52,30 +56,28 @@ public class NetEAINode extends Node {
return nodeType;
}
/**
* @return * @see vrml.eai.Node#getEventIn(java.lang.String) */
@Override
public EventIn getEventIn(String name) throws InvalidEventInException,
InvalidNodeException {
return requestProcessor.getEventIn(nodeID,name);
}
/**
* @return * @see vrml.eai.Node#getEventOut(java.lang.String) */
@Override
public EventOut getEventOut(String name) throws InvalidEventOutException,
InvalidNodeException {
return requestProcessor.getEventOut(nodeID,name);
}
/** * @see vrml.eai.Node#dispose() */
@Override
public void dispose() throws InvalidNodeException {
requestProcessor.disposeNode(nodeID);
}
@Override
public void run() {
dispose();
}
/**
* @return * @see java.lang.Object#equals(java.lang.Object) */
@Override
public boolean equals(Object obj) {
if (obj instanceof NetEAINode)
......
......@@ -226,16 +226,16 @@ public class LoaderThreadPool {
* Ensure all threads are running.
*/
public void restartThreads() {
// TODO: Deprecated in JDK16. How to compensate?
if (threadGroup.isDestroyed()) {
threadGroup = null;
threadPool = new LoaderThreadPool();
}
int size = loaders.length;
for(int i = size; --i >= 0;) {
if(!loaders[i].isAlive())
loaders[i] = new ContentLoader(threadGroup,
pending,
inProgress);
for(ContentLoader loader : loaders) {
if(!loader.isAlive())
loader = new ContentLoader(threadGroup, pending, inProgress);
}
}
}
......@@ -96,24 +96,6 @@ public abstract class Node
*/
public abstract void dispose()
throws InvalidNodeException;
/**
* Clean up any resources used by this class. Explicitly calls the dispose
* method of this class to ensure all resources as disposed of
*/
@Override
public void finalize()
{
try {
dispose();
} finally {
try {
super.finalize();
} catch (Throwable ex) {
Logger.getLogger(Node.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment