RMI 2

Objects sending messages to each other. Sources: Horstmann and Cornell, CoreJava , Prentice Hall, Vol. 2, 1998. Orafali and Harkey, Client/Server Programming with Java and CORBA, Wiley, 1997.

Corba (http://www.omg.org)

Common Object Resource Broker Architecture. Objects can talk to each other regardless of the language or platform of implementation through the CORBA mechanism for data interchange and service discovery. The task of discovery is delegated to an Object Resource Broker. Objects don’t talk directly to each other, but do so through the ORB. CORBA is completely language neutral.

RMI

RMI is an ORB, but is java-centric. It is base on the java language object model, and is best suited for communications between Java objects. It handles all the details of the transport layer for you, such as data encoding, transmission and retransmission, and protocols. You can invoke the methods of objects on other machines, hence the name remote method invocation. The code on a client calls a method on a server. Actually, it calls a regular Java method that is encapsulated in a stub class. Objects that are referenced are serialized with the default Java object serialization which flattens a local Java object's state into a serial stream that it can then pass as a parameter inside a message. This mechanism is like call-by-value rather than call-by-reference. On the other hand, you can invoke methods over the network, so it passes the object by reference, not by copying the actual object over the network. If you want to customize, you have to override the writeObject() and readObject() methods. All remote objects have be serializable. The default mechanism writes all fields except transient and static, to the ObjectOutputStream. The parameters in the remote method are packaged as byte streams. The process of encoding the parameters for transport is called marshalling. The stub sends the information to the server

A stub consists of:

    1. An identifier of the remote object.
    2. An operation number specifying the method called.
    3. The marshalled parameters

On the server side, the skeleton object interprets the information from the stub, and passes it to the object that executes the remote method. It does 5 things on every call:

    1. Unmarshalls the parameters
    2. Calls the desired method
    3. captures return value or exception
    4. marshalls that value
    5. and sends it to the client stub.

Dynamic Class Loading

Stub classes can be put on the machine local to the client, or can be loaded over the network in a manner similar to applets. The stub class loader determines where the classes are, loads them, and uses a security manager to determine what they can do. The stub security manager is more restrictive than the applet security manager.

The idea of dynamic loading is that the client can download stubs, dynamically, from the server. Requires 1) class loader 2) security manager 3) object serialization. First looks in local file system specified with CLASSPATH. If not on local file systems, it 1) server tells client where the stub is by making the URL available as part of the object reference through RMI marshalling, or 2) Stubs loaded from URL in the clients java.rmi.server.codebase property (static configuration).

Stubs are prevented from 1) Accepting connections. 2) Listening on any port. 3) Manipulating threads outside their thread groups. 4) Fork processes. 5) Create Class loaders. 6) Link to DLL’s. 7) Exit from a JVM. 8) Access properties. 9) open file descriptors.

Passing Nonremote Objects

Can pass and return any objects via a remote method call. No stub class, however, is created for non-Remote objects. What you get is a copy of the object. Must be serializable. Remote objects are passed across network as stubs, non-remote objects are copied. Remote objects remain on the server.

RMI and Applets

Applets have their own security managers, and therefore, remote objects don’t need their own security manager. For an applet and RMI, the host must store Web page, applet code, stub code, skeleton code, and bootstrap registry.

Steps to setting up RMI

    1. Place interface class, which extends Remote on the client and server.
    2. Place class extending RemoteObject on server.
    3. Generate stubs and skeleton by running rmic. Copy the stubs to the client.
    4. Start the registry on server.
    5. Start program that creates and registers objects on the server.
    6. Run program that looks up server objects and invokes remote methods.

RMI Core

RMI Naming Service