Java Reference
In-Depth Information
signatures for those methods of the object that the server wishes to make publicly
available. A client program can then use the same naming service to obtain a refer-
ence to this interface in the form of what is called a stub . This stub is effectively a
local surrogate (a 'stand-in' or placeholder) for the remote object. On the remote
system, there will be another surrogate called a skeleton . When the client program
invokes a method of the remote object, it appears to the client as though the method
is being invoked directly on the object. What is actually happening, however, is that
an equivalent method is being called in the stub. The stub then forwards the call and
any parameters to the skeleton on the remote machine. Only primitive types and
those reference types that implement the Serializable interface may be used as
parameters. (The serialising of these parameters is called marshalling .)
Upon receipt of the byte stream, the skeleton converts this stream into the origi-
nal method call and associated parameters (the deserialisation of parameters being
referred to as unmarshalling ). Finally, the skeleton calls the implementation of the
method on the server. The stages of this process are shown diagrammatically in
Fig. 5.1 . Even this is a simplifi cation of what is actually happening at the network
level, however, since the transport layer and a special layer called the remote refer-
ence layer will also be involved at each end of the transmission. In fact, the skeleton
was removed entirely in J2SE 1.2 and server programs now communicate directly
with the remote reference layer. However, the basic principles remain the same and
Fig. 5.1 still provides a useful graphical representation of the process.
Fig. 5.1 Using RMI to
invoke a method of a remote
object
Local machine
Remote machine
Client
Server
Method
implementation
Method call
Stub
Skeleton
Apparent invocation flow:
Actual invocation flow:
If the method has a return value, then the above process is reversed, with the
return value being serialised on the server (by the skeleton) and deserialised on the
client (by the stub).
5.2
Implementation Details
The packages used in the implementation of an RMI client-server application are
java.rmi, java.rmi.server and java.rmi.registry , though only the fi rst two need to be
used explicitly. The basic steps are listed below.
 
Search WWH ::




Custom Search