Java Reference
In-Depth Information
for brevity in the code snippets shown above. The complete source code is also
available on the Web Course site with slightly different formatting than shown
here. After listing the code, we also show the step-by-step instructions needed to
run this example.
We use a root package name of javatech.rmi18 for this example. The
remote interface file is in package javatech.rmi18.server ,inasubdi-
rectory named javatech/rmi18/server .(We use the Unix standard for-
ward slash as a directory separator. Windows users need to mentally replace
the / with a “\ .) To recap the role of this interface, it declares each
method that is to be remotely callable. It must extend the java.rmi.Remote
interface, and each remote method must be declared to throw java.rmi.
RemoteException .
// RMIExampleInterface.java
package javatech.rmi18.server;
import java.rmi.Remote;
import java.rmi.RemoteException;
/** The remote interface for use with the RMI Example
*inCh.18. **/
public interface RMIExampleInterface extends Remote
{
public void method1 (String s) throws RemoteException;
public int add (int a, int b) throws RemoteException;
} // interface RMIExampleInterface
Next comes the class that implements the remote methods declared by
the remote interface. This class obviously must contain an implements
RMIExampleInterface clause. It must also extend UnicastRemoteOb-
ject and must provide an implementation of each of the remote methods
declared
in
the
interface.
It
may
also
include
other
methods,
such
as
the doSomethingLocal() method.
We find it convenient to keep our remote interfaces separate from the imple-
mentation classes, so we put the implementation classes into an impl subdirec-
tory below the directory containing the interface itself. Therefore, the package
for the implementation classes is named javatech.rmi18.server.impl .
Another choice that keeps the interfaces and implementations separate is to put
the interfaces into something like a javatech.rmi18.server.interfaces
package. Alternatively, it is perfectly legal for the interfaces and implementations
to be kept together in the same package called, say, javatech.rmi18.server .
 
Search WWH ::




Custom Search