Java Reference
In-Depth Information
Pattern Use
Abstract Factory (see page 6): The Abstract Factory pattern is used to create families of related products. In RMI,
the RMISocketFactory implements this pattern by defining methods to create the sockets used in RMI
communications. The RMISocketFactory defines abstract methods to create the client and server sockets used
for RMI communications. On a specific JVM, a concrete subclass of RMISocketFactory will provide the
functionality to create the RMI sockets.
Factory Method (see page 21): An Abstract Factory will often use one or more Factory Methods to create its
individual products. The two interfaces implemented by RMISocketFactory, RMIClientSocketFactory and
RMIServerSocketFactory , define factory methods for the creation of client and server sockets, respectively.
These interfaces are implemented in RMISocketFactory as abstract methods, and a subclass supplies concrete
implementations of these methods for RMI during runtime.
Decorator (see page 166): The Decorator pattern lets you extend an object's functionality by creating another
object. This object has the same interface as the original and references the original object for most operations,
but adds some additional features.
RMI uses the Decorator pattern during object serialization. When RMI sends objects to another address space, the
objects are marshalled; the java.rmi.MarshalledObject class handles the task of sending and receiving copies
of the objects. To do this, the MarshalledObject class uses a sub-class of the java.io.ObjectOutputStream
and the java.io.ObjectInputStream during communication. These special subclasses extend the basic
functionality of their underlying java.io.InputStream and java.io.OutputStream by allowing two
MarshalledObjects to be compared for equality even if they reside on different JVMs.
Proxy (see page 197): The RMI stub, which is used by a client to communicate with a server object, is an
implementation of the Proxy pattern. The stub implements the same remote interface as the remote object on the
server, so it acts as the remote object for the RMI client. When a client makes a remote call, the stub forwards the
method call to the real remote object on the server. The benefit here is that the network communication is hidden
from the client. It frees the client from setting up connections, managing a communication session and
participating in distributed garbage collection.
Search WWH ::




Custom Search