Tuesday, 5 February 2013

Defining the RMI Contract | J2EE Tutorial pdf

Defining the RMI Contract

RMI procedures are defined using an existing Java mechanism: interfaces. An interface is similar to an abstract class, but a class can implement more than one interface. RMI remote interfaces must be subclassed from java.rmi.Remote and both the client and server must be in the same Java package. All parameters and return values must be either primitives (int, double, etc.), or implement Serializable (as do most of the standard types like String). Or they can also be Remote.
Figure shows the relationships between the important classes involved in an RMI implementation. The developer need only write the interface and two classes, the client application and the server object implementation. The RMI stub or proxy and the RMI skeleton or adapter are generated for us by the rmic program while the RMI Registry and other RMI classes at the bottom of the figure are provided as part of RMI itself. Next example is a simple RemoteDate getter interface, which lets us find out the date and time on a remote machine.
Example RemoteDate.java
package darwinsys.distdate;
import java.rmi.*;
import java.util.Date;
/** A statement of what the client & server must agree upon. */
public interface RemoteDate extends java.rmi.Remote {
/** The method used to get the current date on the remote */
public Date getRemoteDate( ) throws java.rmi.RemoteException;
/** The name used in the RMI registry service. */
public final static String LOOKUPNAME = "RemoteDate";
}
It's necessary for this file to list all the methods that will be callable from the server by the client.
The lookup name is an arbitrary name that is registered by the server and looked up by the client to establish communications between the two processes.

No comments: