oval


Centre International de Mathİmatiques Pures et Appliquİes
International Center for Pure and Applied Mathematics


A CIMPA-UNSA-INRIA-UNESCO-VIETNAM SCHOOL ON


Objects and Network
Distributed Objects Courses


Emmanuel Chailloux
Emmanuel.Chailloux@lip6.fr
http://www-spi.lip6.fr/~emmanuel

SUMMARY
Distributed Objects:
Distributed Objects

Copying remote objects:

sockets + persistence Ş transport of objects by copy (and creation of new instances)


Sharing remote objects:

References to a remote object from different network places to the same object
to invoke its methods and/or to modify its instance variables.

GOALS:

Implementation difficulties
jdk 1.1 proposes a basic mechanism, called RMI (Remote Method Invocation) to manipulate remote objects.

RMI

Architecture

Server
The server part is more complicated for the following services :

Packages
packages are : The remote objects interface extends the Remote interface and adds some methods, which can throw RemoteException.

Packages description
in java.rmi
in java.rmi.server

Example : Remote Points

Interface: indentation
import java.rmi.*;
public interface PointRMI extends Remote {

void moveto (int a, int b) throws RemoteException;

void rmoveto (int dx, int dy) throws RemoteException;

void display() throws RemoteException;

double distance() throws RemoteException;

}

Remote interfaces implementation
Interface implementation: indentation

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class PointD extends UnicastRemoteObject
implements PointRMI {

int x,y;
PointD(
int a, int b) throws RemoteException {x=a;y=b;}
PointD()
throws RemoteException {x=0;y=0;}

public void moveto (int a, int b)
throws RemoteException
{x=a; y=b;}

public void rmoveto (int dx, int dy)
throws RemoteException
{x = x + dx; y = y + dy;}

public void display()
throws RemoteException
{System.out.println(
"(" + x + "," + y + ")");}

public double distance()
throws RemoteException
{
return Math.sqrt(x*x+y*y);}
}

Compilation
rmic PointD will create the files : PointD_Stub.class (for clients) and PointD_Skel.class (for servers).

Creation and registration
The points server will create PointD instances and will registry them (rebind) to the rmiregistry daemon which manages the rmi protocol.

indentation
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class Creation {

public static void main (String args[]) {
System.setSecurityManager(
new RMISecurityManager());
try {
PointD p0 =
new PointD();
PointD p1 =
new PointD(3,4);
Naming.rebind(
"//etretat.lip6.fr/point0",p0);
Naming.rebind(
"//etretat.lip6.fr/point1",p1);
System.out.println(
"Distributed Objects 'p0'" +
" and 'p1' are registried");
}
catch (Exception e) {e.printStackTrace();
}
}
}

Server running

Naming service:
$ rmiregistry&
Server:
$  java Creation
Distributed Objects 'p0'
and 'p1' are registried
A client

indentation
import java.rmi.*;
public class ClientP {
public static void main( String argv[]) {
String url0=
"rmi://etretat.lip6.fr/point0";
String url1=
"rmi://etretat.lip6.fr/point1";
try {
PointRMI p0 = (PointRMI)Naming.lookup(url0);
PointRMI p1 = (PointRMI)Naming.lookup(url1);
p0.display(); p1.display();
p0.rmoveto(7,12);
p1.rmoveto(5,6);
p0.display(); p1.display();
if (p0.distance() == p1.distance())
System.out.println(
"same distance!!!");
else
System.out.println(
"different distance");
}
catch (Exception e) {
System.err.println(
"exception : " +
e.getMessage());
e.printStackTrace();
}}}

Client running

first execution:
(0,0)
(3,4)
(7,12)
(8,10)
different distance
second execution:
(7,12)
(8,10)
(14,24)
(13,16)
different distance
Concurrent calls
may or not may execute in a separate thread To use synchronized methods for the remote objects!!!

Concurrent Clients
etr: java ClientP C1 & \
     java ClientP C2 & java ClientP C3
[2] 32212
[3] 32213
C3.p0(112,192)
C1.p0(112,192)
C1.p1(83,100)
C1.p0(119,204)
C1.p1(88,106)
C3.p1(88,106)
C3.p0(126,216)
C3.p1(93,112)
C1 : different distance
[2]    Done                  java ClientP C1
C3 : different distance
C2.p0(126,216)
C2.p1(93,112)
C2.p0(133,228)
C2.p1(98,118)
C2 : different distance
[3]    Done                  java ClientP C2
Exceptions
Different cases:
Communication port
Default port for the rmi service is : 1099,
but the rmiregistry can be running on another port :
rmiregistry 2000&
this new port must be used for the URL :
//youpou.lip6.fr:2000
Distributed GC

What is the problem?:

cleans the external reference to an object (in the server side)
Java solution
in java.rmi.dgc package :
A reference to a remote object is leased for a period of time by the client holding the reference.
Interface DGC
indentation
package java.rmi.dgc;

import java.rmi.server.ObjID;

public interface DGC extends java.rmi.Remote {

Lease dirty(ObjID[] ids,
long sequenceNum, Lease lease)
throws java.rmi.RemoteException;

void clean(ObjID[] ids, long seqNum, VMID vmid, boolean strong)
throws java.rmi.RemoteException;
}

For each exported remote object in the local virtual machine, the garbage collector maintains a reference list -- a list of clients that hold references to it.

The clean call removes the vmid from the reference list of each remote object indicated in ids.

CORBA

Common Object Request Broker Architecture : standard (OMG - 1990) allows : To be independent :
Architecture

IDL
Interface Definition Language allows to describe visible methods and fields from objects.
Accept simple or multiple interface inheritance.

Point.idl:
interface Point {
  void moveto(in int a, in int b);
  void rmoveto(in int dx, in int dy);
  void display();
  double distance();
}
From this description, the IDL compiler (given with ORBs), generates stub and skeletons fro the server, and that for different languages (Smalltalk, C++, Java ...)

CORBA and Java

Java IDL: classes, libraries and tools to use CORBA object from Java, contains : Java IDL conforms to IIOP 1.0 (Internet InterORB Protocol).

Java IDL : development process

  1. To define the remote interface : Point.idl
  2. To compile the remote interface, which generates Java version of the interface, and class code files for the stubs and skeletons
  3. To implement the server, by using skeletons
    to implement remote interface, server code includes the ORB starting and waits for invocation.
  4. To implement the client, by using stubs : to start its ORB
    look up the server using the name service, to obtain a reference to remote object and to call its method.
  5. To start the applications
    to start the name service, then to start the server, then to run the clients
RMI and CORBA

same ideas (RMI technology was inspired by CORBA) : CORBA is a standard (OMG = 500 companies), RMI not
CORBA gives a better registration services


RMI vs CORBA
 RMICORBA
versionJDK1.1.6JDK 1.2 Beta 4
communicationJava machinesIIOP
servicesminimalbetter
performancesbadvariable
DGCyesno
costfree licencejavatoidl ??
old programsnotpossible
usagesimplermore complex


This document was translated from LATEX by HEVEA.