summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/rmi
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/rmi')
-rw-r--r--libjava/classpath/java/rmi/AccessException.java5
-rw-r--r--libjava/classpath/java/rmi/AlreadyBoundException.java7
-rw-r--r--libjava/classpath/java/rmi/MarshalledObject.java103
-rw-r--r--libjava/classpath/java/rmi/Naming.java226
-rw-r--r--libjava/classpath/java/rmi/NoSuchObjectException.java9
-rw-r--r--libjava/classpath/java/rmi/NotBoundException.java11
-rw-r--r--libjava/classpath/java/rmi/RMISecurityException.java14
-rw-r--r--libjava/classpath/java/rmi/Remote.java19
-rw-r--r--libjava/classpath/java/rmi/RemoteException.java5
-rw-r--r--libjava/classpath/java/rmi/StubNotFoundException.java7
-rw-r--r--libjava/classpath/java/rmi/dgc/DGC.java39
-rw-r--r--libjava/classpath/java/rmi/dgc/Lease.java69
-rw-r--r--libjava/classpath/java/rmi/package.html2
-rw-r--r--libjava/classpath/java/rmi/registry/Registry.java24
-rw-r--r--libjava/classpath/java/rmi/server/RMIClassLoader.java30
-rw-r--r--libjava/classpath/java/rmi/server/RemoteObjectInvocationHandler.java221
-rw-r--r--libjava/classpath/java/rmi/server/RemoteRef.java64
-rw-r--r--libjava/classpath/java/rmi/server/RemoteStub.java23
-rw-r--r--libjava/classpath/java/rmi/server/UnicastRemoteObject.java213
19 files changed, 846 insertions, 245 deletions
diff --git a/libjava/classpath/java/rmi/AccessException.java b/libjava/classpath/java/rmi/AccessException.java
index b470780046c..40954dfd3e1 100644
--- a/libjava/classpath/java/rmi/AccessException.java
+++ b/libjava/classpath/java/rmi/AccessException.java
@@ -1,5 +1,6 @@
/* AccessException.java -- thrown if the caller does not have access
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -43,7 +44,7 @@ package java.rmi;
*
* @author unknown
* @see Naming
- * @see ActivationSystem
+ * @see java.rmi.activation.ActivationSystem
* @since 1.1
*/
public class AccessException extends RemoteException
diff --git a/libjava/classpath/java/rmi/AlreadyBoundException.java b/libjava/classpath/java/rmi/AlreadyBoundException.java
index 091c0ee5862..10f6e4cec98 100644
--- a/libjava/classpath/java/rmi/AlreadyBoundException.java
+++ b/libjava/classpath/java/rmi/AlreadyBoundException.java
@@ -1,5 +1,6 @@
/* AlreadyBoundException.java -- thrown if a binding is already bound
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,8 +43,8 @@ package java.rmi;
* bound.
*
* @author unknown
- * @see Naming#bind(String, Remote)
- * @see Registry#bind(String, Remote)
+ * @see java.rmi.Naming#bind(String, Remote)
+ * @see java.rmi.registry.Registry#bind(String, Remote)
* @since 1.1
* @status updated to 1.4
*/
diff --git a/libjava/classpath/java/rmi/MarshalledObject.java b/libjava/classpath/java/rmi/MarshalledObject.java
index 9ec0ace0e70..e1a30f5f005 100644
--- a/libjava/classpath/java/rmi/MarshalledObject.java
+++ b/libjava/classpath/java/rmi/MarshalledObject.java
@@ -1,5 +1,6 @@
/* MarshalledObject.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,38 +43,68 @@ import gnu.java.rmi.RMIMarshalledObjectInputStream;
import gnu.java.rmi.RMIMarshalledObjectOutputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.Serializable;
/**
- * FIXME - doc missing
+ * A <code>MarshalledObject</code> consists of a serialized object which is
+ * marshalled according to the RMI specification.
+ * <p>
+ * An object passed to the constructor is serialized and tagged with the needed
+ * URL to retrieve its class definition for remote usage. If the object is a
+ * remote reference its stub is serialized instead. The instance of this
+ * marshalled object can be later retrieved by its <code>get()</code> method.
+ * </p>
+ *
+ * @author unknown
*/
-public final class MarshalledObject implements Serializable
+public final class MarshalledObject
+ implements Serializable
{
- //The following fields are from Java API Documentation "Serialized form"
+ // The following fields are from Java API Documentation "Serialized form"
private static final long serialVersionUID = 8988374069173025854L;
+
byte[] objBytes;
byte[] locBytes;
int hash;
-
- public MarshalledObject(Object obj) throws java.io.IOException
+
+ /**
+ * Constructs a <code>MarshalledObject</code> from the given object.
+ *
+ * @param obj the object to marshal
+ * @throws IOException if an I/O error during serialization occurs.
+ */
+ public MarshalledObject(Object obj) throws IOException
{
ByteArrayOutputStream objStream = new ByteArrayOutputStream();
- RMIMarshalledObjectOutputStream stream = new RMIMarshalledObjectOutputStream(objStream);
+ RMIMarshalledObjectOutputStream stream =
+ new RMIMarshalledObjectOutputStream(objStream);
stream.writeObject(obj);
stream.flush();
objBytes = objStream.toByteArray();
locBytes = stream.getLocBytes();
-
- //The following algorithm of calculating hashCode is similar to String
+
+ // The following algorithm of calculating hashCode is similar to String
hash = 0;
for (int i = 0; i < objBytes.length; i++)
hash = hash * 31 + objBytes[i];
- if(locBytes != null)
+
+ if (locBytes != null)
for (int i = 0; i < locBytes.length; i++)
- hash = hash * 31 + locBytes[i];
+ hash = hash * 31 + locBytes[i];
}
-
- public boolean equals(Object obj)
+
+ /**
+ * Checks if the given object is equal to this marshalled object.
+ *
+ * <p>Marshalled objects are considered equal if they contain the
+ * same serialized object. Codebase annotations where the class
+ * definition can be downloaded are ignored in the equals test.</p>
+ *
+ * @param obj the object to compare.
+ * @return <code>true</code> if equal, <code>false</code> otherwise.
+ */
+ public boolean equals(Object obj)
{
if (! (obj instanceof MarshalledObject))
return false;
@@ -81,33 +112,43 @@ public final class MarshalledObject implements Serializable
// hashCode even differs, don't do the time-consuming comparisons
if (obj.hashCode() != hash)
return false;
-
- MarshalledObject aobj = (MarshalledObject)obj;
+
+ MarshalledObject aobj = (MarshalledObject) obj;
if (objBytes == null || aobj.objBytes == null)
return objBytes == aobj.objBytes;
if (objBytes.length != aobj.objBytes.length)
return false;
- for (int i = 0; i < objBytes.length; i++)
+ for (int i = 0; i < objBytes.length; i++)
{
- if (objBytes[i] != aobj.objBytes[i])
- return false;
+ if (objBytes[i] != aobj.objBytes[i])
+ return false;
}
// Ignore comparison of locBytes(annotation)
return true;
}
-
-public Object get()
- throws java.io.IOException, java.lang.ClassNotFoundException
-{
- if(objBytes == null)
- return null;
- RMIMarshalledObjectInputStream stream =
- new RMIMarshalledObjectInputStream(objBytes, locBytes);
- return stream.readObject();
-}
-
- public int hashCode() {
+
+ /**
+ * Constructs and returns a copy of the internal serialized object.
+ *
+ * @return The deserialized object.
+ *
+ * @throws IOException if an I/O exception occurs during deserialization.
+ * @throws ClassNotFoundException if the class of the deserialized object
+ * cannot be found.
+ */
+ public Object get() throws IOException, ClassNotFoundException
+ {
+ if (objBytes == null)
+ return null;
+
+ RMIMarshalledObjectInputStream stream =
+ new RMIMarshalledObjectInputStream(objBytes, locBytes);
+ return stream.readObject();
+ }
+
+ public int hashCode()
+ {
return hash;
}
-
+
}
diff --git a/libjava/classpath/java/rmi/Naming.java b/libjava/classpath/java/rmi/Naming.java
index d48df069d8d..b605da70d12 100644
--- a/libjava/classpath/java/rmi/Naming.java
+++ b/libjava/classpath/java/rmi/Naming.java
@@ -1,5 +1,6 @@
/* Naming.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -76,136 +77,150 @@ import java.rmi.registry.Registry;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.1
*/
-public final class Naming {
-
+public final class Naming
+{
/**
* This class isn't intended to be instantiated.
*/
- private Naming() {}
+ private Naming()
+ {
+ }
-/**
- * Looks for the remote object that is associated with the named service.
- * Name and location is given in form of a URL without a scheme:
- *
- * <pre>
- * //host:port/service-name
- * </pre>
- *
- * The port is optional.
- *
- * @param name the service name and location
- * @return Remote-object that implements the named service
- * @throws NotBoundException if no object implements the service
- * @throws MalformedURLException
- * @throws RemoteException
- */
-public static Remote lookup(String name) throws NotBoundException, MalformedURLException, RemoteException {
- URL u = parseURL(name);
- String serviceName = getName(u);
- return (getRegistry(u).lookup(serviceName));
-}
+ /**
+ * Looks for the remote object that is associated with the named service.
+ * Name and location is given in form of a URL without a scheme:
+ *
+ * <pre>
+ * //host:port/service-name
+ * </pre>
+ *
+ * The port is optional.
+ *
+ * @param name the service name and location
+ * @return Remote-object that implements the named service
+ * @throws NotBoundException if no object implements the service
+ * @throws MalformedURLException
+ * @throws RemoteException
+ */
+ public static Remote lookup(String name) throws NotBoundException,
+ MalformedURLException, RemoteException
+ {
+ URL u = parseURL(name);
+ String serviceName = getName(u);
+ return (getRegistry(u).lookup(serviceName));
+ }
-/**
- * Try to bind the given object to the given service name.
- * @param name
- * @param obj
- * @throws AlreadyBoundException
- * @throws MalformedURLException
- * @throws RemoteException
- */
-public static void bind(String name, Remote obj) throws AlreadyBoundException, MalformedURLException, RemoteException {
- URL u = parseURL(name);
- String serviceName = getName(u);
- getRegistry(u).bind(serviceName, obj);
-}
+ /**
+ * Try to bind the given object to the given service name.
+ *
+ * @param name
+ * @param obj
+ * @throws AlreadyBoundException
+ * @throws MalformedURLException
+ * @throws RemoteException
+ */
+ public static void bind(String name, Remote obj)
+ throws AlreadyBoundException, MalformedURLException, RemoteException
+ {
+ URL u = parseURL(name);
+ String serviceName = getName(u);
+ getRegistry(u).bind(serviceName, obj);
+ }
-/**
- * Remove a binding for a given service name.
- * @param name
- * @throws RemoteException
- * @throws NotBoundException
- * @throws MalformedURLException
- */
-public static void unbind(String name) throws RemoteException, NotBoundException, MalformedURLException {
- URL u = parseURL(name);
- String serviceName = getName(u);
- getRegistry(u).unbind(serviceName);
-}
+ /**
+ * Remove a binding for a given service name.
+ *
+ * @param name
+ * @throws RemoteException
+ * @throws NotBoundException
+ * @throws MalformedURLException
+ */
+ public static void unbind(String name) throws RemoteException,
+ NotBoundException, MalformedURLException
+ {
+ URL u = parseURL(name);
+ String serviceName = getName(u);
+ getRegistry(u).unbind(serviceName);
+ }
-/**
- * Forces the binding between the given Remote-object and the given service name, even
- * if there was already an object bound to this name.
- * @param name
- * @param obj
- * @throws RemoteException
- * @throws MalformedURLException
- */
-public static void rebind(String name, Remote obj) throws RemoteException, MalformedURLException {
- URL u = parseURL(name);
- String serviceName = getName(u);
- getRegistry(u).rebind(serviceName, obj);
-}
+ /**
+ * Forces the binding between the given Remote-object and the given service
+ * name, even if there was already an object bound to this name.
+ *
+ * @param name
+ * @param obj
+ * @throws RemoteException
+ * @throws MalformedURLException
+ */
+ public static void rebind(String name, Remote obj) throws RemoteException,
+ MalformedURLException
+ {
+ URL u = parseURL(name);
+ String serviceName = getName(u);
+ getRegistry(u).rebind(serviceName, obj);
+ }
-/**
- * Lists all services at the named registry.
- * @param name url that specifies the registry
- * @return list of services at the name registry
- * @throws RemoteException
- * @throws MalformedURLException
- */
-public static String[] list(String name) throws RemoteException, MalformedURLException {
- return (getRegistry(parseURL(name)).list());
-}
+ /**
+ * Lists all services at the named registry.
+ *
+ * @param name url that specifies the registry
+ * @return list of services at the name registry
+ * @throws RemoteException
+ * @throws MalformedURLException
+ */
+ public static String[] list(String name) throws RemoteException,
+ MalformedURLException
+ {
+ return (getRegistry(parseURL(name)).list());
+ }
-private static Registry getRegistry(URL u) throws RemoteException {
- if (u.getPort() == -1) {
- return (LocateRegistry.getRegistry(u.getHost()));
- }
- else {
- return (LocateRegistry.getRegistry(u.getHost(), u.getPort()));
- }
-}
+ private static Registry getRegistry(URL u) throws RemoteException
+ {
+ if (u.getPort() == - 1)
+ {
+ return (LocateRegistry.getRegistry(u.getHost()));
+ }
+ else
+ {
+ return (LocateRegistry.getRegistry(u.getHost(), u.getPort()));
+ }
+ }
/**
- * Parses the supplied URL and converts it to use the HTTP
- * protocol. From an RMI perspective, the scheme is irrelevant
- * and we want to be able to create a URL for which a handler is
- * available.
- *
+ * Parses the supplied URL and converts it to use the HTTP protocol. From an
+ * RMI perspective, the scheme is irrelevant and we want to be able to create
+ * a URL for which a handler is available.
+ *
* @param name the URL in String form.
* @throws MalformedURLException if the URL is invalid.
*/
- private static URL parseURL(String name)
- throws MalformedURLException
+ private static URL parseURL(String name) throws MalformedURLException
{
try
{
- URI uri = new URI(name);
- String host = uri.getHost();
- int port = uri.getPort();
- String query = uri.getQuery();
- String path = uri.getPath();
- return new URL("http",
- (host == null ? "localhost" : host),
- (port == -1 ? 1099 : port),
- uri.getPath() + (query == null ? "" : query));
+ URI uri = new URI(name);
+ String host = uri.getHost();
+ int port = uri.getPort();
+ String query = uri.getQuery();
+ String path = uri.getPath();
+ return new URL("http", (host == null ? "localhost" : host),
+ (port == - 1 ? 1099 : port), uri.getPath()
+ + (query == null ? "" : query));
}
catch (URISyntaxException e)
{
- throw new MalformedURLException("The URL syntax was invalid: " +
- e.getMessage());
+ throw new MalformedURLException("The URL syntax was invalid: "
+ + e.getMessage());
}
}
/**
- * Checks that the URL contains a name, and removes any leading
- * slashes.
- *
+ * Checks that the URL contains a name, and removes any leading slashes.
+ *
* @param url the URL to check.
* @throws MalformedURLException if no name is specified.
- */
- private static String getName(URL url)
- throws MalformedURLException
+ */
+ private static String getName(URL url) throws MalformedURLException
{
String filename = url.getFile();
if (filename.length() == 0)
@@ -216,5 +231,4 @@ private static Registry getRegistry(URL u) throws RemoteException {
return filename.substring(1);
return filename;
}
-
}
diff --git a/libjava/classpath/java/rmi/NoSuchObjectException.java b/libjava/classpath/java/rmi/NoSuchObjectException.java
index 69f7d6c52fb..2943906701b 100644
--- a/libjava/classpath/java/rmi/NoSuchObjectException.java
+++ b/libjava/classpath/java/rmi/NoSuchObjectException.java
@@ -1,5 +1,6 @@
/* NoSuchObjectException.java -- thrown if the remote object no longer exists
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -43,9 +44,9 @@ package java.rmi;
* obey the semantics of "at most once".
*
* @author unknown
- * @see RemoteObject#toStub(Remote)
- * @see UnicastRemoteObject#unexportObject(Remote, boolean)
- * @see Activatable#unexportObject(Remote, boolean)
+ * @see java.rmi.server.RemoteObject#toStub(Remote)
+ * @see java.rmi.server.UnicastRemoteObject#unexportObject(Remote, boolean)
+ * @see java.rmi.activation.Activatable#unexportObject(Remote, boolean)
* @since 1.1
* @status updated to 1.4
*/
diff --git a/libjava/classpath/java/rmi/NotBoundException.java b/libjava/classpath/java/rmi/NotBoundException.java
index b8bc0a5320a..03d4adf8f71 100644
--- a/libjava/classpath/java/rmi/NotBoundException.java
+++ b/libjava/classpath/java/rmi/NotBoundException.java
@@ -1,5 +1,6 @@
/* NotBoundException.java -- attempt to use a registry name with no binding
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,10 +43,10 @@ package java.rmi;
* associated binding.
*
* @author unknown
- * @see Naming#lookup(String)
- * @see Naming#unbind(String)
- * @see Registry#lookup(String)
- * @see Registry#unbind(String)
+ * @see java.rmi.Naming#lookup(String)
+ * @see java.rmi.Naming#unbind(String)
+ * @see java.rmi.registry.Registry#lookup(String)
+ * @see java.rmi.registry.Registry#unbind(String)
* @since 1.1
* @status updated to 1.4
*/
diff --git a/libjava/classpath/java/rmi/RMISecurityException.java b/libjava/classpath/java/rmi/RMISecurityException.java
index a44a67e2a02..6f15af85280 100644
--- a/libjava/classpath/java/rmi/RMISecurityException.java
+++ b/libjava/classpath/java/rmi/RMISecurityException.java
@@ -1,5 +1,6 @@
/* RMISecurityException.java -- deprecated version of SecurityException
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,11 +39,12 @@ exception statement from your version. */
package java.rmi;
/**
- * Never thrown, but originally intended to wrap a java.lang.SecurityException.
+ * Never thrown, but originally intended to wrap a
+ * {@link java.lang.SecurityException} in the case of RMI.
*
* @author unknown
* @since 1.1
- * @deprecated use {@link SecurityException} instead
+ * @deprecated use {@link java.lang.SecurityException} instead
* @status updated to 1.4
*/
public class RMISecurityException extends SecurityException
@@ -55,7 +57,7 @@ public class RMISecurityException extends SecurityException
/**
* Create an exception with a message.
*
- * @param s the message
+ * @param n the message
* @deprecated no longer needed
*/
public RMISecurityException(String n)
@@ -66,8 +68,8 @@ public class RMISecurityException extends SecurityException
/**
* Create an exception with a message and a cause.
*
- * @param s the message
- * @param e the cause
+ * @param n the message
+ * @param a the cause (ignored)
* @deprecated no longer needed
*/
public RMISecurityException(String n, String a)
diff --git a/libjava/classpath/java/rmi/Remote.java b/libjava/classpath/java/rmi/Remote.java
index 93c8d0aa127..0306981e96f 100644
--- a/libjava/classpath/java/rmi/Remote.java
+++ b/libjava/classpath/java/rmi/Remote.java
@@ -1,5 +1,5 @@
/* Remote.java
- Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,5 +37,22 @@ exception statement from your version. */
package java.rmi;
+/**
+ * Marker interface for interfaces which methods are invokable
+ * from outside of this virtual machine through remote method calls.
+ * <p>
+ * Remote invokable methods of remote object implementations are specified
+ * as the methods defined in the implemented remote interfaces. Typically
+ * remote object implementations are subclasses of the convenience classes
+ * {@link java.rmi.server.UnicastRemoteObject} or
+ * {@link java.rmi.activation.Activatable} implementing one or more remote
+ * interfaces indicating their remotely accessible methods. The convenience
+ * classes provide implementations for correct remote object creation,
+ * hash, equals and toString methods.
+ * </p>
+ *
+ * @author unknown
+ */
public interface Remote {
+ // marker interface
}
diff --git a/libjava/classpath/java/rmi/RemoteException.java b/libjava/classpath/java/rmi/RemoteException.java
index cbbb26299c3..929bc80f67f 100644
--- a/libjava/classpath/java/rmi/RemoteException.java
+++ b/libjava/classpath/java/rmi/RemoteException.java
@@ -1,5 +1,6 @@
/* RemoteException.java -- common superclass for exceptions in java.rmi
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -86,7 +87,7 @@ public class RemoteException extends IOException
* Create an exception with the given message and cause.
*
* @param s the message
- * @param ex the cause
+ * @param e the cause
*/
public RemoteException(String s, Throwable e)
{
diff --git a/libjava/classpath/java/rmi/StubNotFoundException.java b/libjava/classpath/java/rmi/StubNotFoundException.java
index 2f9e0f5ff59..524b418cea1 100644
--- a/libjava/classpath/java/rmi/StubNotFoundException.java
+++ b/libjava/classpath/java/rmi/StubNotFoundException.java
@@ -1,5 +1,6 @@
/* StubNotFoundException.java -- thrown if a valid stub is not found
- Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,8 +42,8 @@ package java.rmi;
* Thrown if a valid stub class is not found for an object when it is exported.
*
* @author unknown
- * @see UnicastRemoteObject
- * @see Activatable
+ * @see java.rmi.server.UnicastRemoteObject
+ * @see java.rmi.activation.Activatable
* @since 1.1
* @status updated to 1.4
*/
diff --git a/libjava/classpath/java/rmi/dgc/DGC.java b/libjava/classpath/java/rmi/dgc/DGC.java
index e78ec2a3aa7..66bfc6dfd62 100644
--- a/libjava/classpath/java/rmi/dgc/DGC.java
+++ b/libjava/classpath/java/rmi/dgc/DGC.java
@@ -41,11 +41,40 @@ import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.ObjID;
-public interface DGC extends Remote
+/**
+ * The DGC implementation is used for the server side during the distributed
+ * garbage collection. This interface contains the two methods: dirty and clean.
+ * A dirty call is made when a remote reference is unmarshaled in a client. A
+ * corresponding clean call is made by client it no longer uses that remote
+ * reference. A reference to a remote object is also automatically released
+ * after so called lease period that starts after the dirty call is received. It
+ * is the client's responsibility to renew the leases, by making additional
+ * dirty calls before such leases expire.
+ */
+public interface DGC
+ extends Remote
{
- Lease dirty (ObjID[] ids, long sequenceNum, Lease lease)
- throws RemoteException;
+ /**
+ * Mark the given objects referecnes as used on the client side.
+ *
+ * @param ids the ids of the used objects.
+ * @param sequenceNum the number of the call (used to detect and discard late
+ * calls).
+ * @param lease the requested lease
+ * @return the granted lease
+ */
+ Lease dirty(ObjID[] ids, long sequenceNum, Lease lease)
+ throws RemoteException;
- void clean (ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
- throws RemoteException;
+ /**
+ * Mark the given objects as no longer used on the client side.
+ *
+ * @param ids the ids of the objects that are no longer used.
+ * @param sequenceNum the number of the call (used to detect and discard late
+ * @param vmid the VMID of the client.
+ * @param strong make the "strong" clean call ("strong" calls are scheduled
+ * after the failed dirty calls).
+ */
+ void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong)
+ throws RemoteException;
}
diff --git a/libjava/classpath/java/rmi/dgc/Lease.java b/libjava/classpath/java/rmi/dgc/Lease.java
index d3d7f695216..36ff12ad224 100644
--- a/libjava/classpath/java/rmi/dgc/Lease.java
+++ b/libjava/classpath/java/rmi/dgc/Lease.java
@@ -1,5 +1,6 @@
/* Lease.java
Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -7,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -39,29 +40,61 @@ package java.rmi.dgc;
import java.io.Serializable;
+/**
+ * A lease object is used to request and grant leases for the remote objects. It
+ * contains the lease duration and the unique VM indentifier.
+ */
public final class Lease
- implements Serializable {
+ implements Serializable
+{
-static final long serialVersionUID = -5713411624328831948L;
+ static final long serialVersionUID = - 5713411624328831948L;
-private VMID vmid;
-private long value;
+ private VMID vmid;
-public Lease(VMID id, long duration) {
- vmid = id;
- value = duration;
-}
+ private long value;
-public VMID getVMID() {
- return (vmid);
-}
+ /**
+ * Create the new lease with the given id and duration
+ *
+ * @param id the lease id
+ * @param duration the lease duration
+ */
+ public Lease(VMID id, long duration)
+ {
+ vmid = id;
+ value = duration;
+ }
-public long getValue() {
- return (value);
-}
+ /**
+ * Get the lease id.
+ *
+ * @return the lease id
+ */
+ public VMID getVMID()
+ {
+ return (vmid);
+ }
-public String toString() {
- return ("[" + vmid.toString() + ", " + Long.toString(value) + "]");
-}
+ /**
+ * Get the lease duration
+ *
+ * @return the lease duration
+ */
+ public long getValue()
+ {
+ return (value);
+ }
+
+ /**
+ * Get the string representation of this lease
+ *
+ * @return the string represenation (lease id, followed by the lease
+ * duration).
+ */
+ public String toString()
+ {
+ return ("[" + vmid.toString() + ", " + Long.toString(value) + "]");
+ }
}
diff --git a/libjava/classpath/java/rmi/package.html b/libjava/classpath/java/rmi/package.html
index a7bf8502056..1d36fe80a89 100644
--- a/libjava/classpath/java/rmi/package.html
+++ b/libjava/classpath/java/rmi/package.html
@@ -40,7 +40,7 @@ exception statement from your version. -->
<head><title>GNU Classpath - java.rmi</title></head>
<body>
-<p></p>
+<p>Provides basic Remote Method Invocation (RMI) interfaces, classes and exceptions.</p>
</body>
</html>
diff --git a/libjava/classpath/java/rmi/registry/Registry.java b/libjava/classpath/java/rmi/registry/Registry.java
index 6cd2a04a685..02d8c50cc2a 100644
--- a/libjava/classpath/java/rmi/registry/Registry.java
+++ b/libjava/classpath/java/rmi/registry/Registry.java
@@ -47,7 +47,29 @@ import java.rmi.RemoteException;
public interface Registry extends Remote
{
int REGISTRY_PORT = 1099;
-
+
+ /**
+ * Find and return the reference to the object that was previously bound
+ * to the registry by this name. For remote objects, this method returns
+ * the stub instances, containing the code for remote invocations.
+ *
+ * Since jdk 1.5 this method does not longer require the stub class
+ * (nameImpl_Stub) to be present. If such class is not found, the stub is
+ * replaced by the dynamically constructed proxy class. No attempt to find
+ * and load the stubs is made if the system property
+ * java.rmi.server.ignoreStubClasses is set to true (set to reduce the
+ * starting time if the stubs are surely not present and exclusively 1.2
+ * RMI is used).
+ *
+ * @param name the name of the object
+ *
+ * @return the reference to that object on that it is possible to invoke
+ * the (usually remote) object methods.
+ *
+ * @throws RemoteException
+ * @throws NotBoundException
+ * @throws AccessException
+ */
Remote lookup(String name)
throws RemoteException, NotBoundException, AccessException;
diff --git a/libjava/classpath/java/rmi/server/RMIClassLoader.java b/libjava/classpath/java/rmi/server/RMIClassLoader.java
index f8997fd7e09..33c44198d37 100644
--- a/libjava/classpath/java/rmi/server/RMIClassLoader.java
+++ b/libjava/classpath/java/rmi/server/RMIClassLoader.java
@@ -38,10 +38,13 @@ exception statement from your version. */
package java.rmi.server;
+import gnu.classpath.ServiceFactory;
+import gnu.classpath.SystemProperties;
import gnu.java.rmi.server.RMIClassLoaderImpl;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Iterator;
/**
* This class provides a set of public static utility methods for supporting
@@ -84,6 +87,16 @@ public class RMIClassLoader
return spi.loadClass(codebase, name, defaultLoader);
}
+ public static Class loadProxyClass (String codeBase, String[] interfaces,
+ ClassLoader defaultLoader)
+ throws MalformedURLException, ClassNotFoundException
+ {
+ RMIClassLoaderSpi spi = getProviderInstance();
+ if (spi == null)
+ spi = getDefaultProviderInstance();
+ return spi.loadProxyClass(codeBase, interfaces, defaultLoader);
+ }
+
/**
* Loads a class from <code>codeBase</code>.
*
@@ -171,7 +184,20 @@ public class RMIClassLoader
*/
private static RMIClassLoaderSpi getProviderInstance()
{
- // TODO: Do something more useful here.
- return null;
+ // If the user asked for the default, return it. We do a special
+ // check here because our standard service lookup function does not
+ // handle this -- nor should it.
+ String prop = SystemProperties.getProperty("java.rmi.server.RMIClassLoaderSpi");
+ if ("default".equals(prop))
+ return null;
+ Iterator it = ServiceFactory.lookupProviders(RMIClassLoaderSpi.class,
+ null);
+ if (it == null || ! it.hasNext())
+ return null;
+ // FIXME: the spec says we ought to throw an Error of some kind if
+ // the specified provider is not suitable for some reason. However
+ // our service factory simply logs the problem and moves on to the next
+ // provider in this situation.
+ return (RMIClassLoaderSpi) it.next();
}
}
diff --git a/libjava/classpath/java/rmi/server/RemoteObjectInvocationHandler.java b/libjava/classpath/java/rmi/server/RemoteObjectInvocationHandler.java
new file mode 100644
index 00000000000..afd1d592715
--- /dev/null
+++ b/libjava/classpath/java/rmi/server/RemoteObjectInvocationHandler.java
@@ -0,0 +1,221 @@
+/* RemoteObjectInvocationHandler.java -- RMI stub replacement.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+
+package java.rmi.server;
+
+import gnu.java.rmi.server.RMIHashes;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.UnexpectedException;
+import java.rmi.registry.Registry;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Hashtable;
+
+/**
+ * Together with dynamic proxy instance, this class replaces the generated RMI
+ * stub (*_Stub) classes that (following 1.5 specification) should be no longer
+ * required. It is unusual to use the instances of this class directly in the
+ * user program. Such instances are automatically created and returned by
+ * {@link Registry} or {@link UnicastRemoteObject} methods if the remote
+ * reference is known but the corresponding stub class is not accessible.
+ *
+ * @see Registry#lookup
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class RemoteObjectInvocationHandler extends RemoteObject implements
+ InvocationHandler, Remote, Serializable
+{
+ /**
+ * Use the jdk 1.5 SUID for interoperability.
+ */
+ static final long serialVersionUID = 2L;
+
+ /**
+ * The RMI method hash codes, computed once as described in the section 8.3
+ * of the Java Remote Method Invocation (RMI) Specification.
+ */
+ static Hashtable methodHashCodes = new Hashtable();
+
+ /**
+ * The empty class array to define parameters of .hashCode and .toString.
+ */
+ static final Class[] noArgsC = new Class[0];
+
+ /**
+ * The class array to define parameters of .equals
+ */
+ static final Class[] anObjectC = new Class[] { Object.class };
+
+ /**
+ * Construct the remote invocation handler that forwards calls to the given
+ * remote object.
+ *
+ * @param reference the reference to the remote object where the method
+ * calls should be forwarded.
+ */
+ public RemoteObjectInvocationHandler(RemoteRef reference)
+ {
+ super(reference);
+ }
+
+ /**
+ * Invoke the remote method. When the known method is invoked on a created RMI
+ * stub proxy class, the call is delivered to this method and then transferred
+ * to the {@link RemoteRef#invoke(Remote, Method, Object[], long)} of the
+ * remote reference that was passed in constructor. The methods are handled as
+ * following:
+ * <ul>
+ * <li> The toString() method is delegated to the passed proxy instance.</li>
+ * <li>The .equals method only returns true if the passed object is an
+ * instance of proxy class and its invocation handler is equal to this
+ * invocation handles.</li>
+ * <li>The .hashCode returns the hashCode of this invocation handler (if the.</li>
+ * <li>All other methods are converted to remote calls and forwarded to the
+ * remote reference. </li>
+ * </ul>
+ *
+ * @param proxyInstance
+ * the instance of the proxy stub
+ * @param method
+ * the method being invoked
+ * @param parameters
+ * the method parameters
+ * @return the method return value, returned by RemoteRef.invoke
+ * @throws IllegalAccessException
+ * if the passed proxy instance does not implement Remote interface.
+ * @throws UnexpectedException
+ * if remote call throws some exception, not listed in the
+ * <code>throws</code> clause of the method being called.
+ * @throws Throwable
+ * that is thrown by remote call, if that exception is listend in
+ * the <code>throws</code> clause of the method being called.
+ */
+ public Object invoke(Object proxyInstance, Method method, Object[] parameters)
+ throws Throwable
+ {
+ if (!(proxyInstance instanceof Remote))
+ {
+ String name = proxyInstance == null ? "null"
+ : proxyInstance.getClass().getName();
+ throw new IllegalAccessException(name + " does not implement "
+ + Remote.class.getName());
+ }
+
+ String name = method.getName();
+ switch (name.charAt(0))
+ {
+ case 'e':
+ if (parameters.length == 1 && name.equals("equals")
+ && method.getParameterTypes()[0].equals(Object.class))
+ {
+ if (parameters[0] instanceof Proxy)
+ {
+ Object handler = Proxy.getInvocationHandler(parameters[0]);
+ if (handler == null)
+ return Boolean.FALSE;
+ else
+ return handler.equals(this) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else
+ return Boolean.FALSE;
+ }
+ break;
+ case 'h':
+ if (parameters.length == 0 && name.equals("hashCode"))
+ {
+ int hashC = Proxy.getInvocationHandler(proxyInstance).hashCode();
+ return new Integer(hashC);
+ }
+ break;
+ case 't':
+ if (parameters.length == 0 && name.equals("toString"))
+ return proxyInstance.toString();
+ break;
+ default:
+ break;
+ }
+
+ Long hash = (Long) methodHashCodes.get(method);
+ if (hash == null)
+ {
+ hash = new Long(RMIHashes.getMethodHash(method));
+ methodHashCodes.put(method, hash);
+ }
+
+ try
+ {
+ return getRef().invoke((Remote) proxyInstance, method, parameters,
+ hash.longValue());
+ }
+ catch (RuntimeException exception)
+ {
+ // RuntimeException is always supported.
+ throw exception;
+ }
+ catch (RemoteException exception)
+ {
+ // All remote methods can throw RemoteException.
+ throw exception;
+ }
+ catch (Error exception)
+ {
+ throw exception;
+ }
+ catch (Exception exception)
+ {
+ Class[] exceptions = method.getExceptionTypes();
+ Class exceptionClass = exception.getClass();
+
+ for (int i = 0; i < exceptions.length; i++)
+ {
+ if (exceptions[i].equals(exceptionClass))
+ throw exception;
+ }
+ throw new UnexpectedException(method.getName(), exception);
+ }
+ }
+
+}
diff --git a/libjava/classpath/java/rmi/server/RemoteRef.java b/libjava/classpath/java/rmi/server/RemoteRef.java
index f33f9d374c3..8bdb6633040 100644
--- a/libjava/classpath/java/rmi/server/RemoteRef.java
+++ b/libjava/classpath/java/rmi/server/RemoteRef.java
@@ -1,5 +1,6 @@
/* RemoteRef.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,8 +45,16 @@ import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.RemoteException;
+/**
+ * Represents a handler to the remote object. Each instance of the
+ * {@link RemoteStub} contains such handler and uses it to invoke remote
+ * methods via {@link #invoke(Remote, Method, Object[], long)}.
+ */
public interface RemoteRef extends Externalizable
{
+ /**
+ * Indicates compatibility with JDK 1.1.*
+ */
long serialVersionUID = 3632638527362204081L;
/**
@@ -55,29 +64,74 @@ public interface RemoteRef extends Externalizable
String packagePrefix = "sun.rmi.server";
/**
- * @deprecated
+ * @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
void invoke (RemoteCall call) throws Exception;
- Object invoke (Remote obj, Method method, Object[] params, long opnum)
+ /**
+ * Invoke a method. This method either returns the result of remote invocation
+ * or throws RemoteException if the remote call failed. Other exceptions may
+ * be thrown if some problem has occured in the application level.
+ *
+ * @param obj the object, containing the remote reference (for instance,
+ * remote stub, generated by rmic).
+ * @param method the method to invoke
+ * @param params the method parameters
+ * @param methodHash a persistent hash code that can be used to represent a
+ * method
+ * @return the result of the remote invocation
+ * @throws RemoteException if the remote call has failed
+ * @throws Exception if one is raised at the application level
+ */
+ Object invoke (Remote obj, Method method, Object[] params, long methodHash)
throws Exception;
/**
- * @deprecated
+ * @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
RemoteCall newCall (RemoteObject obj, Operation[] op, int opnum, long hash)
throws RemoteException;
/**
- * @deprecated
+ * @deprecated use {@link #invoke(Remote, Method, Object[], long)} instead.
*/
void done (RemoteCall call) throws RemoteException;
+ /**
+ * Compare two remote objects for equality. The references are equal if
+ * they point to the same remote object.
+ *
+ * @param ref the reference to compare.
+ *
+ * @return true if this and passed references both point to the same remote
+ * object, false otherwise.
+ */
boolean remoteEquals (RemoteRef ref);
+ /**
+ * Get the hashcode for a remote object. Two remote object stubs, referring
+ * to the same remote object, have the same hash code.
+ *
+ * @return the hashcode of the remote object
+ */
int remoteHashCode();
+
+ /**
+ * Returns the class name of the reference type that must be written to the
+ * given stream. When writing, this returned name is passed first, and
+ * the reference.writeExternal(out) writes the reference specific data.
+ *
+ * @param out the stream, where the data must be written
+ *
+ * @return the class name.
+ */
String getRefClass (ObjectOutput out);
+ /**
+ * Get the string representation of this remote reference.
+ *
+ * @return the string representation.
+ */
String remoteToString();
}
diff --git a/libjava/classpath/java/rmi/server/RemoteStub.java b/libjava/classpath/java/rmi/server/RemoteStub.java
index 18c614b54a8..d6dff7fadc8 100644
--- a/libjava/classpath/java/rmi/server/RemoteStub.java
+++ b/libjava/classpath/java/rmi/server/RemoteStub.java
@@ -37,21 +37,40 @@ exception statement from your version. */
package java.rmi.server;
+/**
+ * This is a base class for the automatically generated RMI stubs.
+ */
public abstract class RemoteStub extends RemoteObject
{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
static final long serialVersionUID = -1585587260594494182l;
-
+
+ /**
+ * Constructs the remote stub with no reference set.
+ */
protected RemoteStub ()
{
super ();
}
-
+
+ /**
+ * Constructs the remote stub that uses given remote reference for the
+ * method invocations.
+ *
+ * @param ref the remote reference for the method invocation.
+ */
protected RemoteStub (RemoteRef ref)
{
super (ref);
}
/**
+ * Sets the given remote reference for the given stub. This method is
+ * deprecated. Pass the stub remote reference to the RemoteStub
+ * constructor instead.
+ *
* @deprecated
*/
protected static void setRef (RemoteStub stub, RemoteRef ref)
diff --git a/libjava/classpath/java/rmi/server/UnicastRemoteObject.java b/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
index dbe25bda3fd..31bf8802301 100644
--- a/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
+++ b/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
@@ -1,5 +1,6 @@
/* UnicastRemoteObject.java --
- Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,61 +45,175 @@ import java.rmi.NoSuchObjectException;
import java.rmi.Remote;
import java.rmi.RemoteException;
+/**
+ * This class obtains stub that communicates with the remote object.
+ */
public class UnicastRemoteObject extends RemoteServer
{
-private static final long serialVersionUID = 4974527148936298033L;
-//The following serialized fields are from Java API Documentation "Serialized form"
-private int port = 0;
-private RMIClientSocketFactory csf = null;
-private RMIServerSocketFactory ssf = null;
+ /**
+ * Use SVUID for interoperability.
+ */
+ private static final long serialVersionUID = 4974527148936298033L;
-protected UnicastRemoteObject() throws RemoteException {
- this(0);
-}
+ //The following serialized fields are from Java API Documentation
+ // "Serialized form"
+
+ /**
+ * The port, on that the created remote object becomes available,
+ * zero meaning the anonymous port.
+ */
+ private int port;
+
+ /**
+ * The client socket factory for producing client sockets, used by this
+ * object.
+ */
+ private RMIClientSocketFactory csf;
+
+ /**
+ * The server socket factory for producing server sockets, used by this
+ * object.
+ */
+ private RMIServerSocketFactory ssf;
-protected UnicastRemoteObject(int port) throws RemoteException {
- this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory());
-}
+ /**
+ * Create and export new remote object without specifying the port value.
+ *
+ * @throws RemoteException if the attempt to export the object failed.
+ */
+ protected UnicastRemoteObject()
+ throws RemoteException
+ {
+ this(0);
+ }
+
+ /**
+ * Create and export the new remote object, making it available at the
+ * given port, local host.
+ *
+ * @param port the port, on that the object should become available.
+ * Zero means anonymous port.
+ *
+ * @throws RemoteException if the attempt to export the object failed.
+ */
+ protected UnicastRemoteObject(int port)
+ throws RemoteException
+ {
+ this(port, RMISocketFactory.getSocketFactory(),
+ RMISocketFactory.getSocketFactory());
+ }
-protected UnicastRemoteObject(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException {
- this.port = port;
- //Is RMIXXXSocketFactory serializable
- //this.csf = csf;
- //this.ssf = ssf;
- this.ref = new UnicastServerRef(new ObjID(), port, ssf);
- exportObject(this);
-}
+ /**
+ * Create and export the new remote object, making it available at the
+ * given port, using sockets, produced by the specified factories.
+ *
+ * @param port the port, on that the object should become available.
+ * Zero means anonymous port.
+ *
+ * @param clientSocketFactory the client socket factory
+ * @param serverSocketFactory the server socket factory
+ *
+ * @throws RemoteException if the attempt to export the object failed.
+ */
+ protected UnicastRemoteObject(int port,
+ RMIClientSocketFactory clientSocketFactory,
+ RMIServerSocketFactory serverSocketFactory)
+ throws RemoteException
+ {
+ this.port = port;
+ //Is RMIXXXSocketFactory serializable
+ //this.csf = csf;
+ //this.ssf = ssf;
+ this.ref = new UnicastServerRef(new ObjID(), port, serverSocketFactory);
+ exportObject(this, port);
+ }
-protected UnicastRemoteObject(RemoteRef ref) throws RemoteException {
- super((UnicastServerRef)ref);
- exportObject(this);
-}
+ protected UnicastRemoteObject(RemoteRef ref)
+ throws RemoteException
+ {
+ super((UnicastServerRef) ref);
+ exportObject(this, 0);
+ }
-public Object clone() throws CloneNotSupportedException {
+ public Object clone()
+ throws CloneNotSupportedException
+ {
throw new Error("Not implemented");
-}
-
-public static RemoteStub exportObject(Remote obj) throws RemoteException {
- UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef();
- return (sref.exportObject(obj));
-}
+ }
+
+ /**
+ * Export object, making it available for the remote calls at the
+ * anonymous port.
+ *
+ * This method returns the instance of the abstract class, not an interface.
+ * Hence it will not work with the proxy stubs that are supported since
+ * jdk 1.5 (such stubs cannot be derived from the RemoteStub). Only use
+ * this method if you are sure that the stub class will be accessible.
+ *
+ * @param obj the object being exported.
+ *
+ * @return the remote object stub
+ *
+ * @throws RemoteException if the attempt to export the object failed.
+ */
+ public static RemoteStub exportObject(Remote obj)
+ throws RemoteException
+ {
+ return (RemoteStub) exportObject(obj, 0);
+ }
- public static Remote exportObject(Remote obj, int port) throws RemoteException
+ /**
+ * Export object, making it available for the remote calls at the
+ * specified port.
+ *
+ * Since jdk 1.5 this method does not longer require the stub class to be
+ * present. If such class is not found, the stub is replaced by the
+ * dynamically constructed proxy class. No attempt to find and load the stubs
+ * is made if the system property java.rmi.server.ignoreStubClasses
+ * is set to true (set to reduce the starting time if the stubs are
+ * surely not present and exclusively 1.2 RMI is used).
+ *
+ * @param obj the object being exported.
+ * @param port the remote object port
+ *
+ * @return the remote object stub
+ *
+ * @throws RemoteException if the attempt to export the object failed.
+ */
+ public static Remote exportObject(Remote obj, int port)
+ throws RemoteException
{
return exportObject(obj, port, null);
}
-
- static Remote exportObject(Remote obj, int port, RMIServerSocketFactory ssf)
- throws RemoteException
+
+ /**
+ * Create and export the new remote object, making it available at the
+ * given port, using sockets, produced by the specified factories.
+ *
+ * Since jdk 1.5 this method does not longer require the stub class to be
+ * present. If such class is not found, the stub is replaced by the
+ * dynamically constructed proxy class. No attempt to find and load the stubs
+ * is made if the system property java.rmi.server.ignoreStubClasses
+ * is set to true (set to reduce the starting time if the stubs are
+ * surely not present and exclusively 1.2 RMI is used).
+ *
+ * @param port the port, on that the object should become available.
+ * Zero means anonymous port.
+ *
+ * @param serverSocketFactory the server socket factory
+ */
+ static Remote exportObject(Remote obj, int port,
+ RMIServerSocketFactory serverSocketFactory)
+ throws RemoteException
{
UnicastServerRef sref = null;
if (obj instanceof RemoteObject)
- sref = (UnicastServerRef)((RemoteObject)obj).getRef ();
- if(sref == null)
- {
- sref = new UnicastServerRef(new ObjID (), port, ssf);
- }
- Remote stub = sref.exportObject (obj);
+ sref = (UnicastServerRef) ((RemoteObject) obj).getRef();
+
+ if (sref == null)
+ sref = new UnicastServerRef(new ObjID(), port, serverSocketFactory);
+
+ Remote stub = sref.exportObject(obj);
addStub(obj, stub);
return stub;
}
@@ -106,8 +221,9 @@ public static RemoteStub exportObject(Remote obj) throws RemoteException {
/**
* FIXME
*/
- public static Remote exportObject(Remote obj, int port, RMIClientSocketFactory csf,
- RMIServerSocketFactory ssf)
+ public static Remote exportObject(Remote obj, int port,
+ RMIClientSocketFactory csf,
+ RMIServerSocketFactory ssf)
throws RemoteException
{
return (exportObject(obj, port, ssf));
@@ -118,14 +234,15 @@ public static RemoteStub exportObject(Remote obj) throws RemoteException {
{
if (obj instanceof RemoteObject)
{
- deleteStub(obj);
- UnicastServerRef sref = (UnicastServerRef)((RemoteObject)obj).getRef();
- return sref.unexportObject(obj, force);
+ deleteStub(obj);
+ UnicastServerRef sref =
+ (UnicastServerRef) ((RemoteObject) obj).getRef();
+ return sref.unexportObject(obj, force);
}
else
{
- //FIX ME
- ;
+ // FIXME
+ ;
}
return true;
}
OpenPOWER on IntegriCloud