Lec 7 A
Lec 7 A
RPC/RMI
Motivation
1
Middleware layers
Applications, services
2
Remote Procedure Call
❒ Principle of RPC between a client and server program.
3
Steps of a Remote Procedure Call
2-8
4
Passing Value Parameters (2)
a) A procedure
b) The corresponding message.
5
Request-reply communication
Client Server
Request
doOperation
message getRequest
select procedure
(wait) Execute procedure
Reply
message sendReply
(continuation)
6
Files interface in Sun XDR
2-15
7
RMI
8
Remote and local method invocations
remote local C
E
invocation invocation local
remote
invocation invocation F
B local
A
invocation D
remoteobject
Data
remote
interface
m1 m4
{
implementation m5
m2
of methods m6
m3
9
The role of proxy and skeleton in remote
method invocation
client server
remote
object A proxy for B skeleton
object B
Request & dispatcher
for B’s class
Reply
Client Server
Request
doOperation
message getRequest
select object
(wait) execute
Reply method
message sendReply
(continuation)
10
Operations of the request-reply protocol
11
Request-Reply protocol
index in notes
sequence of bytes 4 bytes on representation
The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1934}
12
Java serialization
The true serialized form contains additional type markers; h0 and h1 are handles
RMI Programming
❒ RMI software
❍ Generated by IDL compiler
❍ Proxy
• Behaves like remote object to clients (invoker)
• Marshals arguments, forwards message to remote object,
unmarshals results, returns results to client
❍ Skeleton
• Server side stub;
• Unmarshals arguments, invokes method, marshals results
and sends to sending proxy’s method
❍ Dispatcher
• Receives the request message from communication module,
passes on the message to the appropriate method in the
skeleton
❒ Server and Client programs
13
RMI Programming
❒ Binder
❍ Client programs need a means of obtaining a remote
object reference
❍ Binder is a service that maintains a mapping from textual
names to remote object references
❍ Servers need to register the services they are exporting
with the binder
❍ Java RMIregistry, CORBA Naming service
❒ Server threads
❍ Several choices: thread per object, thread per invocation
❍ Remote method invocations must allow for concurrent
execution
RPC/RMI systems
❒ RPC systems
❍ SUN RPC
❍ DCE RPC
❒ RMI systems
❍ CORBA
❍ DCOM
❍ Java RMI
❍ SOAP (Simple Object Access Protocol)
• HTTP is request-reply protocol
• XML for data representation
14
Java RMI
❒ Features
❍ Integrated with Java language + libraries
• Security, write once run anywhere, multithreaded
• Object orientation
❍ Can pass “behavior”
• Mobile code
• Not possible in CORBA, traditional RPC systems
❍ Distributed Garbage Collection
❍ Remoteness of objects intentionally not
transparent
15
Creating distributed applications using RMI
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;
}
16
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());}
}
}
17
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 1
private int version;
public ShapeListServant()throws RemoteException{...}
public Shape newShape(GraphicalObject g) throws RemoteException { 2
version++;
Shape s = new ShapeServant( g, version); 3
theList.addElement(s);
return s;
}
public Vector allShapes()throws RemoteException{...}
public int getVersion() throws RemoteException { ... }
}
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());}
}
}
18