Java Reference
In-Depth Information
Example 5.12 The RMI client program
package net.multitool.RMIDemo;
import java.rmi.*;
public class Client {
public static void main(String[] arglist) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
String name = "//penfold/Session";
// Obtain reference to the remote object
Session sess = (Session) Naming.lookup(name);
System.out.println("Pointless RMI Client. 47 + 13 = " +
sess.add(47,13) + ", right?");
} catch (Exception e) {
e.printStackTrace();
}
}
}
5.8.2
In order for a remote object to make itself available and in order for a client to
be able to call such an object, each method needs a client and server-side stub
to proxy the method call. Arguments to the method call are converted to
streamable data (this process is called marshaling ) by the client stub, and that
data is sent over the network to the server stub, which must convert that stream
into object instances on the server side (this is called unmarshaling ). The server-
side stub then calls the actual method implementation. When the method re-
turns, any return values and changes to the state of the arguments must be
marshaled by the server stub and sent back to the client stub where they are
unmarshaled and stored in the correct locations on the client.
This was the traditionally painful part of writing multitier clients. What
rmic does is automate the generation of these stubs, so writing a remote method
is only slightly more difficult than writing any other method.
The rmic Tool
Search WWH ::




Custom Search