Java Reference
In-Depth Information
Chapter 9. Remote Method Invocation
and Object Serialization
So far, I have talked a lot about how to build a program. But just as all programs can be broken
down into more basic objects, most programs these days are part of a larger system of inter-
acting programs. Breaking a system apart into a number of different programs has a lot of ad-
vantages, including independence of failure, security through isolation of parts, and the ability
to change parts without interrupting the overall system. But it also requires that there be some
way for the various programs to interact.
Historically, programs have interacted in different ways depending on how those programs
were deployed. Programs that were guaranteed to run on the same computer would interact
using inter-process communication mechanisms (IPCs), whereas programs that might be run-
ning on different computers would use some form of network communication. The commu-
nication might take a low-level form such as sockets, where the communicating programs
send bits over the wire and are responsible for interpreting those bits. But since the early
1980s, a more common form of communication has been remote procedure call (RPC), which
wraps much of the mechanism used to communicate between programs in a façade that makes
the communication look like a procedure or method call.
Java's Remote Method Invocation (RMI) system is, on the surface, such a remote procedure
call mechanism. Indeed, over the years, RMI has been expanded in a number of ways so that
some uses (such as RMI over IIOP) are just a Java wrapper over more common RPC mechan-
isms (in the case of RMI over IIOP, the wrapper is around the CORBA RPC system).
But the original RMI [ 28 ] (now sometimes called RMI over JRMP) is a lot more interesting
than it might first appear. It can also be very useful. Understanding what it can do and how to
use it can make a programmer's life easier and more interesting. To fully understand RMI, we
also need to dip into object serialization, which was originally used simply to pass arguments
and return values in RMI, but is now used for much more. These two parts of Java are often
maligned, misunderstood, and abused. But once understood, they are definitely in the good
parts of Java. [ 29 ]
 
 
Search WWH ::




Custom Search