Java Remote method Invocation |
The Java Remote Method Invocation (RMI) system allows an object running in one Java Virtual Machine (VM) to invoke methods on an object running in another Java VM. RMI provides for remote communication between programs written in the Java programming language.
To accomplish transparent transmission of objects from one address space to another, the technique of object serialization (designed specifically for the Java language) is used. Object serialization is described in this chapter only with regard to its use for marshaling primitives and objects. Another technique, called dynamic stub loading, is used to support client-side stubs which implement the same set of remote interfaces as a remote object itself. This technique, used when a stub of the exact type is not already available to the client, allows a client to use the Java language's built-in operators for casting and type-checking.
The RMI System Architectural Overview: The RMI system consists of three layers:
The application layer sits on top of the RMI system
Relationship between RMI Layers A remote method invocation from a client to a remote server object travels down through the layers of the RMI system to the client-side transport, then up through the server-side transport to the server.
The appropriate stub and skeleton classes are determined at run time and are dynamically loaded as needed, as described in Dynamic Class Loading. Stubs and skeletons are generated using the rmic compiler.
The Stub/Skeleton Layer · Unicast point-to-point invocation. · Invocation to replicated object groups. · Support for a specific replication strategy. · Support for a persistent reference to the remote object · Reconnection strategies (if remote object becomes inaccessible). The remote reference layer has two cooperating components: · the client-side components · the server-side components.
The client-side component contains information specific to the remote server (or servers, if the remote reference is to a replicated object) and communicates via the transport to the server-side component. During each method invocation, the client and server-side components perform the specific remote reference semantics. For example, if a remote object is part of a replicated object, the client-side component can forward the invocation to each replica rather than just a single remote object. The remote reference layer transmits data to the transport layer via the abstraction of a stream-oriented connection. The transport takes care of the implementation details of connections. Although connections present a streams-based interface, a connectionless transport may be implemented beneath the abstraction. In general, the transport layer of the RMI system is responsible for: · Setting up connections to remote address spaces. · Managing connections. · Monitoring connection "liveness." · Listening for incoming calls. · Maintaining a table of remote objects that reside in the address space. · Setting up a connection for an incoming call. · Locating the dispatcher for the target of the remote call and passing the connection to this dispatcher. The transport for the RMI system consists of four basic abstractions: · A channel is the abstraction for a conduit between two address spaces. As such, it is responsible for managing connections between the local address space and the remote address space for which it is a channel. · A connection is the abstraction for transferring data (performing input/output). · The transport abstraction manages channels. Each channel is a virtual connection between two address spaces. Within a transport, only one channel exists per pair of address spaces, the local address space and a remote address space. Given an endpoint to a remote address space, a transport sets up a channel to that address space. The transport abstraction is also responsible for accepting calls on incoming connections to the address space, setting up a connection object for the call, and dispatching to higher layers in the system.
The Transport Layer
Serialization:Serialization is the process of writing the state of an object to a byte stream. This is useful when we want to save the state of our program to a persistent storage area, such as a file. At a later time, we may restore these objects by using the process of deserialization. Serialization is also needed to implement RMI. RMI allows a Java object on one machine to invoke a method on a different machine. An object may be supplied as an argument to that remote method. The sending machine serializes the object and transmits it. The receiving machine deserializes it.
Why RMI and not Sockets: The question of why to use RMI and not the server sockets for the server-client communication is answered here with a simple analysis in a network Using the echo service (which requires no computation time on the server, except for unpacking and repacking the argument and result) the throughput packet measures round-trip time for each of the two kinds of communications. It measures the round-trip time for a call on the client, with argument and result both of the same size. The round-trip time includes the overall time for · opening the connection on the client (from scratch each time) · serializing and sending the argument from the client · receiving and deserializing the argument on the server · calling a dummy echo() function · serializing and sending the result from the server · receiving and deserializing the result on the client The Total round-trip time in milliseconds obtained by using both the methodologies of RMI and Sockets is tabulated as follows
Total round-trip time in milliseconds
Round-trip data rate in kByte/sec |
|