Java Reference
In-Depth Information
were local. You should be able to call methods on a proxy object that forwards the calls to the
real object on the remote machine. In fact, such schemes have been realized, notably in the
common object request broker architecture ( CORBA ) and in Java's remote method
invocation ( RMI ).
RMI makes it about as easy as possible for a client to obtain a proxy object that forwards calls
to a desired object that is active on another computer. It is well worth learning about RMI, as
RMI is part of the underpinning of the Enterprise JavaBeans ( EJB ) specification, an
important emerging industry standard. Regardless of how industry standards evolve, the role
of P ROXY in distributed computing will continue into the foreseeable future, and RMI
provides a good example of this pattern in action.
To experiment with RMI, you will need a good reference on this topic, such as Java™
Enterprise in a Nutshell (Flanagan et al. 1999). The following example is not a tutorial on
RMI but merely points out the presence and value of P ROXY within RMI applications.
Suppose that you decide to explore the workings of RMI, making an object's methods
available to a Java program running on another computer. The initial development step is to
create an interface for the class that you want to provide remote access to. As an experimental
project, suppose that you create a Rocket interface that is independent of existing code at
Oozinoz:
package com.oozinoz.remote;
import java.rmi.*;
public interface Rocket extends Remote
{
void boost(double factor) throws RemoteException;
double getApogee() throws RemoteException;
double getPrice() throws RemoteException;
}
The Rocket interface extends Remote , and the methods in the interface all declare that they
throw RemoteException . The reasons for these aspects of the interface lie outside the
scope of this topic, but any topic that teaches RMI should cover them. Your RMI source
should also explain that, to act as a server, the implementation of your remote interface can
subclass UnicastRemoteObject , as Figure 11.5 shows.
Search WWH ::




Custom Search