03 Remote Invocation
03 Remote Invocation
Remote Invocation
Figure 5.1
Middleware layers
Applications
This chapter
Remote invocation, indirect communication
(and Chapter 6)
Middleware
Underlying interprocess communication primitives: layers
Client Server
Request
doOperation
message getRequest
select object
(wait) execute
Reply method
message sendReply
(continuation)
Figure 5.3
Operations of the request-reply protocol
// In file Person.idl
struct Person {
string name;
string place;
long year;
};
interface PersonList {
readonly attribute string listname;
void addPerson(in Person p) ;
void getPerson(in string name, out Person p);
long number();
};
Figure 5.9
Call semantics
Request
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Figure 5.11
Files interface in Sun XDR
remote local C
invocation invocation local E
remote
invocation invocation F
A B local
invocation D
Figure 5.13
A remote object and its remote interface
remoteobject
Data
remote
interface
m1 m4
{
implementation m5
m2
of methods m6
m3
Figure 5.14
Instantiation of remote objects
Figure 5.15
The role of proxy and skeleton in remote method invocation
Figure 5.16
Java Remote interfaces Shape and ShapeList
import java.rmi.*;
import java.util.Vector;
public interface Shape extends Remote {
int getVersion() throws RemoteException;
GraphicalObject getAllState() throws RemoteException; 1
}
public interface ShapeList extends Remote {
Shape newShape(GraphicalObject g) throws RemoteException; 2
Vector allShapes() throws RemoteException;
int getVersion() throws RemoteException;
}
Figure 5.17
The Naming class of Java RMIregistry
import java.rmi.*;
public class ShapeListServer{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try{
ShapeList aShapeList = new ShapeListServant(); 1
Naming.rebind("Shape List", aShapeList ); 2
System.out.println("ShapeList server ready");
}catch(Exception e) {
System.out.println("ShapeList server main " + e.getMessage());}
}
}
Figure 5.19
Java class ShapeListServant implements interface ShapeList
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
public class ShapeListServant extends UnicastRemoteObject implements ShapeList {
private Vector theList; // contains the list of Shapes
private int version;
public ShapeListServant()throws RemoteException{...}
public Shape newShape(GraphicalObject g) throws RemoteException { 1
version++;
Shape s = new ShapeServant( g, version); 2
theList.addElement(s);
return s;
}
public Vector allShapes()throws RemoteException{...}
public int getVersion() throws RemoteException { ... }
}
Figure 5.20
Java client of ShapeList
import java.rmi.*;
import java.rmi.server.*;
import java.util.Vector;
public class ShapeListClient{
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
ShapeList aShapeList = null;
try{
aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList") ;
1
Vector sList = aShapeList.allShapes(); 2
} catch(RemoteException e) {System.out.println(e.getMessage());
}catch(Exception e) {System.out.println("Client: " + e.getMessage());}
}
}
Figure 5.21
Classes supporting Java RMI
RemoteObject
RemoteServer
Activatable UnicastRemoteObject
<servant class>