Java Reference
In-Depth Information
Sidebar 13.1 Java RMI
Java RMI is a middleware framework that allows a client application to invoke a method of an
object residing in a different address space, i.e. that is a remote object. Let's consider the example
depicted in the figure below. Classes Naming , Remote and UnicastRemoteObject are provided by the
Java RMI package. Classes SumStub and SumSkeleton are automatically generated by the RMI com-
piler. The other classes are defined by the programmer.
The Client object and the Server objects reside on two different networked computers, each one
being identified by a unique IP address. The Server creates an object of class SumImplementation
that exports the int sum(int a, int b) method defined in interface SumInterface . The RMI framework
allows a Client to invoke the sum method on a SumImplementation object by passing its actual
parameters and getting the result.
This is accomplished by means of two ancillary objects called the SumStub and the SumSkeleton .
The Stub is a surrogate (proxy) of the remote object and resides in the client's address space. It
offers the same set of operations as the remote object, i.e. the sum method. The Stub is in charge of
marshalling the client's request and transmitting it through the network. The Skeleton resides in
the Server address space and is in charge of receiving and unmarshalling the client's request and of
invoking the corresponding operation of the SumImplementation object. The matched pair
Skeleton is automatically generated at compile time from the definition of SumInterface .
In order to make the SumImplementation object accessible from a remote application, the Server
must register it with a symbolic name using the Naming class's bind method. Once a remote object
is registered on the local host, clients on a remote host can look up the remote object by name
using the Naming class's lookup() method, obtain its reference and then invoke remote methods on
the object.
void bind(String name,
Remote obj)
Remote lookUp
(String name)
int sum(int a, int b)
int sum()
int sum(int a, int b)
int sum(int a, int b)
Search WWH ::

Custom Search