RMI
[RemoteMethodInvocation]
Three main Distributed Technologies which are in use are:
- Java RMI(Remote Method Invocation) from Sun Micro Systems.
- CORBA(Common Object Request Broker Architecture) from OMG(ObjectManagementGroup)
- DCOM(Distributed Component Object Model) from Microsoft
Distributed Computing is started with RPC(Remote Procedure Call) technology.
A special S/W called PortMapper takes the client request and Connect him to the requested Application. so client must remember the port number.
The Server does not maintain the state.
Advantages:
- 1. Every Object will have a Unique name. so that client can remember easily
- 2. we can send and receive objects through network
- 3. RMI separates Interfaces from Implementations.
The stubs and skeletons performing the marshaling and unmarshaling of data
A Remote stub uses a remote reference to carry out a remote method invocation to a remote object.
Transport layer makes the stream based network connections over TCP/IP between JVMs .It provides basic connectivity.
RMI allows object to object communication between different virtual machines(JVM). JVM can be distinct entities located on the same or separate computer yet one JVM can invokes methods belonging to an object stored in another JVM. This enables application to call object methods located remotely, sharing resources and processing load across systems. if both communication objects are written java programming langs we use RMI
RMI is easier to understand and convenient to use.
In java, distributed object model, a remote object is one whose methods can be invoked from another java virtual machine Potentially on different host. An object of this type can be described by one or more remote interface which are java interfaces that declare the methods of remote object.
Remote method invocation is the action of invoking a methods of a remote interface on a remote object.
Client:
The JVM that calls the remote object is usually referred to as a client.
Server:
The JVM that contains the remote object is usually referred to as a server.
Remote object is always accessed via its remote interface. In other words, the client invokes the methods on the object only after casting the reference remote interface.
Stubs and skeleton layer:
The stub and skeleton acts as an interface between an application and rest of the RMI system. Its purpose is to transfer data to the remote reference layer via marshalling and unmarshalling. Marshalling refers to process of converting data or object being transferred into byte stream and unmarshalling is convert stream into an object or data. This conversion is achieved via object serialization.
The following list the sequence of events performed by the stub:
1. Initiates the connection with a remote virtual machine containing the remote object.
2. Marshall the parameters to the remote virtual machine.
3. Wait for the result of the method invocation.
4. Unmarshall the return value or exception returned.
5. Return the value to the caller.
Skeleton:
The following list the sequence of the events performed by the skeleton.
1. Unmarshall the parameter for the remote method.
2. Invokes the method on the actual remote object implementation.
3. Marshall the result to the caller.
The jdk contains the rmic tool that creates the class files for stubs and skeleton
Locating Remote Object
Clients find the remote services by using the naming or directory services.
RMI naming service, a registry is a remote object that serves as a directory Service for client. The behavior of the registry is defined by the interface java.rmi.registry.Registry. RMI registry runs on each machine that hosts remote object accepts queries for services by defined on the port 1099.
In simple the remote object is associate with a name in this registry. Anytime the client invokes methods on this remote object it obtains to a
reference to it by looking up the name. Naming class specially locates objects in the RMI registry.
Client connects to the Remote Registry by using the computer name and port no.
Naming class is used to bind the Objects to RMI Registry
Method Description
Public static void bind(String name, Remote obj) Binds the remote
object to a string name.
public static string [] list (String name) Returns an array of names
bounded to the registry.
Pubic static Remote lookup(String name) Return a reference a stub
for the remote object
associated with specified name.
public static void rebind (String name, Remote obj) Rebinds the specified
name if it is already in use to a new remote object.
Public static void unbind (String name) Removes the binding with the
specified name.
Developing application with RMI:
Writing client server application using RMI involves six basic steps:
1. Defining a remote interface.
2. Implementing the remote interface.
3. Writing the client that uses the remote object.
4. Generating stubs and skeletons.
5. Starting the registry and registering object.
6. Running the server and client.