summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAudrius Meskauskas <audriusa@Bioinformatics.org>2006-03-24 17:40:24 +0000
committerAudrius Meskauskas <audriusa@Bioinformatics.org>2006-03-24 17:40:24 +0000
commit63f5926a4f85a4c5f4c8349a7d5bc985badd503f (patch)
treee459cef953f7bdc2a4d995b04143b2bcac9ff478
parentf370efa1358a912b3c57e4bce650babbebd59269 (diff)
downloadclasspath-63f5926a4f85a4c5f4c8349a7d5bc985badd503f.tar.gz
2006-03-24 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* gnu/java/rmi/activation/ActivationSystemTransient.java: Inherit from Activator. 2006-03-24 Audrius Meskauskas <AudriusA@Bioinformatics.org> * gnu/java/rmi/activation/DefaultActivationGroup.java (newInstance): Print debug message if debug flag is set. * gnu/java/rmi/activation/DefaultActivationSystem.java: Rewritten. * gnu/java/rmi/server/ActivatableServerRef.java (activate): assign detail, do not call iniCause(). (exportClass): New method. * gnu/java/rmi/server/CombinedClassLoader.java (constructor): Ignore null (bootstrap) class loader. * gnu/java/rmi/server/UnicastServerRef.java (methods, skel, stub, buildMethodHash, findStubSkelClass, getHelperClass): Changed visibility to protected. * java/rmi/activation/Activatable.java (export, register): Rewritten. (toStub): New method. * java/rmi/activation/ActivationGroup.java (getSystem): Rewritten. * java/rmi/activation/ActivationSystem.java (SYSTEM_PORT): Explained property java.rmi.activation.port. Applying two patches toghether because the intermediate version does not build.
-rw-r--r--ChangeLog23
-rw-r--r--gnu/java/rmi/activation/ActivationSystemTransient.java3
-rw-r--r--gnu/java/rmi/activation/DefaultActivationGroup.java3
-rw-r--r--gnu/java/rmi/activation/DefaultActivationSystem.java75
-rw-r--r--gnu/java/rmi/server/ActivatableServerRef.java54
-rw-r--r--gnu/java/rmi/server/CombinedClassLoader.java2
-rw-r--r--gnu/java/rmi/server/UnicastServerRef.java12
-rw-r--r--java/rmi/activation/Activatable.java50
-rw-r--r--java/rmi/activation/ActivationGroup.java16
-rw-r--r--java/rmi/activation/ActivationSystem.java5
10 files changed, 210 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index edef9d0e4..8496b542e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2006-03-24 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ * gnu/java/rmi/activation/ActivationSystemTransient.java:
+ Inherit from Activator.
+
+2006-03-24 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ * gnu/java/rmi/activation/DefaultActivationGroup.java (newInstance):
+ Print debug message if debug flag is set.
+ * gnu/java/rmi/activation/DefaultActivationSystem.java: Rewritten.
+ * gnu/java/rmi/server/ActivatableServerRef.java (activate): assign
+ detail, do not call iniCause(). (exportClass): New method.
+ * gnu/java/rmi/server/CombinedClassLoader.java (constructor):
+ Ignore null (bootstrap) class loader.
+ * gnu/java/rmi/server/UnicastServerRef.java (methods, skel, stub,
+ buildMethodHash, findStubSkelClass, getHelperClass): Changed
+ visibility to protected.
+ * java/rmi/activation/Activatable.java (export, register): Rewritten.
+ (toStub): New method.
+ * java/rmi/activation/ActivationGroup.java (getSystem): Rewritten.
+ * java/rmi/activation/ActivationSystem.java (SYSTEM_PORT):
+ Explained property java.rmi.activation.port.
+
2006-03-24 Tom Tromey <tromey@redhat.com>
* .externalToolBuilders/CreateLocaleData.launch: Updated.
diff --git a/gnu/java/rmi/activation/ActivationSystemTransient.java b/gnu/java/rmi/activation/ActivationSystemTransient.java
index 3ef5685a5..ea31e4bdf 100644
--- a/gnu/java/rmi/activation/ActivationSystemTransient.java
+++ b/gnu/java/rmi/activation/ActivationSystemTransient.java
@@ -49,6 +49,7 @@ import java.rmi.activation.ActivationID;
import java.rmi.activation.ActivationInstantiator;
import java.rmi.activation.ActivationMonitor;
import java.rmi.activation.ActivationSystem;
+import java.rmi.activation.Activator;
import java.rmi.activation.UnknownGroupException;
import java.rmi.activation.UnknownObjectException;
import java.util.HashMap;
@@ -63,7 +64,7 @@ import java.util.Map;
*/
public class ActivationSystemTransient
extends DefaultActivationSystem
- implements ActivationSystem, ActivationMonitor
+ implements ActivationSystem, ActivationMonitor, Activator
{
/**
* Maps group identifiers into group descriptions.
diff --git a/gnu/java/rmi/activation/DefaultActivationGroup.java b/gnu/java/rmi/activation/DefaultActivationGroup.java
index 95c5a4139..dc2a3221a 100644
--- a/gnu/java/rmi/activation/DefaultActivationGroup.java
+++ b/gnu/java/rmi/activation/DefaultActivationGroup.java
@@ -120,6 +120,9 @@ public class DefaultActivationGroup
{
try
{
+ if (ActivationSystemTransient.debug)
+ System.out.println("Instantiating "+desc.getClassName());
+
Remote object;
Class objectClass;
diff --git a/gnu/java/rmi/activation/DefaultActivationSystem.java b/gnu/java/rmi/activation/DefaultActivationSystem.java
index 75fb45160..754b5dcb9 100644
--- a/gnu/java/rmi/activation/DefaultActivationSystem.java
+++ b/gnu/java/rmi/activation/DefaultActivationSystem.java
@@ -39,19 +39,80 @@ exception statement from your version. */
package gnu.java.rmi.activation;
import java.rmi.activation.ActivationSystem;
-import java.rmi.activation.Activator;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
/**
- * The default activation system for this jre.
+ * Finds and returns the default activation system for this jre.
*
- * @author Audrius Meskauskas (audriusa@bioinformatics.org)
+ * @author Audrius Meskauskas (audriusa@bioinformatics.org)
*/
public abstract class DefaultActivationSystem
- implements ActivationSystem, Activator
{
/**
- * The singleton instance of the default activation system.
+ * The activation system (assigned if once found).
*/
- public static final ActivationSystem singleton
- = ActivationSystemTransient.getInstance();
+ static ActivationSystem system;
+
+ /**
+ * The default activation registry port.
+ */
+ static int ACTIVATION_REGISTRY_PORT;
+
+ /**
+ * The name of the activation system registry port property.
+ */
+ static String AS_PORT_PROPERTY = "java.rmi.activation.port";
+
+ /**
+ * The defalut name of the activation system in the activation registry.
+ */
+ static String ACTIVATION_SYSTEM_NAME = "java.rmi.activation.ActivationSystem";
+
+ /**
+ * Get the activation system, default for this jre. If no external activation
+ * system exists, the internal activation system will be activated. This
+ * internal system is limited in capabilities and should be used exclusively
+ * for automated testing, to avoid necessity of starting rmi daemon during
+ * testing process.
+ */
+ public static ActivationSystem get()
+ {
+ if (system == null)
+ try
+ {
+ // Obtain the port:
+ String asr = System.getProperty("java.rmi.activation.port");
+
+ if (asr != null)
+ {
+ try
+ {
+ ACTIVATION_REGISTRY_PORT = Integer.parseInt(asr);
+ if (ACTIVATION_REGISTRY_PORT <= 0)
+ throw new InternalError("Invalid " + asr + " value, "
+ + ACTIVATION_REGISTRY_PORT);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new InternalError("Unable to parse " + asr
+ + " to integer");
+ }
+ }
+ else
+ ACTIVATION_REGISTRY_PORT = ActivationSystem.SYSTEM_PORT;
+
+ // Expect the naming service running first.
+ // The local host may want to use the shared registry
+ Registry r = LocateRegistry.getRegistry(ACTIVATION_REGISTRY_PORT);
+ ActivationSystem system = (ActivationSystem) r.lookup(ACTIVATION_SYSTEM_NAME);
+ return system;
+ }
+ catch (Exception ex)
+ {
+ system = ActivationSystemTransient.getInstance();
+ }
+
+ return system;
+ }
}
diff --git a/gnu/java/rmi/server/ActivatableServerRef.java b/gnu/java/rmi/server/ActivatableServerRef.java
index 6463f40d2..d89e351d3 100644
--- a/gnu/java/rmi/server/ActivatableServerRef.java
+++ b/gnu/java/rmi/server/ActivatableServerRef.java
@@ -43,6 +43,8 @@ import java.rmi.RemoteException;
import java.rmi.activation.ActivationID;
import java.rmi.server.ObjID;
import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.Skeleton;
/**
* The activatable server reference works like UnicastServerReference, but it
@@ -117,7 +119,7 @@ public class ActivatableServerRef extends UnicastServerRef
catch (Exception exc)
{
RemoteException rx = new RemoteException("Activation failed.");
- rx.initCause(exc);
+ rx.detail = exc;
throw rx;
}
}
@@ -143,4 +145,54 @@ public class ActivatableServerRef extends UnicastServerRef
UnicastServer.registerActivatable(this);
return r;
}
+
+ /**
+ * Export object and ensure it is present in the server activation table as
+ * well.
+ *
+ * @param aClass the class being exported, must implement Remote.
+ */
+ public Remote exportClass(Class aClass) throws RemoteException
+ {
+ if (!Remote.class.isAssignableFrom(aClass))
+ throw new InternalError(aClass.getName()+" must implement Remote");
+
+ String ignoreStubs;
+
+ ClassLoader loader =aClass.getClassLoader();
+
+ // Stubs are always searched for the bootstrap classes that may have
+ // obsolete pattern and may still need also skeletons.
+ if (loader==null)
+ ignoreStubs = "false";
+ else
+ ignoreStubs = System.getProperty("java.rmi.server.ignoreStubClasses",
+ "false");
+
+ if (! ignoreStubs.equals("true"))
+ {
+ // Find and install the stub
+ Class cls = aClass;
+
+ // where ist the _Stub? (check superclasses also)
+ Class expCls = expCls = findStubSkelClass(cls);
+
+ if (expCls != null)
+ {
+ stub = (RemoteStub) getHelperClass(expCls, "_Stub");
+ // Find and install the skeleton (if there is one)
+ skel = (Skeleton) getHelperClass(expCls, "_Skel");
+ }
+ }
+
+ if (stub == null)
+ stub = createProxyStub(aClass, this);
+
+ // Build hash of methods which may be called.
+ buildMethodHash(aClass, true);
+
+ UnicastServer.registerActivatable(this);
+ return stub;
+ }
+
}
diff --git a/gnu/java/rmi/server/CombinedClassLoader.java b/gnu/java/rmi/server/CombinedClassLoader.java
index efffda4c6..6225fb30b 100644
--- a/gnu/java/rmi/server/CombinedClassLoader.java
+++ b/gnu/java/rmi/server/CombinedClassLoader.java
@@ -77,7 +77,7 @@ public class CombinedClassLoader extends ClassLoader
while (iter.hasNext())
{
cl = iter.next();
- if (!sLoaders.contains(cl))
+ if (cl!=null && !sLoaders.contains(cl))
sLoaders.add(cl);
}
diff --git a/gnu/java/rmi/server/UnicastServerRef.java b/gnu/java/rmi/server/UnicastServerRef.java
index 237e6d94d..cd891a1aa 100644
--- a/gnu/java/rmi/server/UnicastServerRef.java
+++ b/gnu/java/rmi/server/UnicastServerRef.java
@@ -84,18 +84,18 @@ public class UnicastServerRef
/**
* The skeleton (if any), associated with the exported remote object.
*/
- private Skeleton skel;
+ protected Skeleton skel;
/**
* The stub, associated with the exported remote object (may be proxy class).
*/
- private Remote stub;
+ protected Remote stub;
/**
* The method table (RMI hash code to method) of the methods of the
* exported object.
*/
- private Hashtable methods = new Hashtable();
+ protected Hashtable methods = new Hashtable();
/**
* Used by serialization.
@@ -205,7 +205,7 @@ public class UnicastServerRef
*
* @return the class having stub defined, null if none.
*/
- private Class findStubSkelClass(Class startCls)
+ protected Class findStubSkelClass(Class startCls)
{
Class cls = startCls;
@@ -245,7 +245,7 @@ public class UnicastServerRef
* @return the instantiated instance of the helper class or null if the
* helper class cannot be found or instantiated.
*/
- private Object getHelperClass(Class cls, String type)
+ protected Object getHelperClass(Class cls, String type)
{
try
{
@@ -313,7 +313,7 @@ public class UnicastServerRef
* @param build if true, the class methods are added to the table. If
* false, they are removed from the table.
*/
- private void buildMethodHash(Class cls, boolean build)
+ protected void buildMethodHash(Class cls, boolean build)
{
Method[] meths = cls.getMethods();
for (int i = 0; i < meths.length; i++)
diff --git a/java/rmi/activation/Activatable.java b/java/rmi/activation/Activatable.java
index f7fe1ad55..472c65c11 100644
--- a/java/rmi/activation/Activatable.java
+++ b/java/rmi/activation/Activatable.java
@@ -232,8 +232,8 @@ public abstract class Activatable
}
/**
- * This method registers an activatable object. The object is expected to
- * be on the anonymous port (null client and server socket factories).
+ * This method registers an activatable object. The object is expected to be
+ * on the anonymous port (null client and server socket factories).
*
* @param desc the object description.
* @return the remote stub for the activatable object (the first call on this
@@ -246,7 +246,17 @@ public abstract class Activatable
throws UnknownGroupException, ActivationException, RemoteException
{
ActivationID id = obtainId(desc);
- return id.activate(false);
+ try
+ {
+ return toStub(
+ id,
+ Thread.currentThread().getContextClassLoader().loadClass(
+ desc.getClassName()));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ActivationException("Class not found: "+desc.getClassName());
+ }
}
/**
@@ -456,16 +466,9 @@ public abstract class Activatable
RMIServerSocketFactory serverSocketFactory)
throws RemoteException
{
- UnicastServerRef sref = null;
- if (obj instanceof RemoteObject)
- sref = (UnicastServerRef) ((RemoteObject) obj).getRef();
-
- if (sref == null)
- sref = new ActivatableServerRef(makeId(id), id, port, serverSocketFactory);
-
- Remote stub = sref.exportObject(obj);
- // addStub(obj, stub); // need probably the stub repository elsewhere
- return stub;
+ ActivatableServerRef sref = null;
+ sref = new ActivatableServerRef(makeId(id), id, port, serverSocketFactory);
+ return sref.exportObject(obj);
}
/**
@@ -504,4 +507,25 @@ public abstract class Activatable
return id;
}
+ /**
+ * Connect the object to the UnicastServer (export), but not activate it.
+ * The object will be activated on the first call.
+ */
+ static Remote toStub(ActivationID anId, Class stubFor)
+ {
+ try
+ {
+ ActivatableServerRef asr =
+ new ActivatableServerRef(makeId(anId), anId, 0, null);
+ UnicastServer.exportActivatableObject(asr);
+ return asr.exportClass(stubFor);
+ }
+ catch (RemoteException e)
+ {
+ InternalError ierr = new InternalError(
+ "Failed to obtain activatable stub");
+ ierr.initCause(e);
+ throw ierr;
+ }
+ }
}
diff --git a/java/rmi/activation/ActivationGroup.java b/java/rmi/activation/ActivationGroup.java
index f90300acc..2fc438a8d 100644
--- a/java/rmi/activation/ActivationGroup.java
+++ b/java/rmi/activation/ActivationGroup.java
@@ -281,8 +281,18 @@ public abstract class ActivationGroup
}
/**
- * Get the current activation system. If the system is not set via this
- * method, the default implementatin for this virtual machine is returned.
+ * Get the current activation system. If the system is not set via
+ * {@link #setSystem} method, the default system for this virtual machine is
+ * returned. The default system is first searched by name
+ * "java.rmi.activation.ActivationSystem" on the activation registry port. The
+ * default value of the activation registry port is
+ * {@link ActivationSystem#SYSTEM_PORT}, but it can be changed by putting the
+ * system property java.rmi.activation.port. Both activation system and
+ * activation registry are provided by the RMI daemon tool, RMID, if it is
+ * running on the local host. If the RMID is not running, the internal
+ * transient activation system will be created and returned. This internal
+ * system is highly limited in in capabilities and is not intended to be used
+ * anywhere apart automated testing.
*
* @return the activation system for this virtual machine
* @throws ActivationException
@@ -290,7 +300,7 @@ public abstract class ActivationGroup
public static ActivationSystem getSystem() throws ActivationException
{
if (system == null)
- return DefaultActivationSystem.singleton;
+ return DefaultActivationSystem.get();
else
return system;
}
diff --git a/java/rmi/activation/ActivationSystem.java b/java/rmi/activation/ActivationSystem.java
index ab56b4692..719676445 100644
--- a/java/rmi/activation/ActivationSystem.java
+++ b/java/rmi/activation/ActivationSystem.java
@@ -55,12 +55,15 @@ import java.rmi.RemoteException;
* methods in this interface throw {@link java.rmi.AccessException} if called
* from the client that is not reside on the same host as the activation system.
* </p>
+ * @see ActivationGroup#getSystem()
*/
public interface ActivationSystem
extends Remote
{
/**
- * The port, used by the activation system (1098 by default).
+ * The port, used by the activation system. The value is equal to 1098 by
+ * default, but it can be changed by putting the system property
+ * .
*/
int SYSTEM_PORT = 1098;