Learning Unit 3 Distributed Objects
Learning Unit 3 Distributed Objects
Learning Unit 3
Distributed Objects
• Introduction
• Communication between distributed
objects
• Events and notifications
2
(Recap) Middleware
• Layers of Middleware
• Provide a programming model
• Provide transparency
• Location
• Communication protocols
• Computer hardware
• Operating systems
• Programming languages
3
(Recap) Middleware layers
Applications
Middleware
Request reply protocol layers
Operating System
4
(Recap) Distributed programming model
• Remote procedure call (RPC)
• Birrel and Nelson (1984)
• call procedure in separate process
• Remote method invocation (RMI)
• extension of local method invocation in OO model
• invoke the methods of an object of another process
• Event-based model
• Register interested events of other objects
• Receive notification of the events at other objects
5
(Recap) Interfaces
• Interface
• Specifies accessible procedures and variables
• Inner alteration won’t affect the user of the interface
• Interface in distributed system
• Can’t access variables directly
• Input argument and output argument
• Pointers can’t be passed as arguments or returned results
6
(Recap) Interface cases
7
Communication between
distributed objects
Discuss RMI under following headings
• The object model
• Distributed objects
• The distributed object model
• Design issues
• semantics of remote invocations
• Implementation
• RMI above the request-reply protocol
• Distributed garbage collections
9
The object model
• Object references
• Objects can be accessed via object references
• First-class values
• Interfaces
• A definition of the signatures of a set of methods
• No constructers
• A class can implement several interfaces, e.g. Java
• Actions
• Initiated by an object invoking a method in another object
• Two affects
• Change the state of the receiver
• Further invocations on methods in other objects
10
The object model
• Exceptions mechanism
• A clean way to deal with error conditions
• List exceptions at the method head
• throw user know exceptions
• Catch exceptions
• Garbage collection
• Freeing the space occupied by cancelled objects
• C++: collected by programmers
• Java: collected by JVM
11
Distributed objects
• Natural extension
• physical distribution of objects into different processes or
computers in a distributed system
• Benefits of distributed objects
• Enforce encapsulation
• can’t access variables directly
• Support heterogeneous systems
• Assume other architectural models then client/server
• Replicated objects
• Migrated objects
12
Remote and local method invocations
local C
remote
E
invocation invocation local
remote
invocation
invocation F
B
A local
invocation D
13
The distributed objects model
remoteobject
Data
remote
interface
m1 m4
implementation
{ m2
m3 of methods
m5
m6
15
Design Issues – Invocation semantics
• Maybe
• For invoker: executed once, or not at all ???
• Suffer from: (1) message lost; (2) server crash
• Useful for app. in which occasional failed invocation are acceptable
• At least once
• For invoker: execute at least once, or an exception
• Suffer from: (1) server crash; (2) arbitrary failures for non-
idempotent method
• At most once
• For invoker: receives result, or an exception
• Prevent: omission failures by retrying, arbitrary failures
17
Design Issues - Transparency
18
Implementation of RMI
19
Request-reply message structure (fig 4.13)
20
The role of proxy and skeleton in remote method invocation
client server
remote
skeleton
object A proxy for B object B
Request & dispatcher
for B’s class
Reply
21
Implementation of RMI – RMI software
• Proxy
• forward invocation to remote object
• one remote object one proxy
• implement the method in the remote interface
• It marshals a reference to the target object , its own methodId and its arguments
into request message and send it to the target, awaits the reply and message,
unmarshals it and returns the results to invoker
• Skeleton
• implement the method in the remote interface
• unmarshal the arguments in the request
• invoke the corresponding method in the remote object
• wait for the invocation complete
• marshal the result in the reply message
• Dispatcher
• Receive the request from communication module and select
appropriate method in the skeleton
• one dispatcher and skeleton for one remote object
22
Implementation of RMI - execution
23
Implementation of RMI - Object state
• The binder
• A service that maintains mapping information of textual names to
remote object references
• Activation of remote objects
• to avoid resource waste, the servers can be started whenever they
are needed- FTP service
• Activators: process that start server processes to host remote
objects.
• a remote object could be active or passive
• Passive object: consist of two parts
• Implementation of its methods
• Its state in marshaled form
• Activation: Making a new object from corresponding passive object
by creating a new instance of its class and initializing its variables
from the stored state
• Java RMI uses one activator on each server computer , which is
responsible for activating objects on that computer.
24
Implementation of RMI - Object state (cont..)
25
Distributed garbage collection
26
Distributed garbage collection (cont..)
• Leases in Jini
• lease: the granting of the use of a resource for a period of time
• avoid to discover whether the resource users are still interested or their
programs have not exited
27
Event and Notification
Event-notification model
• Idea
• one object react to a change occurring in another object
• Event examples
• modification of a document
• A new doc added in an electronically tagged book
• 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
• asynchronous
29
Example - dealing room system
• Requirements
– allow dealers to see the latest market price information
• System components
– Information provider
• receive new trading information
• publish stocks prices event
• stock price update notification
– Dealer process
• subscribe stocks prices event
• System architecture
30
Dealing room system
Notification Information
provider Notification
Notification
Notification
Notification
Dealer’s computer Dealer’s computer
Notification
Information
provider
Notification
Notification
Dealer
Dealer
External
source 31
Architecture for distributed event notification
Event service
object of interest subscriber
1. notification
2. notification notification
3. notification
32
The roles of the participating objects
33
Notification delivery
• Delivery semantics
• Unreliable
• Reliable
• real-time
• Roles for observers
• Forwarding
• send notifications to subscribers on behalf of one or more
objects of interests
• Filtering of notifications
• Patterns of events
• Notification mailboxes
• notification be delayed until subscriber being ready to receive
34
Jini distributed event specification
• EventGenerator interface
• Provide register method
• Event generator implement it
• Subscriber invoke it to subscribe to the interested events
• RemoteEventListener interface
• Provide notify method
• subscriber implement it
• receive notifications when the notify method is invoked
• RemoteEvent
• a notification that is passed as argument to the notify method
• Third-party agents
• interpose between an object of interest and a subscriber
• equivalent of observer
35
Unsupervised Lab
• Please refer to eLeap for lab material on RMI
• This is unsupervised lab (you are on your 3rd / 4th year anyway),
please do it on your own time
Any question?