Professional Documents
Culture Documents
CC Unit 5
CC Unit 5
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Role of Middleware
• Middleware Roles
provide high-level abstractions such as RMI
enable location transparency
free from specifics of
o communication protocols
o operating systems and communication
hardware
interoperability
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.1
Middleware layers
Applications
Operating System
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Interfaces
• Interface – skeleton of public class
Interaction specification
useful abstraction that removes dependencies on internal
details
examples
o procedure interface
o class interface
o module interface
• Distributed system interfaces
What is the main difference from single processor
situation?
o processes at different nodes
o can only pass accessible information
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Service Interface (RPC)
• Service interface
specifies set of procedures available to client
input and output parameters
Remote Procedure Call
o arguments are marshaled
o marshaled packet sent to server
o server unmarshals packet, performs procedure, and
sends marshaled return packet to client
o client unmarshals the return
o all the details are transparent
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Remote Interface (RMI)
• Remote interface
specifies methods of an object available for remote
invocation
input and output parameters may be objects
Remote Method Invocation
o communication actual arguments marshaled and sent
to server
o server unmarshals packet, performs procedure, and
sends marshaled return packet to caller
o client unmarshals return packet
o common format definition for how to pass objects (e.g.,
CORBA IDL or Java RMI)
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Interface Definition Language
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
CORBA IDL Example
struct Person {
string name; Figure 5.2
CORBA has a string place;
struct long year; remote interface
};
interface PersonList { remote interface
readonly attribute string listname;
defines methods for
void addPerson(in Person p) ;
void getPerson(in string name, out Person RMI
p);
long number();
}; parameters are in, out or inout
• Remote interface:
specifies the methods of an object available for remote invocation
an interface definition language (or IDL) is used to specify remote
interfaces. E.g. the above in CORBA IDL.
Java RMI would have a class for Person, but CORBA has a struct
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
•
© Addison-Wesley Publishers 2000
The Object Model
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
The Object Model
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
The Distributed Objects Model
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Distributed Object Model
Figure 5.3
remote local C
invocation invocation local E
remote
invocation invocation F
B local
A
invocation D
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
•
© Addison-Wesley Publishers 2000
Distributed Object Model
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.4
A remote object and its remote interface
remoteobject
Data
remote
interface
m1 m4
{
implementation m5
m2
of methods m6
m3
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Design Issues for RMI
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics Properties
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics Properties
• At-least-once invocation semantics:
The invoker either receives a result (in which case the
user knows the method was executed at least once) or an
exception.
Types of failures:
o Retransmitting request masks omission failures.
o Crash failures when the server containing the remote
object fails.
o Arbitrary failure when the remote method is invoked
more than once, wrong values are stored or returned.
An idempotent operation that can be performed
repeatedly with the same effect can be a solution.
Useful if the objects in a server can be designed to have
idempotent operations.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics Properties
• At-most-once invocation semantics:
The invoker either receives a result (and the user knows
the the method was executed exactly at most once) or an
exception.
All fault tolerance methods executed.
Omission failures can be eliminated by retransmitting
request.
Arbitrary failures can be prevented by ensuring that no
method is executed more than once.
• JAVA RMI and CORBA use at-most-once
semantics. CORBA also maybe semantics for
methods that do not return results. SUNRPC
provides at-least-once semantics.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Invocation Semantics
• Local invocations are executed exactly once
• Remote invocations cannot achieve this. Why not? :
The Request-reply protocol can apply fault-tolerance
measure.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Implementation of RMI
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
The Architecture of Remote Method
Invocation
Figure 5.6
client server
remote
object A proxy for B skeleton
object B
Request & dispatcher
for B’s class
Reply
• Responsibilities
translation between local and remote object references
o remote object table
- entry for each remote object held by process
- entry for each local proxy
o arriving remote object reference - creation of remote
object references
creation of remote object references
o need to pass a remote object - look up in remote object
table (create new remote object reference and add
entry if necessary)
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RMI Software
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RMI Server and Client Programs
• Server
classes for dispatchers, skeletons and remote objects
initialization section for creating some remote objects
registration of remote objects with the binder
• Client
classes for proxies of all remote objects
binder to look up remote object references
cannot create remote objects by directly calling
constructors - provide factory methods instead
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RMI Binder and Server Threads
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RMI Distributed Garbage Collection
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Remote Procedure Call Basics
Request
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Remote Procedure Call Basics
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Sun RPC
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.8
Files interface in Sun XDR
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Sun RPC
• The interface compiler rpcgen can be used to
generate the following from interface definition.
client stub procedures
server main procedure, dispatcher and server stub
procedures
XDR marshalling and unmarshalling procedures used
by dispatcher and client, server stub procedures.
• Binding:
portmapper records program number, version number,
and port number.
If there are multiple instance running on different
machines, clients make multicast remote procedure calls
by broadcasting them to all the port mappers.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC Interface Compiler
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Sun RPC
• Authentication:
Additional fields are provided in the request-reply
message.
Server program should check the authentication and then
execute.
Different authentication protocols can be supported - none,
UNIX style, shared key, Kerberos style.
A field in RPC header indicates which style is used.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Example (Sun RPC)
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC IDL File (sum.x)
struct sum_in {
long arg1;
};
struct sum_out {
long res1;
};
program SUM_PROG {
version SUM_VERS {
sum_out SUMPROC(sum_in) = 1; /* procedure number = 1*/
} = 1; /* version number = 1 */
} = 0x32123000; /* program number */
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Example (Sun RPC)
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC Client Code (rsum.c)
#include ''sum.h''
main(int argc, char* argv[]) {
CLIENT* cl; sum_in in; sum_out *outp;
// create RPC client handle; need to know server's address
cl = clnt_create(argv[1], SUM_PROG, SUM_VERS, ''tcp'');
in.arg1 = atol(argv[2]); // number to be squared
// Call RPC; note convention of RPC function naming
if ( (outp = sumproc_1(&in, cl)) == NULL)
err_quit(''%s'', clnt_sperror(cl, argv[1]);
printf(''result: %ld\n'', outp->res1);
}
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC Server Code (sum_serv.c)
#include "sum.h"
sum_out* sumproc_1_svc (sum_in *inp, struct svc_req *rqstp)
{ // server function has different name than client call
static sum_out out; // why is this static?
int i;
out.res1 = inp->arg1;
for (i = inp->arg1 - 1; i > 0; i--)
out.res1 += i;
return(&out);
}
// server's main() is generated by rpcgen
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Compilation Linking
rpcgen sum.x
cc -c rsum.c -o rsum.o
cc -c sum_clnt.c -o sum_clnt.o
cc -c sum_xdr.c -o sum_xdr.o
cc -o client rsum.o sum_clnt.o sum_xdr.o
cc -c sum_serv.c -o sum_serv.o
cc -c sum_svc.c -o sum_svc.o
cc -o server sum_serv.o sum_svc.o sum_xdr.o
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Internal Details of Sun RPC
• Initialization
Server runs: register RPC with port mapper on server host
(rpcinfo –p)
Client runs: clnt_create contacts server's port mapper
and establishes TCP connection with server (or UDP
socket)
• Client
Client calls local procedure (client stub: sumproc_1), that
is generated by rpcgen. Client stub packages arguments,
puts them in standard format (XDR), and prepares network
messages (marshaling).
Network messages are sent to remote system by client
stub.
Network transfer is accomplished with TCP or UDP.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Internal Details of Sun RPC
• Server
Server stub (generated by rpcgen) unmarshals arguments
from network messages. Server stub executes local
procedure (sumproc_1_svc) passing arguments received
from network messages.
When server procedure is finished, it returns to server stub
with return values.
Server stub converts return values (XDR), marshals them
into network messages, and sends them back to client
• Back to Client
Client stub reads network messages from kernel
Client stub returns results to client function
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Details of RPC
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC Issues
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RPC Issues
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
• In publish-subscribe paradigm
An object that has event publishes.
Those that have interest subscribe.
• Objects that represent events are called
notifications.
• Distributed event-based systems have two main
characteristics:
Heterogeneous – Event-based systems can be used to
connect heterogeneous components in the Internet.
Asynchronous – Notification are sent asynchronously by
event-generating objects to those subscribers.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.9
Dealing room system
Notification Information
provider Notification
Notification
Notification
Notification
Dealer’s computer Dealer’s computer
Notification
Information
provider
Notification
Dealer Notification
Dealer
External
source
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.10
Architecture for distributed event notification
Event service
object of interest subscriber
1. notification
2. notification notification
3. notification
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Events and Notifications
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Jini Distributed Event Specification
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Jini Distributed Event Specification
• Main objects:
Event generators - It is an object that allows other
objects to subscribe to its events and generates
notifications.
Remote event listeners - A remote event listener is an
object that can receive notifications.
Remote events - A remote event is an object that is
passed by value to remote event listeners. It is equivalent
to a notification.
Third party agents - Third party agents may be
interposed between an object of interest and a subscriber.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Interfaces and Classes
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
HelloInterface.java
import java.rmi.*;
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Hello.java
import java.rmi.*;
import java.rmi.server.*;
public class Hello extends
UnicastRemoteObject implements HelloInterface {
private String message;
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Hello.java (continued)
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
HelloClient.java
import java.rmi.*;
HelloInterface hello =
(HelloInterface) Naming.lookup(path);
for (int i = 0; i < args.length; ++i)
System.out.println(hello.say(args[i]));
} catch(Exception e) {
System.out.println("HelloClient exception: " + e);
}
}
}
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
HelloServer.java
import java.rmi.*;
import java.rmi.server.*;
catch (Exception e) {
System.out.println("Hello server failed:" + e.getMessage());
}
}
}
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI Remote Object References
• An object must have the remote object reference of
other object in order to do remote invocation of that
object.
• Parameter and result passing
Remote object references may be passed as input
arguments or returned as output arguments.
Parameters of a method in Java are input parameters.
Returned result of a method in Java is the single output
parameter.
Objects are serialized to be passed as parameters.
When a remote object reference is returned, it can be
used to invoke remote methods.
Local serializable objects are copied by value.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI Remote Object References
• Downloading of classes
Java is designed to allow classes to be downloaded from
one virtual machine to another.
If the recipient of a remote object reference does not
posses the proxy class, its code is downloaded
automatically.
• RMIregistry
The RMIregistry is designed to allow is the binder for Java
RMI.
It maintains a table mapping textual, URL-style names to
references to remote objects.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI Remote Object References
• Server Program
The server consists of a main method and a servant class
to implement each of its remote interface.
The main method of a server needs to create a security
manager to enable Java security to apply the protection for
an RMI server.
• Client Program
Any client program needs to get started by using a binder
to look up a remote reference.
A client can set a security manager and then looks up a
remote object reference.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Java RMI Callbacks
• Advantages of callback
more efficient than polling
more timely than polling
provides a way for the server to inquire about client status
• Disadvantages of callback
may leave server in inconsistent state if client crashes or
exits without notifying server
requires server to make series of synchronous RMI's
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Shared Whiteboard Example
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.13
Java class ShapeListServer with main method
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());}
}
}
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.14
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 { ... }
} Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.15
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());}
}
}
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
Figure 5.16
Classes supporting Java RMI
RemoteObject
RemoteServer
Activatable UnicastRemoteObject
<servant class>
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
© Addison-Wesley Publishers 2000
RMI Summary
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3
•
© Addison-Wesley Publishers 2000