Java RMI (Remote Method Invocation)
RMI allows client Java objects to invoke remote Java objects as
if they were local to the client. The RMI architecture separates
the code that defines the behaviour and the code that implements
the behaviour to remain separate and run on separate JVM's. Figure
2 illustrates this separation.
Figure 2. Separation of behaviour
and implementation
It should be noted that a Java interface
contains no executable code. Instead RMI supports two classes
that implement the same interface. The first class, run on the
server, is the implementation of the behaviour and the second
class, run on the client, acts as a proxy for the remote service.
Figure 3 illustrates this structure.
Figure 3. RMI implementation structure
When a method is 'called on the remote
object' the call is actually made on the proxy object or stub
object. RMI sends the request to the remote JVM, and forwards
it to the implementation. Return values produced by the implementation
are sent back to the proxy and then to the client [2].
Architecture
RMI is formed of three abstraction layers:
Stub and Skeleton - RMI uses a proxy pattern to forward method
calls between the participating objects, Figure 4 illustrates
the stub and skeleton role.

Figure 4. role of the stub and the
skeleton
Remote Reference Layer - This
layer understands how to interpret and manage references made
from clients to the remote service objects.
Transport Layer - Based on TCP/IP connections
between machines in a network, this layer provides basic connectivity,
as well as some firewall penetration strategies.
Naming Remote Objects
When a server program creates an object (implementing a service)
it registers the object in the RMI Registry under a public name.
The client locates the remote server via the static lookup() method
of rmi.Naming class. The lookup() method accepts a URL that specifies
the server host name and the name of the desired service. The
method returns a remote reference to the service object. The URL
takes the form:
rmi://<host_name>
[:<name_service_port>]
/<service_name>
where the host_name is
a name recognized on the local area network (LAN) or a DNS name
on the Internet. The name_service_port
only needs to be specified only if the naming service is running
on a different port to the default [2].
As with the implementation of traditional classes
the server has to set a securityManager and bind itself to the
local rmiregistry in order to be available to it's clients. Remote
methods must throw RemoteException's to indicate problems in the
remote connection.
All the required classes for RMI implementation
are included in the JDK development kit (java.rmi.*)
Next Page