Java Reference
In-Depth Information
written on the server side that implements the interface, and a special compiler
is used to generate stubs for the server side and the client side. On the client
side, a call to an RMI method looks like any other method call, but it is sent
across the network to the server, where the actual instructions are carried out.
Any return value is then passed back over the network to the client.
We will walk you through a very simple (and very pointless) example just
to show you the tools.
5.8.1.3
Our interface is pathetically simple. It is a class that sums two integer arguments
and returns an integer result. Example 5.10 shows the interface file.
Writing the Interface
NOTE
The names of the classes in the following examples may seem a bit strange,
and they are. It is because we aim to build on this example later.
Example 5.10 The Session interface
package net.multitool.RMIDemo;
import java.rmi.*;
public interface Session extends Remote {
public int add(int x, int y) throws RemoteException;
}
The two important things to note here are that the interface must extend
java.rmi.Remote and that any remote method must be defined as throwing
java.rmi.RemoteException . If anything goes wrong during an RMI call,
like someone tripping over a network cable, the call will not complete success-
fully and an exception of that type will be thrown. It is not possible to have a
RMI method that cannot throw this exception.
Beyond those features, you can see that defining remote methods is quite
familiar and easy.
Search WWH ::




Custom Search