Java Remote method Invocation

Home
Members
Discussions
Archive
Installation
Snap Shots
Contact Information

           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.

 

The RMI system consists of three layers: the stub/skeleton layer, the remote reference layer, and the transport layer. The boundary at each layer is defined by a specific interface and protocol; each layer, therefore, is independent of the next and can be replaced by an alternate implementation without affecting the other layers in the system. For example, the current transport implementation is TCP-based (using Java sockets), but a transport based on UDP could be substituted.

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:

bullet The stub/skeleton layer - client-side stubs (proxies) and server-side skeletons
bullet The remote reference layer - remote reference behavior (e.g. invocation to a single object or to a replicated object)
bullet The transport layer - connection set up and management and remote object tracking

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.

A client invoking a method on a remote server object actually makes use of a stub or proxy for the remote object as a conduit to the remote object. A client-held reference to a remote object is a reference to a local stub. This stub is an implementation of the remote interfaces of the remote object and forwards invocation requests to that server object via the remote reference layer. Stubs are generated using the rmic compiler.

The remote reference layer is responsible for carrying out the semantics of the invocation. For example the remote reference layer is responsible for determining whether the server is a single object or is a replicated object requiring communications with multiple locations. Each remote object implementation chooses its own remote reference semantics-whether the server is a single object or is a replicated object requiring communications with its replicas.

Also handled by the remote reference layer are the reference semantics for the server. The remote reference layer, for example, abstracts the different ways of referring to objects that are implemented in (a) servers that are always running on some machine, and (b) servers that are run only when some method invocation is made on them (activation). At the layers above the remote reference layer, these differences are not seen.

The transport is responsible for connection set-up, connection management, and keeping track of and dispatching to remote objects (the targets of remote calls) residing in the transport's address space.

In order to dispatch to a remote object, the transport forwards the remote call up to the remote reference layer. The remote reference layer handles any server-side behavior that needs to be done before handing off the request to the server-side skeleton. The skeleton for a remote object makes an up-call to the remote object implementation which carries out the actual method call.

The return value of a call is sent back through the skeleton, remote reference layer and transport on the server side, and then up through the transport, remote reference layer and stub on the client side.

The Stub/Skeleton Layer:

The stub/skeleton layer is the interface between the application layer and the rest of the RMI system. This layer does not deal with specifics of any transport, but transmits data to the remote reference layer via the abstraction of marshal streams. Marshal streams employ a mechanism called object serialization which enables Java objects to be transmitted between address spaces. Objects transmitted using the object serialization system are passed by copy to the remote address space, unless they are remote objects, in which case they are passed by reference.

A stub for a remote object is the client-side proxy for the remote object. Such a stub implements all the interfaces that are supported by the remote object implementation. A client-side stub is responsible for:

bullet Initiating a call to the remote object (by calling the remote reference layer).
bullet Marshaling arguments to a marshal stream (obtained from the remote reference layer).
bullet Informing the remote reference layer that the call should be invoked.
bullet Unmarshaling the return value or exception from a marshal stream.
bullet Informing the remote reference layer that the call is complete.

A skeleton for a remote object is a server-side entity that contains a method which dispatches calls to the actual remote object implementation. The skeleton is responsible for:

bullet Unmarshaling arguments from the marshal stream.
bullet Making the up-call to the actual remote object implementation.
bullet Marshaling the return value of the call or an exception (if one occurred) onto the marshal stream.

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

The Remote Reference Layer:

The remote reference layer deals with the lower level transport interface. This layer is also responsible for carrying out a specific remote reference protocol which is independent of the client stubs and server skeletons.

Each remote object implementation chooses its own remote reference subclass that operates on its behalf. Various invocation protocols can be carried out at this layer, for example:

·                     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.

In a corresponding manner, the server-side component implements the specific remote reference semantics prior to delivering a remote method invocation to the skeleton. This component, for example, could handle ensuring atomic multicast delivery by communicating with other servers in the replica group.

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.

The Transport Layer:

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 concrete representation of a remote object reference consists of an endpoint and an object identifier. This representation is called a live reference. Given a live reference for a remote object, a transport can use the endpoint to set up a connection to the address space in which the remote object resides. On the server side, the transport uses the object identifier to look up the target of the remote call.

The transport for the RMI system consists of four basic abstractions:

·         An endpoint is the abstraction used to denote an address space or Java virtual machine. In the implementation, an endpoint can be mapped to its transport. That is, given an endpoint, a specific transport instance can be obtained.

·         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.

A transport defines what the concrete representation of an endpoint is, so multiple transport implementations may exist. The design and implementation also supports multiple transports per address space, so both TCP and UDP can be supported in the same virtual machine.

The Transport Layer

Dynamic Class Loading:

In RPC (remote procedure call) systems, client-side stub code must be generated and linked into a client before a remote procedure call can be done. This code may be either statically linked into the client or linked in at run-time via dynamic linking with libraries available locally or over a network file system. In either the case of static or dynamic linking, the specific code to handle an RPC must be available to the client machine in compiled form.

RMI generalizes this technique, using a mechanism called dynamic class loading to load at runtime (in the Java language's architecture neutral bytecode format) the classes required to handle method invocations on a remote object. These classes are:

bullet The classes of remote objects and their interfaces.
bullet The stub and skeleton classes that serve as proxies for remote objects. (Stubs and skeletons are created using the rmic compiler.)
bullet Other classes used directly in an RMI-based application, such as parameters to or return values from remote method invocations.

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

 

 

Data size

10 Bytes

100 Bytes

1 kByte

10 kBytes

50 kBytes

100 kBytes

1 MByte

10 MByte

RMIClient

22.9

19.6

34.8

113.1

436.7

838.4

8,354.8

83,087.5

SocketClient

200.5

200.5 

200.5 

105.2

430.5 

833.4

8,291.1

83,326.8

ServletClient

205.8

200.3

200.3

96.0

421.2

828.8 

8,395.7

84,469.4 

GzipSocketClient

200.8

200.8

200.4

106.5

454.8

891.5

8,903.6

88,840.8

LargeSocketClient

200.5

200.5

200.5

104.2

394.6

742.9

7,213.2

71,763.2

Total round-trip time in milliseconds

         

Data size

1 kByte

10 kBytes

50 kBytes

100 kBytes

1 MByte

10 MByte

RMIClient

28

88

114

120

122

123

SocketClient

5

95

116

120

123

123

ServletClient

5

104

119

120

122

121

GzipSocketClient

5

94

110

112

115

115

LargeSocketClient

5

96

126

135

142

143

Round-trip data rate in kByte/sec

Home | Members | Discussions | Archive | Installation | Snap Shots | Contact Information

 No Modifications in the above project is allowed without proper permissions
For problems or questions regarding this Project contact [susheelelango@yahoo.co.in] or [gunasekaranmohan@yahoo.com]