Modul-05: Invokasi Jarak Jauh: Rekayasa Aplikasi Terdistribusi
Modul-05: Invokasi Jarak Jauh: Rekayasa Aplikasi Terdistribusi
! Layers of Middleware
! Provide a programming model
! Provide transparence
! Location
! Communication protocols
! Computer hardware
! Operating systems
! Programming languages
Interfaces
! Interface
! Specifies accessible procedures and variables
! Inner alteration won’t affect the user of the interface
! Event-based model
! Register interested events of other objects
! Receive notification of the events at other objects
Interface cases
Figure 5.3
remote local C
E
invocation invocation local
invocation remote
invocation F
A B local
invocation D
client server
remote
object A proxy for B skeleton
object B
Request & dispatcher
for B’s class
Reply
Reply
client stub server stub
procedure procedure
client service
program Communication Communication procedure
module module dispatcher
Sun RPC case study
! Designed for NFS
! at-least-once semantics
! XDR - Interface definition language
! Interface name: Program number, version number
! Procedure identifier: procedure number
! Rpcgen – generator of RPC components
! client stub procedure
! server main procedure
! Dispatcher
! server stub procedure
! marshalling and unmarshalling procedure
Sun RPC case study …continued
! Binding – portmapper
! Server: register ((program number, version number),
port number)
! Client: request port number by (program number,
version number)
! Authentication
! Each request contains the credentials of the user, e.g.
uid and gid of the user
! Access control according to the credential information
Events and
notifications
! Idea
! one object react to a change occurring in another object
! Event examples
! modification of a document
! an electronically tagged book being at a new location
! Publish/subscribe paradigm
! event generator publish the type of events
! event receiver subscribe to the types of events that are interest to them
! When event occur, notify the receiver
! Distributed event-based system – two characteristics
! Heterogeneous: components in a DS that were not designed to
interoperate can be made to work together
! Asynchronous: prevent publishers needing to synchronize with
subscribers
Example - dealing room system
• Requirements
– allow dealers to see the latest market price of the
tocks they deal in.
• System components
– Information provider
• receive new trading information
• publish stocks prices event
• stock price update notification
– Dealer process
• subscribe stocks prices event
• System architecture
Architecture for distributed event notification
Event service
object of interest subscriber
1. notification
2. notification notification
3. notification
The roles of the participating objects
! Delivery semantics
! Unreliable, e.g. deliver the latest state of a player in a
Internet game
! Reliable, e.g. dealing room
! real-time, e.g. a nuclear power station or a hospital
patient monitor
! Roles for observers
! Forwarding
# send notifications to subscribers on behalf of one or more
objects of interests
! Filtering of notifications according to some predicate
! Patterns of events
! Notification mailboxes
# notification be delayed until subscriber being ready to receive
Jini distributed event specification
! Remote Interface
! Server program and Client program
! Callbacks
! A server’s action of notifying clients about an event
! Implementation
# Client create a remote object
# Client pass the remote object reference to server
# Whenever an event occurs, server call client via the remote
object
! Advantage
# Improve performance by avoid constant polling
# Delivery information in a timely manner
Design and implementation of Java RMI
RemoteServer
Activatable UnicastRemoteObject
<servant class>
Java RMI
! Introduction
! Communication between distributed
objects
! Remote procedure call
! Events and notifications
! Java RMI case study
! Summary
Summary
Applications
Middleware
Request reply protocol layers
Operating System
A remote object and its remote interface
remoteobject
Data
remote
interface
m1 m4
{ m2
m3
implementation
of methods
m5
m6
Remote and local method invocations
local C
remote
E
invocation invocation local
remote
invocation
invocation F
B
A local
invocation D
Files interface in Sun XDR
Notification Information
provider Notification
Notification
Notification
Notification
Dealer’s computer Dealer’s computer
Notification
Information
provider
Notification
Dealer Notification
Dealer
External
source
The Naming class of Java RMIregistry
import java.rmi.*;
import java.util.Vector;
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 { ... }
}
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());}
}
}
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());}
}
}
Callback mechanism in the whiteboard system