Module4 Distributed Computing
Module4 Distributed Computing
04/17/2023 1
Message Passing vs. Distributed
Objects
04/17/2023 2
Message Passing versus Distributed Objects
04/17/2023 3
Message Passing versus Distributed Objects –2
Message passing requires the participating processes to be
tightly-coupled: throughout their interaction, the processes
must be in direct communication with each other. If
communication is lost between the processes (due to failures
in the communication link, in the systems, or in one of the
processes), the collaboration fails.
The message-passing paradigm is data-oriented. Each
message contains data marshalled in a mutually agreed upon
format, and is interpreted as a request or response according
to the protocol. (e.g., 1000-character message)
The receiving of each message triggers an action in the
receiving process. It is inadequate for complex applications
involving a large mix of requests and responses. In such an
application, the task of interpreting the messages can become
overwhelming.
04/17/2023 4
The distributed object paradigm
04/17/2023 5
object-oriented programming
To illustrate, consider objects of the DatagramMessage class. Each
object instantiated from this class contains three state data items--a
message, the sender’s address, and the sender’s port number. In
addition, each object contains four operations:
a method putVal, which allows the values of these data items
to be modified,
a getMessage method, which allows the current value of the
be retrieved.
a getPort method, which allows the sender’s port to be
retrieved.
04/17/2023 6
object-oriented programming
public class DatagramMessage{
private String message;
private InetAddress senderAddress;
private int senderPort;
04/17/2023 8
The Distributed Object Paradigm
In a distributed object paradigm, network resources are
represented by distributed objects. To request services from a
network resource, a process invokes one of its operations or
methods, passing data as arguments to the method. The method
is executed on the remote host, and the response, if any, is
sent back to the requesting process as a returned value.
Host A Host B
c lie n t pr o ce s s
m e t h o d ca ll
o bje c t s t a t e da t a i t e m
o b je c t o p e r a t i o n
04/17/2023 a di s t r i bu t e d o b je c t 9
Message Passing versus Distributed Objects
04/17/2023 10
The Distributed Object Paradigm - 2
A process running in host A makes a method call
to a distributed object residing on host B, passing
with the data as arguments, if any.
The method call invokes an action performed by
the method on host B, and a returned value, if any,
is passed from host B to host A.
A process which makes use of a distributed
object is said to be a client process of that
object, and the methods of the remote object are
called remote methods (as opposed to local
methods, or methods belonging to a local object)
to the client process.
04/17/2023 11
The Distributed Objects
Paradigm
04/17/2023 12
An Archetypal Distributed Objects System
o b je c t
r e g is t r y
o b je c t c l i e n t o b je c t s e r v e r
clie n t s e rv e r
pro x y pr o x y
ru n t im e ru n t im e
s u ppo r t s u ppo rt
n e two rk n e two rk
s u ppo r t s u ppo r t
ph y s ic a l da t a pa t h
lo g ic a l da t a pa t h
04/17/2023 14
Distributed Object System - 2
Logically, the object client makes a call directly to a
remote method.
In reality, the call is handled by a software
component, called a client proxy/stub, which
interacts the software on the client host that
provides the runtime support for the distributed
object system.
The runtime support is responsible for the
interprocess communication needed to transmit the
call to the remote host, including the marshalling of
the argument data that needs to be transmitted to
the remote object.
04/17/2023 15
Distributed Object System - 3
A similar architecture is required on the server side,
where the runtime support for the distributed object
system handles the receiving of messages and the
unmarshalling of data, and forwards the call to a
software component called the server proxy/skeleton.
The server proxy interfaces with the distributed
object to invoke the method call locally (on the
remote host), passing in the unmarshalled data for the
arguments.
The method call results in the performance of some
tasks on the server host.
The outcome of the execution of the method, including
the marshalled data for the returned value, is
forwarded by the server proxy to the client proxy, via
the runtime support and network support on both
sides.
04/17/2023 16
Distributed Object Systems/Protocols
The distributed object paradigm has been widely adopted in
distributed applications, for which a large number of
mechanisms based on the paradigm are available. Among the
most well known of such mechanisms are:
Java Remote Method Invocation (RMI),
04/17/2023 17
From Remote Procedure Call
to Remote Method Invocation
04/17/2023 18
Remote Procedure Calls (RPC)
Remote Method Invocation (RMI) has its origin in a paradigm
called Remote Procedure Call (RPC)
In the RPC model, a procedure call is made by one process to
another, with data passed as arguments.
Upon receiving a call, the actions encoded in the procedure are
executed, the caller is notified of the completion of the call, and a
returned value, if any, is transmitted from the callee to the caller.
Pro ce s s A
Pro ce s s B
pro c1 (a rg 1 , a rg 2 )
retu rn v a l u e
a re m o te pro ce du re
04/17/2023 e x e cu ti o n fl o w
19
Local Procedure Call and Remote Procedure Call
h ost A
pro c1
e x e cu ti o n fl o w
pro c2
A l o ca l pro ce du re ca l l
h ost B
host A
1 . pro c1 o n h o s t A m a k e s a ca l l 4 . Th e p r o x y o n h o s t B
to pro c 2 o n h o s t B . pro c1 u n m a rs h a l l s th e da ta
pro c2
2 . Th e r u n t i m e s u p p o r t m a p s r e c e i ve d a n d i s s u e s a
th e ca l l to a ca l l to th e pro x y ca l l to pro c2 .
on h ost A. 5 . Th e c o d e i n p r o c 2 i s
3 . Th e p r o x y m a r s h a l l s t h e d a t a e x e cu te d a n d re tu rn s
a n d m a k e s a n IP C c a l l t o a to th e pro x y o n h o s t B .
pro x y o n h o s t B . 6 . Th e p r o x y m a r s h a l l s
t h e r e t u r n va l u e a n d
7 . Th e p r o x y r e c e i ve d t h e r e t u r n m a k e s a n IP C c a l l t o
va l u e , u n m a r s h a l l s t h e d a t a , pro x y th e pro x y o n h o s t A .
pro x y
a n d f o r w a r d s t h e r e t u r n va l u e
to pro c1 , w h i ch re s u m e s i ts
e x e cu ti o n fl o w .
A re m o te pro ce du re ca l l
(th e re tu rn e x e cu ti o n pa th i s n o t s h o w n )
04/17/2023 20
Remote Procedure Calls (RPC) - 2
Since its introduction in the early 1980s, the Remote Procedure
Call model has been widely in use in network applications.
There are two prevalent APIs for this paradigm.
the Open Network Computing (ONC) Remote Procedure Call, evolved
from the RPC API originated from Sun Microsystems in the early 1980s.
04/17/2023 21
Java Remote Method Invocation
04/17/2023 22
Remote Method Invocation
Remote Method Invocation (RMI) is an object-oriented
implementation of the Remote Procedure Call (RPC) model.
It is an API for Java programs only.
Using RMI, an object server exports a remote object and
registers it with a directory service (e.g., RMI registry). The
object provides remote methods, which can be invoked in
client programs.
Syntactically:
A remote object is declared with a remote interface, a Java interface.
The remote interface is implemented by the object server.
An object client accesses the object by invoking the remote methods
associated with the objects using syntax provided for remote method
invocations.
04/17/2023 23
The Java RMI Architecture
D ire ctory se rvice
obje ct obje ct
clie n t se rve r
supports the interfac e w ith
the applic ation program
[1] One such service is the Java Naming and Directory Interface (JNDI), which is more
general than the RMI registry, in the sense that it can be used by applications that do not
use the RMI API.
[2] The Java SDK is what you download to your machine to obtain the use of the Java class
libraries and tools such as the java compiler javac .
04/17/2023 25
The interaction between the stub and the skeleton
s tu b s k e le t o n R e m ote
Me th od
t im e
m a rs h a l pa ra m e t e rs ;
s e n d R e qu e s t
u n m a rs h a l pa ra m e t e r s
In vok e m e th od
e x e cu t e co de
a n d re t u rn a
v a lu e
re ce iv e re t u rn v a lu e
m a rs h a l re ply
s e n d re ply
u n m a rs h a ll re ply ;
re t u rn v a lu e
( ba s e d o n h t t p: //ja v a . s u n .c o m .m a rk e t in g /co lla t e ra l/ja v a rim . h t m l)
04/17/2023 26
The API for the Java RMI
The Remote Interface
The Server-side Software
The Remote Interface Implementation
Stub and Skeleton Generations
The Object Server
The Client-side Software
04/17/2023 27
Stub and Skeleton
RMI uses stub and skeleton object for
communication with the remote object.
A remote object is an object whose method can
be invoked from another JVM. Let's understand
the stub and skeleton objects:
04/17/2023 28
Stub
The stub is an object, acts as a gateway for the client side. All
the outgoing requests are routed through it. It resides at the
client side and represents the remote object. When the caller
invokes method on the stub object, it does the following tasks:
1. It initiates a connection with remote Virtual Machine (JVM),
2. It writes and transmits (marshals) the parameters to the remote
Virtual Machine (JVM),
3. It waits for the result
4. It reads (unmarshals) the return value or exception, and
5. It finally, returns the value to the caller.
04/17/2023 29
Skeleton
The skeleton is an object, acts as a gateway for the
server side object. All the incoming requests are routed
through it. When the skeleton receives the incoming
request, it does the following tasks:
1. It reads the parameter for the remote method
2. It invokes the method on the actual remote object, and
3. It writes and transmits (marshals) the result to the
caller.
04/17/2023 30
Stub and Skeleton
04/17/2023 31
Requirements of a Distributed application
04/17/2023 32
RMI Steps
Create the remote interface
Provide the implementation of the remote
interface
Compile the implementation class and create
the stub and skeleton objects using the rmic tool
Start the registry service by rmiregistry tool
Create and start the remote application
Create and start the client application
04/17/2023 33
Example
04/17/2023 34
1) create the remote interface
For creating the remote interface, extend the Remote
interface and declare the RemoteException with all the
methods of the remote interface. Here, we are creating
a remote interface that extends the Remote interface.
There is only one method named add() and it declares
RemoteException.
import java.rmi.*;
public interface Adder extends Remote{
public int add(int x,int y)throws RemoteException;
}
04/17/2023 35
Provide the implementation of the remote
interface
04/17/2023 36
Create the stub and skeleton objects using the
rmic tool.
rmic AdderRemote
04/17/2023 37
Start the registry service by the rmiregistry
tool
Now start the registry service by using the
rmiregistry tool. If you don't specify the port
number, it uses a default port number. In this
example, we are using the port number 5000.
rmiregistry 5000
04/17/2023 38
Create and run the server application – Naming Class
public static java.rmi.Remote lookup(java.lang.String) throws It returns the reference of the remote object.
java.rmi.NotBoundException,
java.net.MalformedURLException, java.rmi.RemoteException;
public static void bind(java.lang.String, java.rmi.Remote) It binds the remote object with the given name.
throws java.rmi.AlreadyBoundException,
java.net.MalformedURLException, java.rmi.RemoteException;
public static void unbind(java.lang.String) throws It destroys the remote object which is bound with the given
java.rmi.RemoteException, java.rmi.NotBoundException, name.
java.net.MalformedURLException;
public static void rebind(java.lang.String, java.rmi.Remote) It binds the remote object to the new name.
throws java.rmi.RemoteException,
java.net.MalformedURLException;
public static java.lang.String[] list(java.lang.String) throws It returns an array of the names of the remote objects bound in
java.rmi.RemoteException, java.net.MalformedURLException; the registry.
04/17/2023 39
Create and run the server application
import java.rmi.*;
import java.rmi.registry.*;
public class MyServer{
public static void main(String args[]){
try{
Adder stub=new AdderRemote();
Naming.rebind("rmi://localhost:5000/sonoo",stub);
}catch(Exception e){System.out.println(e);}
}
}
04/17/2023 40
Create and Run the Client Application
04/17/2023 42
Comparison of the RMI and the socket APIs
04/17/2023 43
Comparison of the RMI and the socket APIs
04/17/2023 45
RMI Security Manager
The RMISecurityManager enforces the security policy for classes that are
loaded as stubs for remote objects, by overriding all of the relevant access-
check methods from the SecurityManager.
By default, stub objects are only allowed to perform class definition and
class access operations.
java.lang.Object
java.lang.SecurityManager
java.rmi.RMISecurityManager
Syntax:
04/17/2023 46
How to incorporate the Security Manager
class?
To use a SecurityManager in your application, add the following
statement to your code
Syntax:
System.setSecurityManager(new SecurityManager());
Implementation:
if (System.getSecurityManager() == null)
{
// Setting the RMISecurityManager on System
System.setSecurityManager(new SecurityManager());
}
04/17/2023 47
Java.Policy file
The java. policy file installed with the JDK
grants all permissions to standard extensions,
allows anyone to listen on un-privileged ports,
and allows any code to read certain "standard"
properties that are not security-sensitive, such
as the " os.name " and " file.
04/17/2023 48
Algorithms for Building an RMI application,
Allowing for Stub Downloading
Algorithm for Developing the Server-Side Software
Open a directory for all the files to be generated for this application.
Specify the remote-server interface SomeInterface.java, and compile it to generate
the interface class file.
Build the remote server class SomeImpl.java by implementing the interface, and
compile it using javac.
Use rmic to process the server class to generate a stub.class file and a skelton.class
file: rmic SomeServer
If stub downloading is desired, copy the stub file to an appropriate directory on the
HTTP host.
Activate the RMIRegistry, if it has not already been activated.
Set up a java.policy file.
Activate the server, specifying (i) the codebase if stub downloading is desired, (ii) the
server host name, and (iii) the security policy file.
04/17/2023 49
Object Client-Side Algorithm for Developing the Client-Side
Software
1. Open a directory for all the files to be generated for this application.
2. Obtain a copy of the remote interface class file SomeInterface.class,
Alternatively, obtain a copy of the source file SomeInterface.java for
the remote interface, and compile it using javac to generate the
interface class file.
3. If stub downloading is not in effect, obtain a copy of the stub class file
and place it in the current directory.
4. Set up a java.policy file for application, and place it in an appropriate
directory or the current direct directory.
5. Activate the client, specifying (i) the server host name, and (ii) the
security policy file.
04/17/2023 50
The HelloWorld Sample
04/17/2023 51
Diagrams for the Hello application
H e llo I n t e r f a ce
U n i c a s t R e m o t e O bj e c t
s a y H e llo ( )
lis t R e g is t ry ( )
s t a rt R e g is t ry ( )
U M L di ag r am
c lie n t r e g is t ry s e rv e r
r e bin d( )
lo o k u p( )
s a y H e llo ( )
s e q u e n c e d i ag r am
04/17/2023 52
Source files for the Hello application
HelloInterface.java
HelloImpl.java
HelloClient.java
Demo example:
http://java.sun.com/j2se/1.4.2/docs/guide/rmi/
getstart.doc.html
04/17/2023 53
A Sample Enterprise Application
In the illustrated application, the object server provides remote methods
which allows the object clients to look up or update the data in an Expense
Records database. Programs which are clients of the object provide the
application or business logic for processing the data and the presentation
logic for the user interface which presents the data.
C lien t
C lien t RM I
RMI RM I C lien t
S er v er
J D BC
E x p en s e R ec o r d s