Chapter 17. The java.rmi.server PackageThe java.rmi.server package contains the classes that develop server implementations of remote objects. Figure 17-1 shows the class hierarchy for this package. The RemoteServer class in this package acts as the base class for all RMI server objects. A single subclass of RemoteServer, UnicastRemoteObject, is provided in this package. It implements a nonpersistent, point-to-point object communication scheme. Other subclasses of RemoteServer could be written to implement multicast object communication, replicated objects, etc. This package also contains several Exception subclasses relevant to the server implementation of a remote object. Figure 17-1. The java.rmi.server package
This RemoteException is thrown if an attempt is made to export a remote object on a port already in use.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->IOException-->RemoteException-->ExportException Subclasses: SocketSecurityException
This defines the interface to the internal handler used by the RMIClassLoader to load classes over the network.
This class provides the server with an output stream to an error log. A LogStream cannot be created directly by an application. Instead, a handle on a LogStream is obtained by calling the static log() method with the name of the desired log. If the named log doesn't exist, the default log is returned. The default PrintStream creates new LogStream objects can be retrieved through the getDefaultStream() method and set using the setDefaultStream() method.
Hierarchy: Object-->java.io.OutputStream-->FilterOutputStream-->PrintStream-->LogStream Returned By: LogStream.log()
An ObjID is used on an object server to uniquely identify exported remote objects. It is used in an RMI server during distributed garbage collection. The equals() method is overridden from Object to return true only if the objects identified by the two ObjID values are equal. The ObjID class also has read() and write() methods that marshal and unmarshal an ObjID from I/O streams.
Hierarchy: Object-->ObjID(Serializable) Passed To: java.rmi.dgc.DGC.{clean(), dirty()} Returned By: ObjID.read()
An Operation contains a description of a method on a remote object. This class is used only in the stub classes generated by the rmic compiler. The Java 2 rmic compiler no longer uses the Operation class, so it is deprecated, but still present in the Java 2 SDK 1.2 to support RMI stubs generated by the JDK 1.1 rmic compiler.
Passed To: RemoteRef.newCall() Returned By: Skeleton.getOperations()
RemoteCall is the interface used by stubs and skeletons to perform remote method calls. The getInputStream() and getOutputStream() methods return streams that can marshal arguments, or return values and then unmarshal them on the other end of the method call.
Passed To: RemoteRef.{done(), invoke()}, Skeleton.dispatch() Returned By: RemoteRef.newCall()
The RemoteObject class reimplements key Object methods for remote objects. It also maintains a RemoteRef object, which is a handle to the actual remote object. The equals() implementation returns true only if the two referenced remote objects are equal. The hashCode() method is implemented so that every remote stub that refers to the same remote object has the same hash code.
Hierarchy: Object-->RemoteObject(Remote,Serializable) Subclasses: RemoteServer, RemoteStub Passed To: RemoteRef.newCall()
A RemoteRef is a handle on the object that implements a remote object reference. Each RemoteObject contains a RemoteRef that acts as its interface to the actual remote object it represents. Normally, you don't need to interact directly with RemoteRef objects from your application code. Rather, application code interacts with RemoteObject objects, which use their internal RemoteRef objects to perform remote method invocations. The newCall() method creates a call object for invoking a remote method on the referenced object. The invoke() method actually executes a remote-method invocation. If a remote method returns successfully, the done() method is called to clean up the connection to the remote object. The remoteEquals(), remoteHashCode(), and remoteToString() methods on RemoteRef are used by RemoteObject to implement the remote versions of the equals(), hashCode(), and toString() methods.
Hierarchy: (RemoteRef(Externalizable(Serializable))) Implementations: ServerRef Passed To: java.rmi.activation.ActivationGroup_Stub.ActivationGroup_Stub(), RemoteObject.RemoteObject(), RemoteRef.remoteEquals(), RemoteServer.RemoteServer(), RemoteStub.{RemoteStub(), setRef()} Returned By: RemoteObject.getRef() Type Of: RemoteObject.ref
This class acts as an abstract base class for all remote object server implementations. The intent is for subclasses to implement the semantics of the remote object (e.g., multicast remote objects, replicated objects). As of JDK 1.1 and later, the only concrete sub-class provided is UnicastRemoteObject, which implements a nonreplicated remote object. The java.activation.Activatable class is a new abstract subclass in Java 2 that represents a server object that is persistent and activatable. The getClientHost() method returns the name of the host for the client being served in the current thread. The getLog() and setLog() methods access the call log for a RemoteServer.
Hierarchy: Object-->RemoteObject(Remote,Serializable)-->RemoteServer Subclasses: java.rmi.activation.Activatable, UnicastRemoteObject
All client stub classes generated by the rmic compiler are derived from this abstract class. A client receives a RemoteStub when it successfully looks up a remote object through the RMI registry. A client stub serves as a client interface to the remote object it references, converting method calls on its interface to remote method invocations on the remote object implementation.
Hierarchy: Object-->RemoteObject(Remote,Serializable)-->RemoteStub Subclasses: java.rmi.activation.ActivationGroup_Stub Passed To: RemoteStub.setRef() Returned By: ServerRef.exportObject(), UnicastRemoteObject.exportObject()
This class loads classes over the network using URLs. The class has two loadClass() methods, one for loading a class from a given (absolute) URL and another for loading a class from a given (relative) URL, starting at a particular codebase.
This interface represents a source for client sockets that is used by the RMI internals to make client connections during RMI calls. It is possible to provide a custom socket factory to be used with a particular remote object, by using the appropriate constructors on the UnicastRemoteObject or Activatable classes, or, with a particular registry, by using the appropriate LocateRegistry.createRegistry() method. This can be useful in situations where a firewall lies between the client and the server object or remote registry, and specialized sockets are needed to negotiate the firewall protocol. The RMIClientSocketFactory associated with a remote object is used by any remote stub references to establish connections with the server object.
Implementations: RMISocketFactory Passed To: java.rmi.activation.Activatable.{Activatable(), exportObject()}, java.rmi.registry.LocateRegistry.{createRegistry(), getRegistry()}, UnicastRemoteObject.{exportObject(), UnicastRemoteObject()}
The failure() method on the current RMIFailureHandler is called when the RMI communication system fails to create a Socket or ServerSocket. The current handler is set using the setFailureHandler() method on RMISocketFactory. The failure() method returns a boolean value that indicates whether the RMI system should retry the socket connection.
Passed To: RMISocketFactory.setFailureHandler() Returned By: RMISocketFactory.getFailureHandler()
This interface represents a source for server sockets that is used by the RMI internals to make client connections during RMI calls. It is possible to provide a custom socket factory to be used with a particular remote object, by using the appropriate constructors on the UnicastRemoteObject or Activatable classes, or, with a particular registry, by using the appropriate LocateRegistry.createRegistry() method. This can be useful in situations where a firewall lies between the client and the server object or the remote registry, and specialized sockets are needed to negotiate the firewall protocol. The RMIServerSocketFactory creates ServerSocket objects that are used by remote objects to accept client connections.
Implementations: RMISocketFactory Passed To: java.rmi.activation.Activatable.{Activatable(), exportObject()}, java.rmi.registry.LocateRegistry.createRegistry(), UnicastRemoteObject.{exportObject(), UnicastRemoteObject()}
This abstract class provides an interface for the RMI internals to use to create sockets for both client and server communications. It implements both the RMIClientSocketFactory and the RMIServerSocketFactory interfaces, so it can create either Socket objects for clients or ServerSocket objects for servers. The factory maintains a RMIFailureHandler to deal with failures encountered while attempting to create sockets. If an error is encountered while creating a socket, the failure() method on the current RMIFailureHandler is called. If the return value is true, the RMISocketFactory attempts the socket creation again; otherwise the factory gives up and throws an IOException. Client sockets are created using the createSocket() method (inherited from RMIClientSocketFactory), while server sockets are created using the createServerSocket() method (inherited from RMIServerSocketFactory). The current RMISocketFactory for the runtime system can be accessed using the static getSocketFactory() and setSocketFactory() methods. The RMIFailureHandler for the current factory is accessed using the getFailureHandler() and setFailureHandler() methods.
Hierarchy: Object-->RMISocketFactory(RMIClientSocketFactory,RMIServerSocketFactory) Passed To: RMISocketFactory.setSocketFactory() Returned By: RMISocketFactory.{getDefaultSocketFactory(), getSocketFactory()}
This exception is thrown if an attempt to clone a RemoteServer object fails while the clone is being exported. The nested exception is the RemoteException that was thrown during the cloning operation.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->CloneNotSupportedException-->ServerCloneException
This exception is thrown if the getClientHost() method is called on a RemoteServer when the server isn't handling a remote method call.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->ServerNotActiveException Thrown By: RemoteServer.getClientHost(), ServerRef.getClientHost()
This is an interface to the server-side implementation of a remote object. The getClientHost() method returns the name of the host whose remote method call is currently being serviced by the object implementation. If the server object is not servicing a remote method call when getClientHost() is called, a ServerNotActiveException is thrown. Using the data provided, the exportObject() method either creates or finds a client stub for the given object implementation.
Hierarchy: (ServerRef(RemoteRef(Externalizable(Serializable))))
Server-side skeleton classes generated by the rmic compiler implement the Skeleton interface. The dispatch() method invokes a method on the server object, and getOperations() returns an array of Operation objects that represent the methods available on the server object. The Skeleton interface is used in classes generated by the rmic compiler in JDK 1.1. The Java 2 SDK 1.2 rmic compiler doesn't use the Skeleton interface for its skeleton classes, so it has been deprecated as of Java 2.
This RemoteException is thrown during a remote method call if a mismatch is detected on the server between the hash code of the client stub and the hash code of the server implementation. It is usually received by the client wrapped in a ServerException.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->IOException-->RemoteException-->SkeletonMismatchException
This RemoteException is thrown during the export of a remote object, if the corresponding skeleton class for the object either cannot be found or loaded for some reason.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->IOException-->RemoteException-->SkeletonNotFoundException
This exception is a subclass of ExportException that is thrown if a socket security violation is encountered while attempting to export a remote object. An example would be an attempt to export an object on an illegal port.
Hierarchy: Object-->Throwable(Serializable)-->Exception-->IOException-->RemoteException-->ExportException-->SocketSecurityException
A UID is an identifier that is unique with respect to a particular host. UID objects are used internally by RMI's distributed garbage collector and are generally not dealt with directly in application code.
Hierarchy: Object-->UID(Serializable) Returned By: UID.read()
This class represents a nonreplicated remote object, or in other words, an object that lives as a singular implementation on a server, with a point-to-point connection to each client through reference stubs. This remote server class does not implement persistence, so client references to the object are valid only during the lifetime of the object.
Hierarchy: Object-->RemoteObject(Remote,Serializable)-->RemoteServer-->UnicastRemoteObject Subclasses: java.rmi.activation.ActivationGroup
If a server object implements this interface, the unreferenced() method is called by the RMI runtime system when the last client reference to a remote object is dropped. A remote object shouldn't be garbage collected until all its remote and local references are gone. So the unreferenced() method isn't a trigger for an object to be finalized, but rather a chance for the remote object to respond appropriately when its client reference count goes to zero. The unreferenced object could, for example, start a timer countdown to move the object to persistent storage after a given idle time with respect to remote clients.
Copyright © 2001 O'Reilly & Associates. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|