Remote Reference Layer
The Remote Reference Layer is between the Transport layer and the Proxy
layer. It supports communication between the Stub and Skeleton. It is
responsible for passing the stream-oriented data received from the Transport
layer to the Proxy layer and vice versa.
Transport Layer
This layer is responsible for setting and managing connections to remote
machines. It sends to, and receives data from, other machines. When
the transport layer receives a request from the client-side Remote Reference
Layer, it establishes a socket connection to the server. If a significant
amount of time passes with no activity on the connection, the transport
layer is responsible for shutting down the connection.
Distributed
and Non-distributed models
A call to a remote object using RMI is similar to a call to a local
object but there are also some differences. Let(s) first see the
similarities.
- A reference to a remote object can be passed as an argument to a
method or can be returned as a result by a method.
- A remote object can be cast using the Java syntax for casting.
- instanceof operator can be used on remote objects.
The Java distributed object model differs from Java object model
in the following ways:
- A client of a remote object always interacts with the remote interface,
not with the implementing class.
- A non-remote object passed as a parameter to a remote method is
passed by value. In contrary to this, a remote object is passed by
reference.
- The equals(), hashcode() and toString()
methods defined in java.lang.Object
are overridden by java.rmi.server.RemoteObject.
For example, the hashcode() method
returns the same hash code, if two remote object stubs refer to the
same remote object. The toString()
method returns a string representation of the remote object. It includes
information about the port number, host name, etc. The equals(Object
obj) method indicates whether some other object is "equal to"
this one.
- An object, passed as an argument to, or returned by a remote method
must be serializable.
RMI system is organized as a four-layer model.
Application
Layer
Proxy
Layer
Remote
Reference Layer
Transport
Layer
A remote object may be exported in two ways:
By
extending UnicastRemoteObject class
By
using the UnicastRemoteObject(s) exportObject()
methods.
A remote object must implement at least one interface that extends
the java.rmi.Remote interface. A server
registers any remote objects with the rmiregistry. A client can
obtain a reference to a remote object by looking up in the server(s)
registry or as a result of a remote method call.
|