Distributed Objects & Remote Invocation
Distributed Objects & Remote Invocation
REMOTE INVOCATION
Introduction
This chapter is concerned with programming models for
distributed applications . . .
Familiar programming models have been extended to apply
to distributed programs:
- Remote procedure call (RPC)
- Remote method invocation (RMI)
- Event-based programming model
Introduction
Middleware
The middleware layer uses protocols based on messages
between processes to provide its higher-level abstractions. .
- Location transparency
- Communication protocols
- Computer hardware
- Operating systems
- Use of several programming languages.
Middleware layers
Applications
RMI, RPC and events
Request reply protocol
External data representation
Operating System
Middleware
layers
Interfaces
Communication between modules can be by procedure calls
or by direct access to the variables . . .
Interface - to control the possible interactions between
modules.
Interfaces in distributed systems - In a distributed program, the
modules can run in separate processes. . .
Interfaces
Parameter passing mechanisms . . .
Types of parameters in the specification of a method:
- Input parameters
- Output parameters
- parameter used for both input and output
Pointers cannot be passed . . .
Interfaces
Client-server model: Service interface
- refers to the specification of the procedures offered by a
server.
Distributed object model: Remote interface
- specifies the methods of an object that are available for
invocation by objects in other processes.
- methods can pass objects as arguments and results . . .
- references to remote objects may also be passed.
Interfaces
Interface definition languages (IDLs):
An RMI mechanism can be integrated with a particular with
a particular programming language if it includes a notation
for defining interfaces, . . .
Interfaces
Interface definition languages (IDLs):
- designed to allow objects implemented in different
languages to invoke one another.
- provides a notation for defining interfaces
- each of the parameters of a method may be described as
for input or output in addition to having its type specified.
Distributed objects
- The state of an object consists of the values of its instance
variables. In the object-based paradigm the state of a
program is partitioned into separate parts, each of which is
associated with an object.
- Distributed object systems may adopt the client-server
architecture. Objects are managed by servers . . .
- Distributed objects can assume other architectural models.
- Having client and server objects in different processes
enforces encapsulation. The state of an object can be
accessed only by the methods of the object . . .
local
remote
invocation
A
C
local E
invocation
invocation
local
invocation
D
remote
invocation
remoteobject
remote
interface
Data
m1
m2
m3
implementation
of methods
m4
m5
m6
L
C
remote
invocation
instantiateinstantiate
M
remote
invocation
Invocation semantics
Duplicate
filtering
Invocation
semantics
Re-execute procedure
or retransmit reply
No
Not applicable
Not applicable
Maybe
Yes
No
Re-execute procedure
At-least-once
Yes
Yes
Retransmit reply
At-most-once
Implementation of RMI
Several separate objects and modules are involved.
Illustration: an application-level object A invokes a method in a
remote application-level object B for which it holds a remote
object reference.
server
client
object Aproxy for B
Request
skeleton
& dispatcher
for Bs class
remote
object B
Reply
Remote Communication
reference module module
servant
CommunicationRemote reference
module
module
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Implementation of RMI
Communication module: The two cooperating communication
modules carry out the request-reply protocol.
- This module uses only the first three items of the requestreply message - message type, requestId and object
reference
- These modules are together responsible for providing a
specified invocation semantics.
- The communication module in the server selects the
dispatcher for the class of the object to be invoked, passing
on its local reference, . . .
Implementation of RMI
Remote reference module:
- is responsible for translating between local and remote
object references and for creating remote object references.
- the remote reference module in each process has a
remote object table that records the correspondence
between local object references in that process and remote
object references.
Implementation of RMI
The remote object table includes:
- An entry for all the remote objects held by the process.
Ex: the remote object B will be recorded in the table at the
server.
- An entry for each local proxy.
Ex: the proxy for B will be recorded in the table at the client.
Implementation of RMI
Actions of the remote reference module:
o When a remote object is to be passed as argument or result
for the first time, the remote reference module is asked to
create a remote object reference, which it adds to its table.
o When a remote object reference arrives in a request or
reply message, the remote reference module is asked for
the corresponding local object reference.
Implementation of RMI
Servants:
- It is an instance of a class which provides the body of a
remote object.
- eventually handles the remote requests passed on by the
corresponding skeleton.
Implementation of RMI
The RMI software:
- A layer of software between the application-level objects
and the communication and remote reference modules.
- Roles of the middleware objects:
Proxy
Dispatcher
Skeleton
Implementation of RMI
Proxy:
- makes remote method invocation transparent to clients by
behaving like a local object to the invoker.
- hides the details of the remote object reference, the
marshalling of arguments, etc.
- There is one proxy for each remote object for which a
process holds a remote object reference.
Implementation of RMI
Dispatcher:
- A server has one dispatcher and skeleton for each class
representing a remote object.
- It receives the request message from the communication
module, uses the methodld to select the appropriate method
in the skeleton & passes on the request message.
Implementation of RMI
Skeleton:
- The class of a remote object has a skeleton, which
implements the methods in the remote interface.
- A skeleton method unmarshals the arguments in the
request message and invokes the corresponding method in
the servant.
- It waits for the invocation to complete and then marshals
the result, together with any exceptions, in a reply message
to the sending proxy's method.
Implementation of RMI
The binder:
- a separate service that maintains a table containing
mappings from textual names to remote object references.
- used by servers to register their remote objects by name &
by clients to look them up.
Server threads:
- to avoid the execution of one remote invocation delaying
the execution of another, servers generally allocate a
separate thread for the execution or each remote
invocation.
Implementation of RMI
Activation of remote objects:
- Some applications require that information survive for long
periods of time. . .
- Servers that manage remote objects can be started
whenever they are needed by clients.
- Processes that start server processes to host remote
objects are called activators.
Implementation of RMI
A remote object is described as active when it is available
for invocation within a running process, whereas it is called
passive if is not currently active but can be made active.
A passive object consists of two pans:
the implementation of its methods; and
its state in the marshalled form.
Implementation of RMI
Activation
- create an active object from the corresponding passive
object
- by creating a new instance of its class and initializing its
instance variables from the stored state.
An activator is responsible for:
Registering passive objects that are available for activation
Starting named server processes and activating remote
objects in them
Keeping track of the locations of the servers for remote
objects that it has already activated
Implementation of RMI
Persistent object stores
- Persistent object: An object that is guaranteed to live
between activations of processes.
- a persistent object store will manage very large numbers
of persistent objects.
- Activation is normally transparent
- Persistent objects that are no longer needed in main
memory can be passivated.
Implementation of RMI
Object location
- In the simple case, a remote object reference can act as
an address. . .
- A location service helps clients to locate remote objects
from their remote object references.
It uses a database that maps remote object references to
their current locations
Implementation of RMI
Distributed garbage collection
- the aim is to ensure that if a local or remote reference to
an object is still held anywhere, then the object will continue
to exist.
Implementation of RMI
Java distributed garbage collection algorithm
- based on reference counting.
- whenever a remote object reference enters a process, a
proxy will be created.
- the server should be informed of the new proxy at the
client.
- later when there is no longer a proxy at the client, the
server should be informed.
Implementation of RMI
Each server process maintains a set of the names of the
processes that hold remote object references for each of its
remote objects;
Ex: B.holders is the set of client processes that have
proxies for object B.
When a client C first receives a remote reference to a
particular remote object, B, it makes an addRef(B)
invocation to the server of that remote object and then
creates a proxy;
the server adds C to B.holders.
Implementation of RMI
When a client C's garbage collector notices that a proxy for
remote object B is no longer reachable, it makes a
removeRef(B) invocation to the corresponding server and
then deletes the proxy;
the server removes C from B.holders.
When B.holders is empty, the server's local garbage
collector will reclaim the space occupied by B unless there
are any local holders.
Implementation of RMI
This algorithm is intended to be carried out by means of
pairwise request-reply communication with at-most-once
invocation semantics between the remote reference
modules in processes.
The algorithm tolerates communication failures:
- if addRef(B) call returns an exception . . .
- if removeRef(B) fails . . . leases
The algorithm tolerates failure of client processes . . . leases
client process
server process
Request
client stub
procedure
client
program
Communication
module
Reply
server stub
procedure
Communication
dispatcher
module
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
service
procedure
Dealers computer
External
source
Notification
Notification
Notification
Information
provider Notification
Notification
Dealer
Notification
Notification
Dealers computer
Dealers computer
Notification
Information
provider
Notification
Notification
Dealer
Dealer
External
source
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
Event service
subscriber
object of interest
1.
notification
object of interest
2.
object of interest
3.
observer
notification
subscriber
notification
observer
subscriber
notification
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
RMlregistry
Binder for Java RMI.
An instance of RMlregistry must run on every server computer
that hosts remote objects.
Maintains a table mapping textual, URL-style names to
references to remote objects hosted on that computer.
Accessed by methods of the Naming class
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorld.java
import java.rmi.Remote;
import java.rmi.RemoteException;
//Classname: HelloWorld
//Comment: The remote interface.
public interface HelloWorld extends Remote {
String helloWorld() throws RemoteException;
}
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldClient.java
Client program: The client
- starts by using a binder to look up a remote object
reference.
- continues by sending RMls to that remote object or to
others
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldClient.java
import java.rmi.Naming;
import java.rmi.RemoteException;
/*
Classname: HelloWorldClient
Comment: The RMI client.
*/
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldClient.java
public class HelloWorldClient {
static String message = "blank";
static HelloWorld obj = null;
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldClient.java
public static void main(String args[])
{
try {
obj = (HelloWorld)Naming.lookup("//"+ "kvist.cs.umu.se"+
"/HelloWorld");
message = obj.helloWorld();
System.out.println("Message from the RMI-server was: \""
+ message + "\"");
}
catch (Exception e) {
System.out.println("HelloWorldClient exception: "
+ e.getMessage());
e.printStackTrace();
}
}}
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldServer.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldServer.java
public class HelloWorldServer extends nicastRemoteObject
implements HelloWorld {
public HelloWorldServer() throws RemoteException {
super();
}
public String helloWorld() {
System.out.println("Invocation to helloWorld was
succesful!");
return "Hello World from RMI server!";
}
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005
HelloWorldServer.java
public static void main(String args[]) {
try {
// Create an object of the HelloWorldServer class.
HelloWorldServer obj = new HelloWorldServer();
// Bind this object instance to the name "HelloServer".
Naming.rebind("HelloWorld", obj);
System.out.println("HelloWorld bound in registry");
}
catch (Exception e) {
System.out.println("HelloWorldServer error: " +
e.getMessage());
e.printStackTrace();
}
}
}
Instructors Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4
Pearson Education 2005