Java Reference
In-Depth Information
these requirements are met by extending the RMI convenience class
java.rmi.server.UnicastRemoteObject ,asubclass of RemoteOb-
ject .Atconstruction time, UnicastRemoteObject takes care of doing the
export.
An implementation of the interface shown above is given here:
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class RMIExampleImpl
extends UnicastRemoteObject
implements RMIExampleInterface
{
/** Constructor must throw RemoteException **/
public RMIExampleImpl () throws RemoteException {}
/** Echoes the input string. **/
public void method1 (String s) {
System.out.println ( " method1: " + s);
} // method1
/** Adds the input parameters and returns the sum. **/
public int add (int a, int b) {
returna+b;
} // add
/** Do something locally. **/
public void doSomethingLocal (float x) {...}
} // class RMIExampleImpl
Notice that this implementation class provides the implementation of the two
remote methods declared in the remote interface - method1() and add() .It
also defines the local method doSomethingLocal() . This method is perfectly
legal, but since it is not declared in the remote interface, it cannot be called from
the remote (client-side) JVM. It is only available locally and to other objects on
the server side.
18.3.4 The RMI registry
Client code must be able to find the remote objects. RMI provides a simple name
server known as the RMI registry to facilitate this remote object lookup. The
 
Search WWH ::




Custom Search