Remote Method Invocation

Client Server Java Programming
Remote Method Invocation
EJB
Navigate Concurrent Programming topic: v  d  e )


Java's Remote Method Invocation (commonly referred to as RMI) is used for client and server models. RMI is the object oriented equivalent to RPC (Remote procedure call).

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.

RMI is defined to use only with the Java platform. If you need to call methods between different language environments, use CORBA. With CORBA a Java client can call C++ server and/or a C++ client can call a Java server. With RMI that can not be done.

STUB and SKELETONEdit

The remote method invocation goes through a STUB on the client side and a so called SKELETON on the server side.

CLIENT --> STUB --> ... Network ... --> SKELETON --> REMOTE OBJECT


rmiregistryEdit

Remote objects are listed in the rmiregistry. Clients will get a reference to the remote object by querying the rmiregistry. After that, the client can call methods on the remote objects.

The rmiregistry is a separate process that has to be started before remote objects can be added to it. It can be started by the command line in Unix:

Computer code rmiregistry on Unix
rmiregistry <port> &

or under Windows:

Computer code rmiregistry on Windows
start rmiregistry <port>

If the port is not specified the default 1099 is used. The client will need to connect to this port to access the remote object.

The rmiregistry can also be started from a program by calling the following code:

Example Code section 1: rmiregistry starting
import java.rmi.registry.LocateRegistry;
...
Registry reg = LocateRegistry.createRegistry(iPort);

Objects passed in as parameters to the remote objects's methods will be passed by value. This is the only thing developers need to keep in mind (program logic wise) when using remote objects. If the remote object changes the passed in object values, it won't be reflected on the client side, this is opposite what happens when a local object is called. Objects that used as parameters for remote methods invocation, must implement the java.io.Serializable interface, as they are going to be serialized when passed through the network, and a new object will be created on the other side.

rmic toolEdit

Clipboard

To do:
Complete this section.

RMI Remote objectEdit

The remote object has to extend the java.rmi.server.UnicastRemoteObject object.

RMI clientsEdit

Clipboard

To do:
Complete this section.


Clipboard

To do:
Add some exercises like the ones in Variables

Client Server Java Programming
Remote Method Invocation
EJB
Last modified on 31 October 2012, at 05:16