Remote Method Invocation
RMI provides support for accessing Java classes on remote systems.Here is an example
of Remote Method Invocation that allows us to access the
Cso database on umslvma.umsl.edu. Sun Microsystems provides complete documentation on RMI in their Remote Method Invocation Specification. In addition to the creation of at least three classes, using RMI requires the performance of a number of steps. One of these involving the proper distribution of various files to the pararticipating systems. We will detail these steps, but first we will look at the source files used to generate the Cso query applet. They are
As stated by Sun Microsystems in its documentation mentioned above, "The goals for supporting distributed objects in the Java language are:
- Support seamless remote invocation on objects in different virtual machines.
- Support callbacks from servers to applets.
- Integrate the distributed object model into the Java language in a natural way while retaining most of
the Java language's object semantics.
- Make differences between the distributed object model and local Java object model apparent.
- Make writing reliable distributed applications as simple as possible.
- Preserve the safety provided by the Java runtime environment."
Quoting again from Sun's Remote Method Invocation Specification
"In the Java distributed object model, a remote object is one whose methods can be invoked from another Java Virtual Machine, potentially on a different host. An object of this type is described by one or more remote interfaces, which are Java interfaces that declare the methods of the remote object.
Remote method invocation (RMI) is the action of invoking a method of a remote interface on a remote object. Most importantly, a method invocation on a remote object has the same syntax as a method invocation on a local object.
The Distributed and Non-Distributed Models Contrasted
The Java distributed object model is similar to the Java object model in the following ways:
A reference to a remote object can be passed as an argument or returned as a result in any method invocation (local or remote).
A remote object can be cast to any of the set of remote interfaces supported by the implementation using the built-in Java syntax for casting.
The built-in Java instanceof
operator can be used to test the remote interfaces supported by a remote object.
The Java distributed object model differs from the Java object model in these ways:
- Clients of remote objects interact with remote interfaces, never with the implementation classes of those interfaces.
- Non-remote arguments to and results from a remote method invocation are passed by copy rather than by reference. This is because references to objects are only useful within a single virtual machine.
- A remote object is passed by reference, not by copying the actual remote implementation.
- The semantics of some of the methods defined by class
Object
are specialized for remote objects.
- Since the failure modes of invoking remote objects are inherently more complicated than the failure modes of invoking local objects, clients must deal with additional exceptions that can occur during a remote method invocation."
Next, here is Sun's description of the RMI architecture.
Finally, the steps necessary to create the "Cso applet."
javac *.java
rmiregistry &
rmic -d //accounts/faculty/siegel/public_html/java1.1/part5/rmi CsoImpl1
java -Djava.rmi.server.codebase=http://jinx.umsl.edu/~siegel/java1.1/part5/rmi/ CsoImpl1 &
Check for a more complete description.