SlideShare une entreprise Scribd logo
1  sur  58
01/30/15 Distributed Computing, M. L. Liu 1
Distributed Objects
M. L. Liu
01/30/15 Distributed Computing, M. L. Liu 2
Message Passing vs. Distributed
Objects
01/30/15 Distributed Computing, M. L. Liu3
Message Passing versus Distributed Objects
 The message-passing paradigm is a
natural model for distributed computing, in
the sense that it mimics interhuman
communications. It is an appropriate
paradigm for network services where
processes interact with each other through
the exchanges of messages.
 However, the abstraction provided by this
paradigm does not meet the needs of the
complexity of sophisticated network
applications.
01/30/15 Distributed Computing, M. L. Liu4
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. 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.
01/30/15 Distributed Computing, M. L. Liu5
The distributed object
paradigm
 The distributed object paradigm is a paradigm
that provides abstractions beyond those of the
message-passing model. As its name implies,
the paradigm is based on objects that exist in a
distributed system.
 In object-oriented programming, supported by an
object-oriented programming language such as
Java, objects are used to represent an entity
significant to an application. Each object
encapsulates:
 the state or data of the entity: in Java, such data is
contained in the instance variables of each object;
 the operations of the entity, through which the state
of the entity can be accessed or updated.
01/30/15 Distributed Computing, M. L. Liu6
object-oriented programming
To illustrate, consider objects of the
DatagramMessage class in Figure 6f (in
Chapter 6). 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 three 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 message to be retrieved, and

a getAddress method, which allows the sender’s
address to be retrieved.
01/30/15 Distributed Computing, M. L. Liu7
Local Objects vs. Distributed Objects
 Local objects are those whose methods can only
be invoked by a local process, a process that
runs on the same computer on which the object
exists.
 A distributed object is one whose methods can
be invoked by a remote process, a process
running on a computer connected via a network
to the computer on which the object exists.
01/30/15 Distributed Computing, M. L. Liu8
The Distributed Object Paradigm
In a distributed object paradigm, network resources are
represented by distributed objects. To request service from a
network resource, a process invokes one of its operations or
methods, passing data as parameters to the method. The
method is executed on the remote host, and the response is sent
back to the requesting process as a return value.
o b je c t s t a t e d a t a i t e m
o b je c t o p e r a t i o n
H o s t A H o s t B
c l i e n t p r o c e s s
m e t h o d c a l l
a d i s t r i b u t e d o b je c t
01/30/15 Distributed Computing, M. L. Liu9
Message Passing versus Distributed Objects - 3
Compared to the message-passing
paradigm, which is data-oriented, the
distributed objects paradigm is action-
oriented: the focus is on the invocation
of the operations, while the data passed
takes on a secondary role. Although less
intuitive to human-beings, the distributed-
object paradigm is more natural to object-
oriented software development.
01/30/15 Distributed Computing, M. L. Liu10
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 call data for the parameters,
if any.
 The method call invokes an action performed
by the method on host A, and a return value,
if any, is passed from host A to host B.
 A process which makes use of a distributed
object is said to be a client process of that
object, and the methods of the object are
called remote methods (as opposed to local
methods, or methods belonging to a local
object) to the client process.
01/30/15 Distributed Computing, M. L. Liu 11
The Distributed Objects
Paradigm
01/30/15 Distributed Computing, M. L. Liu12
An Archetypal Distributed Objects System
o b je c t c l i e n t o b je c t s e r v e r
c l i e n t
p r o x y
s e r v e r
p r o x y
r u n t i m e
s u p p o r t
n e t w o r k
s u p p o r t
n e t w o r k
s u p p o r t
p h y s i c a l d a t a p a t h
l o g i c a l d a t a p a t h
o b je c t
r e g i s t r y
r u n t i m e
s u p p o r t
01/30/15 Distributed Computing, M. L. Liu13
Distributed Object System
 A distributed object is provided, or exported, by
a process, here called the object server. A
facility, here called an object registry, must be
present in the system architecture for the
distributed object to be registered.
 To access a distributed object, a process –an object
client – looks up the object registry for a reference[1]
to
the object. This reference is used by the object client
to make calls to the methods.
[1] A reference is a “handle” for an object; it is a representation
through which an object can be located in the computer where the
object resides.
01/30/15 Distributed Computing, M. L. Liu14
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, which
interacts which 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.
01/30/15 Distributed Computing, M. L. Liu15
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.
 The server proxy interfaces with the distributed object to
invoke the method call locally, 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 return value,
is forwarded by the server proxy to the client proxy, via the
runtime support and network support on both sides.
01/30/15 Distributed Computing, M. L. Liu16
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),
~ the Common Object Request Broker Architecture
(CORBA) systems,
~ the Distributed Component Object Model (DCOM),
~ mechanisms that support the Simple Object Access
Protocol (SOAP).
Of these, the most straightforward is the Java RMI
01/30/15 Distributed Computing, M. L. Liu 17
From Remote Procedure Call
to Remote Method Invocation
01/30/15 Distributed Computing, M. L. Liu18
Remote Procedure Calls (RPC)
 Remote Method Invocation has its origin in a paradigm called
Remote Procedure Call
 In the remote procedure call 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 return value, if any, is transmitted from the callee to the caller.
p r o c 1 ( a r g 1 , a r g 2 )
P r o c e s s A
P r o c e s s B
a r e m o t e p r o c e d u r e
r e t u r n v a l u e
e x e c u t i o n f l o w
01/30/15 Distributed Computing, M. L. Liu19
Local Procedure Call and Remote Procedure Call
p r o c 1
e x e c u t i o n f l o w
p r o c 2
h o s t A
A l o c a l p r o c e d u r e c a l l
h o s t A
h o s t B
A r e m o t e p r o c e d u r e c a l l
( t h e r e t u r n e x e c u t i o n p a t h i s n o t s h o w n )
p r o c 1
p r o c 2
p r o x y
p r o x y
1 . p r o c 1 o n h o s t A m a k e s a c a l l
t o p r o c 2 o n h o s t B .
2 . T h e r u n t i m e s u p p o r t m a p s
t h e c a l l t o a c a l l t o t h e p r o x y
o n h o s t A .
3 . T h e p r o x y m a r s h a l l s t h e d a t a
a n d m a k e s a n I P C c a l l t o a
p r o x y o n h o s t B .
7 . T h e p r o x y r e c e i v e d t h e r e t u r n
v a l u e , u n m a r s h a l l s t h e d a t a ,
a n d f o r w a r d s t h e r e t u r n v a l u e
t o p r o c 1 , w h i c h r e s u m e s i t s
e x e c u t i o n f l o w .
4 . T h e p r o x y o n h o s t B
u n m a r s h a l l s t h e d a t a
r e c e i v e d a n d i s s u e s a
c a l l t o p r o c 2 .
5 . T h e c o d e i n p r o c 2 i s
e x e c u t e d a n d r e t u r n s
t o t h e p r o x y o n h o s t B .
6 . T h e p r o x y m a r s h a l l s
t h e r e t u r n v a l u e a n d
m a k e s a n I P C c a l l t o
t h e p r o x y o n h o s t A .
01/30/15 Distributed Computing, M. L. Liu20
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 Remote Procedure Call,
evolved from the RPC API originated from Sun
Microsystems in the early 1980s.
 The other well-known API is the Open Group
Distributed Computing Environment (DCE) RPC.
 Both APIs provide a tool, rpcgen, for
transforming remote procedure calls to local
procedure calls to the stub.
01/30/15 Distributed Computing, M. L. Liu 21
Java Remote Method Invocation
01/30/15 Distributed Computing, M. L. Liu22
Remote Method Invocation
 Remote Method Invocation (RMI) is an object-oriented
implementation of the Remote Procedure Call 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. The object
provides remote methods, which can be invoked in client
programs.
 Syntactically:
 A remote object is declared with a remote interface, an
extension of the 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.
01/30/15 Distributed Computing, M. L. Liu23
The Java RMI Architecture
s t u b
r e m o t e r e f e r e n c e la y e r
t r a n s p o r t la y e r
s k e le t o n
r e m o t e r e f e r e n c e la y e r
t r a n s p o r t la y e r
lo g ic a l d a t a p a t h
p h y s ic a l d a t a p a t h
s u p p o r t s t h e in t e r f a c e w it h
t h e a p p lic a t io n p r o g r a m
m a p s t h e p la t f o r m - in d e p e n d e n t s t u b / s k e le t o n
la y e r t o t h e p la tf o r m - d e p e n d e n t t r a n s p o r t
la y e r ; c a r r ie s o u t r e m o t e r e f e r e n c e p r o t o c o ls
s e t s u p , m a in t a in s , a n d s h u t s d o w n
c o n n e c t io n s ; a n d c a r r ie s o u t t h e
t r a n s p o r t p r o to c o l
o b je c t
c lie n t
o b je c t
s e r v e r
D ir e c t o r y s e r v ic e
01/30/15 Distributed Computing, M. L. Liu24
Object Registry
 The RMI API allows a number of directory
services to be used[1]
for registering a distributed
object.
 We will use a simple directory service called the
RMI registry, rmiregistry, which is provided
with the Java Software Development Kit (SDK)[2]
.
The RMI Registry is a service whose server,
when active, runs on the object server’s host
machine, by convention and by default on the
TCP port 1099.
[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 .
01/30/15 Distributed Computing, M. L. Liu25
The interaction between the stub and
the skeleton
A time-event diagram describing the
interaction between the stub and the
skeleton: s k e l e t o n
m a r s h a l p a r a m e t e r s ;
s e n d R e q u e s t
u n m a r s h a l p a r a m e t e r s
I n v o k e m e t h o d
R e m o t e
M e t h o d
e x e c u t e c o d e
a n d r e t u r n a
v a l u e
r e c e i v e r e t u r n v a l u e
m a r s h a l r e p l y
s e n d r e p l y
u n m a r s h a l l r e p l y ;
r e t u r n v a l u e
t i m e
( b a s e d o n h t t p : / / ja v a . s u n . c o m . m a r k e t i n g / c o l l a t e r a l / ja v a r i m . h t m l )
s t u b
01/30/15 Distributed Computing, M. L. Liu26
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
01/30/15 Distributed Computing, M. L. Liu27
The Remote Interface
 A Java interface is a class that serves as a
template for other classes: it contains
declarations or signatures of methods[1]
whose
implementations are to be supplied by classes
that implements the interface.
 A java remote interface is an interface that
inherits from the Java Remote class, which
allows the interface to be implemented using RMI
syntax. Other than the Remote extension and the
Remote exception that must be specified with
each method signature, a remote interface has
the same syntax as a regular or local Java
interface.
[1] They are called abstract methods.
01/30/15 Distributed Computing, M. L. Liu28
A sample remote interface
// file: SomeInterface.java
// to be implemented by a Java RMI server class.
import java.rmi.*
public interface SomeInterface extends Remote {
// signature of first remote method
public String someMethod1( )
throws java.rmi.RemoteException;
// signature of second remote method
public int someMethod2( float ) throws
java.rmi.RemoteException;
// signature of other remote methods may follow
} // end interface
01/30/15 Distributed Computing, M. L. Liu29
A sample remote interface - 2
 The java.rmi.Remote Exception must be listed
in the throw clause of each method signature.
 This exception is raised when errors occur during
the processing of a remote method call, and the
exception is required to be caught in the method
caller’s program.
 Causes of such exceptions include exceptions
that may occur during interprocess
communications, such as access failures and
connection failures, as well as problems unique to
remote method invocations, including errors
resulting from the object, the stub, or the skeleton
not being found.
01/30/15 Distributed Computing, M. L. Liu30
The Server-side Software
An object server is an object that provides the
methods of and the interface to a distributed
object. Each object server must
 implement each of the remote methods specified
in the interface,
 register an object which contains the
implementation with a directory service.
It is recommended that the two parts be
provided as separate classes.
01/30/15 Distributed Computing, M. L. Liu31
The Remote Interface Implementation
A class which implements the remote interface should be provided. The
syntax is similar to a class that implements a local interface.
import java.rmi.*;
import java.rmi.server.*;
/**
* This class implements the remote interface SomeInterface.
*/
public class SomeImpl extends UnicastRemoteObject
implements SomeInterface {
public SomeImpl() throws RemoteException {
super( );
}
public String someMethod1( ) throws RemoteException {
// code to be supplied
}
public int someMethod2( ) throws RemoteException {
// code to be supplied
}
} // end class
01/30/15 Distributed Computing, M. L. Liu32
UML diagram for the SomeImpl class
U n i c a s t R e m o t e O b je c t
S o m e I n t e r f a c e
S o m e I m p l
U M L D i a g r a m f o r S o m e I m p l
M e t h o d 1
M e t h o d 2
M e t h o d 2
M e t h o d 1
...
...
01/30/15 Distributed Computing, M. L. Liu33
Stub and Skeleton Generations
In RMI, each distributed object requires a proxy each for
the object server and the object client, knowns as the
object’s skeleton and stub respectively. These proxies are
generated from the implementation of a remote interface
using a tool provided with the Java SDK: the RMI compiler
rmic.
rmic <class name of the remote interface
implementation>
For example:
rmic SomeImpl
As a result of the compilation, two proxy files will be
generated, each prefixed with the implementation class
name:
SomeImpl_skel.class
SomeImpl_stub.class.
01/30/15 Distributed Computing, M. L. Liu34
The stub file for the object
 The stub file for the object, as well as the
remote interface file, must be shared with each
object client – these file are required for the
client program to compile.
 A copy of each file may be provided to the
object client by hand. In addition, the Java RMI
has a feature called “stub downloading” which
allows a stub file to be obtained by a client
dynamically.
01/30/15 Distributed Computing, M. L. Liu35
The Object Server
The object server class is a class whose code instantiates
and exports an object of the remote interface
implementation. Figure 10 shows a template for the
object server class.
import java.rmi.*;
……
public class SomeServer {
public static void main(String args[]) {
try{
// code for port number value to be supplied
SomeImpl exportedObj = new SomeImpl();
startRegistry(RMIPortNum);
// register the object under the name “some”
registryURL = "rmi://localhost:" + portNum + "/some";
Naming.rebind(registryURL, exportedObj);
System.out.println("Some Server ready.");
}// end try
} // end main
01/30/15 Distributed Computing, M. L. Liu36
The Object Server - 2
// This method starts a RMI registry on the local host, if it
// does not already exists at the specified port number.
private static void startRegistry(int RMIPortNum)
throws RemoteException{
try {
Registry registry= LocateRegistry.getRegistry(RMIPortNum);
registry.list( );
// The above call will throw an exception
// if the registry does not already exist
}
catch (RemoteException ex) {
// No valid registry at that port.
System.out.println(
"RMI registry cannot be located at port " + RMIPortNum);
Registry registry= LocateRegistry.createRegistry(RMIPortNum);
System.out.println(
"RMI registry created at port " + RMIPortNum);
}
} // end startRegistry
01/30/15 Distributed Computing, M. L. Liu37
The Object Server - 3
 In our object server template, the code for exporting an object is as
follows:
// register the object under the name “some”
registryURL = "rmi://localhost:" + portNum +
"/some";
Naming.rebind(registryURL, exportedObj);
 The Naming class provides methods for storing and obtaining
references from the registry. In particular, the rebind method allow
an object reference to be stored in the registry with a URL in the
form of
rmi://<host name>:<port number>/<reference name>
 The rebind method will overwrite any reference in the registry
bound with the given reference name. If the overwriting is not
desirable, there is also a bind method.
 The host name should be the name of the server, or simply
“localhost”. The reference name is a name of your choice, and
should be unique in the registry.
01/30/15 Distributed Computing, M. L. Liu38
The RMI Registry
 A server exports an object by registering it by a symbolic name with a
server known as the RMI registry.
// Create an object of the Interface
SomeInterfacel obj = new SomeInterface(“Server1”);
// Register the object; rebind will overwirte existing
// registration by same name – bind( ) will not.
Naming.rebind(“Server1”, obj);
 A server, called the RMI Registry, is required to run on the host of the
server which exports remote objects.
 The RMIRegistry is a server located at port 1099 by default
 It can be invoked dynamically in the server class:
import java.rmi.registry.LocateRegistry;
…
LocateRegistry.createRegistry ( 1099 );
…
01/30/15 Distributed Computing, M. L. Liu39
The RMI Registry - 2
 Alternatively, an RMI registry can be
activated by hand using the rmiregistry
utility which comes with the Java Software
Development Kit (SDK), as follows:
rmiregistry <port number>
where the port number is a TCP port
number. If no port number is specified, port
number 1099 is assumed.
 The registry will run continuously until it is
shut down (via CTRL-C, for example)
01/30/15 Distributed Computing, M. L. Liu40
The Object Server - 5
 When an object server is executed, the exporting
of the distributed object causes the server
process to begin to listen and wait for clients to
connect and request the service of the object.
 An RMI object server is a concurrent server: each
request from an object client is serviced using a
separate thread of the server. Note that if a client
process invokes multiple remote method calls,
these calls will be executed concurrently unless
provisions are made in the client process to
synchronize the calls.
01/30/15 Distributed Computing, M. L. Liu41
The Client-side Software
The program for the client class is like any
other Java class.
The syntax needed for RMI involves
 locating the RMI Registry in the server host,
and
 looking up the remote reference for the server
object; the reference can then be cast to the remote
interface class and the remote methods invoked.
01/30/15 Distributed Computing, M. L. Liu42
The Client-side Software - 2
import java.rmi.*;
….
public class SomeClient {
public static void main(String args[]) {
try {
String registryURL =
"rmi://localhost:" + portNum + "/some";
SomeInterface h =
(SomeInterface)Naming.lookup(registryURL);
// invoke the remote method(s)
String message = h.method1();
System.out.println(message);
// method2 can be invoked similarly
} // end try
catch (Exception e) {
System.out.println("Exception in SomeClient: " + e);
}
} //end main
// Definition for other methods of the class, if any.
}//end class
01/30/15 Distributed Computing, M. L. Liu43
Looking up the remote object
The lookup method of the Naming class
is used to retrieve the object reference, if
any, previously stored in the registry by the
object server. Note that the retrieved
reference must be cast to the remote
interface (not its implementation) class.
String registryURL =
"rmi://localhost:" + portNum + "/some";
SomeInterface h =
(SomeInterface)Naming.lookup(registryURL);
01/30/15 Distributed Computing, M. L. Liu44
Invoking the Remote Method
The remote interface reference can be used to
invoke any of the methods in the remote
interface, as in the example:
String message = h.method1();
System.out.println(message);
 Note that the syntax for the invocation of the
remote methods is the same as for local methods.
 It is a common mistake to cast the object
retrieved from the registry to the interface
implementation class or the server object class .
Instead it should be cast as the interface class.
01/30/15 Distributed Computing, M. L. Liu 45
Steps for building an RMI application
01/30/15 Distributed Computing, M. L. Liu46
Algorithm for developing the server-side software
1. Open a directory for all the files to be generated for this application.
2. Specify the remote-server interface in SomeInterface.java.
Compile it until there is no more syntax error.
3. Implement the interface in SomeImpl.java Compile it until there is
no more syntax error.
4. Use the RMI compiler rmic to process the implementation class and
generate the stub file and skelton file for the remote object:
rmic SomeImpl
The files generated can be found in the directory as
SomeImpl_Skel.class and SomeImpl_Stub.class.
Steps 3 and 4 must be repeated each time that a change is made to
the interface implementation.
5. Create the object server program SomeServer.java. Compile it
until there is no more syntax error.
6. Activate the object server
java SomeServer
 
01/30/15 Distributed Computing, M. L. Liu47
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.
Alternatively, obtain a copy of the source file for the
remote interface, and compile it using javac to
generate the interface class file.
3. Obtain a copy of the stub file for the implementation of
the interface:
SomeImpl_Stub.class.
4. Develop the client program SomeClient.java, and
compile it to generate the client class.
5. Activate the client.
java SomeClient
 
01/30/15 Distributed Computing, M. L. Liu48
Placement of files for a RMI application
S o m e C l i e n t . c l a s s
O b je c t C l i e n t h o s t O b je c t S e r v e r h o s t
o b je c t s e r v e r d i r e c t o r y
S o m e I n t e r f a c e . c l a s s
S o m e I n t e r f a c e . c l a s s
S o m e I m p l . c l a s s
S o m e S e r v e r . c l a s s
S o m e I m p l _ S k e l . c l a s s
S o m e I m p l _ S t u b . c l a s s
o b je c t c l i e n t d i r e c t o r y
01/30/15 Distributed Computing, M. L. Liu49
Testing and Debugging an RMI Application
1. Build a template for a minimal RMI program. Start with a
remote interface with a single signature, its
implementation using a stub, a server program which
exports the object, and a client program which invokes the
remote method. Test the template programs on one host
until the remote method can be made successfully.
2. Add one signature at a time to the interface. With each
addition, modify the client program to invoke the added
method.
3. Fill in the definition of each remote method, one at a time.
Test and thoroughly debug each newly added method
before proceeding with the next one.
4. After all remote methods have been thoroughly tested,
develop the client application using an incremental
approach. With each increment, test and debug the
01/30/15 Distributed Computing, M. L. Liu50
Comparison of the RMI and the socket APIs
The remote method invocation API is an efficient
tool for building network applications. It can be
used in lieu of the socket API in a network
application. Some of the tradeoffs between the
RMI API and the socket API are as follows:
 The socket API is closely related to the operating
system, and hence has less execution overhead. For
applications which require high performance, this may
be a consideration.
 The RMI API provides the abstraction which eases the
task of software development. Programs developed
with a higher level of abstraction are more
comprehensible and hence easier to debug.
01/30/15 Distributed Computing, M. L. Liu 51
The HelloWorld Sample
01/30/15 Distributed Computing, M. L. Liu52
Diagrams for the Hello application
s a y H e l l o ( )
H e l l o I n t e r f a c e
U n i c a s t R e m o t e O b j e c t
H e l l o I m p lH e l l o S e r v e r
l i s t R e g i s t r y ( )
s t a r t R e g i s t r y ( )
s e r v e rr e g i s t r yc l i e n t
r e b i n d ( )
l o o k u p ( )
s a y H e l l o ( )
s e q u e n c e d i a g r a m
U M L d i a g r a m
H e l l o C l i e n t
01/30/15 Distributed Computing, M. L. Liu53
Source files for the Hello application
 HelloInterface.java
 HelloImpl.java
 HelloClient.java
01/30/15 Distributed Computing, M. L. Liu54
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.
S e r v e r
C lie n t
C lie n t
C lie n t
E x p e n s e R e c o r d s
J D B C
R M I
R M I
R M I
A n E x p e n s e R e p o r t i n g S y s t e m , f r o m h t t p :/ / ja v a . s u n . c o m
01/30/15 Distributed Computing, M. L. Liu55
To be continued
The Java RMI facility is rich in features.
This chapter has presented a very basic
subset of those features, as an illustration
of a distributed object system. Some of the
more interesting advanced features of RMI
will be presented in the next chapter.
01/30/15 Distributed Computing, M. L. Liu56
Summary - 1
 The distributed object paradigm is at a higher
level of abstraction than the message-passing
paradigm.
 Using the paradigm, a process invokes
methods of a remote object, passing in
data as arguments and receiving a return
value with each call, using syntax similar to
local method calls.
 In a distributed object system, an object
server provides a distributed object whose
methods can be invoked by an object
client.
01/30/15 Distributed Computing, M. L. Liu57
Summary - 2
 Each side requires a proxy which interacts with the
system’s runtime support to perform the necessary
IPC.
 an object registry must be available which allow
distributed objects to be registered and looked up.
 Among the best-known distributed object system
protocols are the Java Remote Method Invocation
(RMI), the Distributed Component Object, Model
(DCOM), the Common Object Request Broker
Architecture (CORBA) , and the Simple Object
Access Protocol (SOAP).
01/30/15 Distributed Computing, M. L. Liu58
Summary - 3
 Java RMI is representative of distributed object
systems.
 The architecture of the Java Remote Method
Invocation API includes three abstract layers on
both the client side and the server side.
 The software for a RMI application includes a
remote interface, server-side software, and client-
side software.
 What are the tradeoffs between the socket API and
the Java RMI API?

Contenu connexe

Tendances

Operating Task Redistribution in Hyperconverged Networks
Operating Task Redistribution in Hyperconverged Networks Operating Task Redistribution in Hyperconverged Networks
Operating Task Redistribution in Hyperconverged Networks
IJECEIAES
 
Bx32903907
Bx32903907Bx32903907
Bx32903907
IJMER
 

Tendances (6)

Operating Task Redistribution in Hyperconverged Networks
Operating Task Redistribution in Hyperconverged Networks Operating Task Redistribution in Hyperconverged Networks
Operating Task Redistribution in Hyperconverged Networks
 
Routing Protocols of Distributed Hash Table Based Peer to Peer Networks
Routing Protocols of Distributed Hash Table Based Peer to Peer NetworksRouting Protocols of Distributed Hash Table Based Peer to Peer Networks
Routing Protocols of Distributed Hash Table Based Peer to Peer Networks
 
Bx32903907
Bx32903907Bx32903907
Bx32903907
 
Efficient Detection Of Selfish Node In Manet Using A Colloborative Watchdog
Efficient Detection Of Selfish Node In Manet Using A Colloborative WatchdogEfficient Detection Of Selfish Node In Manet Using A Colloborative Watchdog
Efficient Detection Of Selfish Node In Manet Using A Colloborative Watchdog
 
Probablistic information retrieval
Probablistic information retrievalProbablistic information retrieval
Probablistic information retrieval
 
IDENTIFICATION AND INVESTIGATION OF THE USER SESSION FOR LAN CONNECTIVITY VIA...
IDENTIFICATION AND INVESTIGATION OF THE USER SESSION FOR LAN CONNECTIVITY VIA...IDENTIFICATION AND INVESTIGATION OF THE USER SESSION FOR LAN CONNECTIVITY VIA...
IDENTIFICATION AND INVESTIGATION OF THE USER SESSION FOR LAN CONNECTIVITY VIA...
 

Similaire à Chapter7

Formal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-BFormal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-B
ijcsit
 
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
Eswar Publications
 

Similaire à Chapter7 (20)

A LIGHT-WEIGHT DISTRIBUTED SYSTEM FOR THE PROCESSING OF REPLICATED COUNTER-LI...
A LIGHT-WEIGHT DISTRIBUTED SYSTEM FOR THE PROCESSING OF REPLICATED COUNTER-LI...A LIGHT-WEIGHT DISTRIBUTED SYSTEM FOR THE PROCESSING OF REPLICATED COUNTER-LI...
A LIGHT-WEIGHT DISTRIBUTED SYSTEM FOR THE PROCESSING OF REPLICATED COUNTER-LI...
 
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONSAN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
 
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONSAN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
AN EFFICIENT GROUP AUTHENTICATION FOR GROUP COMMUNICATIONS
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
 
System Event Monitoring for Active Authentication
System Event Monitoring for Active AuthenticationSystem Event Monitoring for Active Authentication
System Event Monitoring for Active Authentication
 
Intrusion detection in heterogeneous network by multipath routing based toler...
Intrusion detection in heterogeneous network by multipath routing based toler...Intrusion detection in heterogeneous network by multipath routing based toler...
Intrusion detection in heterogeneous network by multipath routing based toler...
 
Intrusion detection in heterogeneous network by multipath routing based toler...
Intrusion detection in heterogeneous network by multipath routing based toler...Intrusion detection in heterogeneous network by multipath routing based toler...
Intrusion detection in heterogeneous network by multipath routing based toler...
 
04 Client Server Technology
04 Client Server Technology04 Client Server Technology
04 Client Server Technology
 
G0434045
G0434045G0434045
G0434045
 
Preclusion Measures for Protecting P2P Networks from Malware Spread
Preclusion Measures for Protecting P2P Networks from Malware  SpreadPreclusion Measures for Protecting P2P Networks from Malware  Spread
Preclusion Measures for Protecting P2P Networks from Malware Spread
 
IRJET - Twitter Spam Detection using Cobweb
IRJET - Twitter Spam Detection using CobwebIRJET - Twitter Spam Detection using Cobweb
IRJET - Twitter Spam Detection using Cobweb
 
EXPLORING PEER-TO-PEER DATA MINING
EXPLORING PEER-TO-PEER DATA MININGEXPLORING PEER-TO-PEER DATA MINING
EXPLORING PEER-TO-PEER DATA MINING
 
Exploring Peer-To-Peer Data Mining
Exploring Peer-To-Peer Data MiningExploring Peer-To-Peer Data Mining
Exploring Peer-To-Peer Data Mining
 
Fuzzy logic based authentication in cognitive radio networks
Fuzzy logic based authentication in cognitive radio networksFuzzy logic based authentication in cognitive radio networks
Fuzzy logic based authentication in cognitive radio networks
 
Formal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-BFormal Verification of Distributed Checkpointing Using Event-B
Formal Verification of Distributed Checkpointing Using Event-B
 
Event detection and summarization based on social networks and semantic query...
Event detection and summarization based on social networks and semantic query...Event detection and summarization based on social networks and semantic query...
Event detection and summarization based on social networks and semantic query...
 
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
Outlier Detection in Secure Shell Honeypot using Particle Swarm Optimization ...
 
Probabilistic models for anomaly detection based on usage of network traffic
Probabilistic models for anomaly detection based on usage of network trafficProbabilistic models for anomaly detection based on usage of network traffic
Probabilistic models for anomaly detection based on usage of network traffic
 
PRIVACY ENHANCEMENT OF NODE IN OPPORTUNISTIC NETWORK BY USING VIRTUAL-ID
PRIVACY ENHANCEMENT OF NODE IN OPPORTUNISTIC NETWORK BY USING VIRTUAL-IDPRIVACY ENHANCEMENT OF NODE IN OPPORTUNISTIC NETWORK BY USING VIRTUAL-ID
PRIVACY ENHANCEMENT OF NODE IN OPPORTUNISTIC NETWORK BY USING VIRTUAL-ID
 

Plus de lopjuan

Chapter 2
Chapter 2Chapter 2
Chapter 2
lopjuan
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
lopjuan
 
Chapter 4 2
Chapter 4 2Chapter 4 2
Chapter 4 2
lopjuan
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
lopjuan
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1
lopjuan
 
Java servlets
Java servletsJava servlets
Java servlets
lopjuan
 
Java applets
Java appletsJava applets
Java applets
lopjuan
 
Chapter10
Chapter10Chapter10
Chapter10
lopjuan
 
Web services
Web servicesWeb services
Web services
lopjuan
 

Plus de lopjuan (9)

Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 4 2
Chapter 4 2Chapter 4 2
Chapter 4 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1
 
Java servlets
Java servletsJava servlets
Java servlets
 
Java applets
Java appletsJava applets
Java applets
 
Chapter10
Chapter10Chapter10
Chapter10
 
Web services
Web servicesWeb services
Web services
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Chapter7

  • 1. 01/30/15 Distributed Computing, M. L. Liu 1 Distributed Objects M. L. Liu
  • 2. 01/30/15 Distributed Computing, M. L. Liu 2 Message Passing vs. Distributed Objects
  • 3. 01/30/15 Distributed Computing, M. L. Liu3 Message Passing versus Distributed Objects  The message-passing paradigm is a natural model for distributed computing, in the sense that it mimics interhuman communications. It is an appropriate paradigm for network services where processes interact with each other through the exchanges of messages.  However, the abstraction provided by this paradigm does not meet the needs of the complexity of sophisticated network applications.
  • 4. 01/30/15 Distributed Computing, M. L. Liu4 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. 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.
  • 5. 01/30/15 Distributed Computing, M. L. Liu5 The distributed object paradigm  The distributed object paradigm is a paradigm that provides abstractions beyond those of the message-passing model. As its name implies, the paradigm is based on objects that exist in a distributed system.  In object-oriented programming, supported by an object-oriented programming language such as Java, objects are used to represent an entity significant to an application. Each object encapsulates:  the state or data of the entity: in Java, such data is contained in the instance variables of each object;  the operations of the entity, through which the state of the entity can be accessed or updated.
  • 6. 01/30/15 Distributed Computing, M. L. Liu6 object-oriented programming To illustrate, consider objects of the DatagramMessage class in Figure 6f (in Chapter 6). 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 three 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 message to be retrieved, and  a getAddress method, which allows the sender’s address to be retrieved.
  • 7. 01/30/15 Distributed Computing, M. L. Liu7 Local Objects vs. Distributed Objects  Local objects are those whose methods can only be invoked by a local process, a process that runs on the same computer on which the object exists.  A distributed object is one whose methods can be invoked by a remote process, a process running on a computer connected via a network to the computer on which the object exists.
  • 8. 01/30/15 Distributed Computing, M. L. Liu8 The Distributed Object Paradigm In a distributed object paradigm, network resources are represented by distributed objects. To request service from a network resource, a process invokes one of its operations or methods, passing data as parameters to the method. The method is executed on the remote host, and the response is sent back to the requesting process as a return value. o b je c t s t a t e d a t a i t e m o b je c t o p e r a t i o n H o s t A H o s t B c l i e n t p r o c e s s m e t h o d c a l l a d i s t r i b u t e d o b je c t
  • 9. 01/30/15 Distributed Computing, M. L. Liu9 Message Passing versus Distributed Objects - 3 Compared to the message-passing paradigm, which is data-oriented, the distributed objects paradigm is action- oriented: the focus is on the invocation of the operations, while the data passed takes on a secondary role. Although less intuitive to human-beings, the distributed- object paradigm is more natural to object- oriented software development.
  • 10. 01/30/15 Distributed Computing, M. L. Liu10 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 call data for the parameters, if any.  The method call invokes an action performed by the method on host A, and a return value, if any, is passed from host A to host B.  A process which makes use of a distributed object is said to be a client process of that object, and the methods of the object are called remote methods (as opposed to local methods, or methods belonging to a local object) to the client process.
  • 11. 01/30/15 Distributed Computing, M. L. Liu 11 The Distributed Objects Paradigm
  • 12. 01/30/15 Distributed Computing, M. L. Liu12 An Archetypal Distributed Objects System o b je c t c l i e n t o b je c t s e r v e r c l i e n t p r o x y s e r v e r p r o x y r u n t i m e s u p p o r t n e t w o r k s u p p o r t n e t w o r k s u p p o r t p h y s i c a l d a t a p a t h l o g i c a l d a t a p a t h o b je c t r e g i s t r y r u n t i m e s u p p o r t
  • 13. 01/30/15 Distributed Computing, M. L. Liu13 Distributed Object System  A distributed object is provided, or exported, by a process, here called the object server. A facility, here called an object registry, must be present in the system architecture for the distributed object to be registered.  To access a distributed object, a process –an object client – looks up the object registry for a reference[1] to the object. This reference is used by the object client to make calls to the methods. [1] A reference is a “handle” for an object; it is a representation through which an object can be located in the computer where the object resides.
  • 14. 01/30/15 Distributed Computing, M. L. Liu14 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, which interacts which 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.
  • 15. 01/30/15 Distributed Computing, M. L. Liu15 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.  The server proxy interfaces with the distributed object to invoke the method call locally, 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 return value, is forwarded by the server proxy to the client proxy, via the runtime support and network support on both sides.
  • 16. 01/30/15 Distributed Computing, M. L. Liu16 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), ~ the Common Object Request Broker Architecture (CORBA) systems, ~ the Distributed Component Object Model (DCOM), ~ mechanisms that support the Simple Object Access Protocol (SOAP). Of these, the most straightforward is the Java RMI
  • 17. 01/30/15 Distributed Computing, M. L. Liu 17 From Remote Procedure Call to Remote Method Invocation
  • 18. 01/30/15 Distributed Computing, M. L. Liu18 Remote Procedure Calls (RPC)  Remote Method Invocation has its origin in a paradigm called Remote Procedure Call  In the remote procedure call 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 return value, if any, is transmitted from the callee to the caller. p r o c 1 ( a r g 1 , a r g 2 ) P r o c e s s A P r o c e s s B a r e m o t e p r o c e d u r e r e t u r n v a l u e e x e c u t i o n f l o w
  • 19. 01/30/15 Distributed Computing, M. L. Liu19 Local Procedure Call and Remote Procedure Call p r o c 1 e x e c u t i o n f l o w p r o c 2 h o s t A A l o c a l p r o c e d u r e c a l l h o s t A h o s t B A r e m o t e p r o c e d u r e c a l l ( t h e r e t u r n e x e c u t i o n p a t h i s n o t s h o w n ) p r o c 1 p r o c 2 p r o x y p r o x y 1 . p r o c 1 o n h o s t A m a k e s a c a l l t o p r o c 2 o n h o s t B . 2 . T h e r u n t i m e s u p p o r t m a p s t h e c a l l t o a c a l l t o t h e p r o x y o n h o s t A . 3 . T h e p r o x y m a r s h a l l s t h e d a t a a n d m a k e s a n I P C c a l l t o a p r o x y o n h o s t B . 7 . T h e p r o x y r e c e i v e d t h e r e t u r n v a l u e , u n m a r s h a l l s t h e d a t a , a n d f o r w a r d s t h e r e t u r n v a l u e t o p r o c 1 , w h i c h r e s u m e s i t s e x e c u t i o n f l o w . 4 . T h e p r o x y o n h o s t B u n m a r s h a l l s t h e d a t a r e c e i v e d a n d i s s u e s a c a l l t o p r o c 2 . 5 . T h e c o d e i n p r o c 2 i s e x e c u t e d a n d r e t u r n s t o t h e p r o x y o n h o s t B . 6 . T h e p r o x y m a r s h a l l s t h e r e t u r n v a l u e a n d m a k e s a n I P C c a l l t o t h e p r o x y o n h o s t A .
  • 20. 01/30/15 Distributed Computing, M. L. Liu20 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 Remote Procedure Call, evolved from the RPC API originated from Sun Microsystems in the early 1980s.  The other well-known API is the Open Group Distributed Computing Environment (DCE) RPC.  Both APIs provide a tool, rpcgen, for transforming remote procedure calls to local procedure calls to the stub.
  • 21. 01/30/15 Distributed Computing, M. L. Liu 21 Java Remote Method Invocation
  • 22. 01/30/15 Distributed Computing, M. L. Liu22 Remote Method Invocation  Remote Method Invocation (RMI) is an object-oriented implementation of the Remote Procedure Call 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. The object provides remote methods, which can be invoked in client programs.  Syntactically:  A remote object is declared with a remote interface, an extension of the 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.
  • 23. 01/30/15 Distributed Computing, M. L. Liu23 The Java RMI Architecture s t u b r e m o t e r e f e r e n c e la y e r t r a n s p o r t la y e r s k e le t o n r e m o t e r e f e r e n c e la y e r t r a n s p o r t la y e r lo g ic a l d a t a p a t h p h y s ic a l d a t a p a t h s u p p o r t s t h e in t e r f a c e w it h t h e a p p lic a t io n p r o g r a m m a p s t h e p la t f o r m - in d e p e n d e n t s t u b / s k e le t o n la y e r t o t h e p la tf o r m - d e p e n d e n t t r a n s p o r t la y e r ; c a r r ie s o u t r e m o t e r e f e r e n c e p r o t o c o ls s e t s u p , m a in t a in s , a n d s h u t s d o w n c o n n e c t io n s ; a n d c a r r ie s o u t t h e t r a n s p o r t p r o to c o l o b je c t c lie n t o b je c t s e r v e r D ir e c t o r y s e r v ic e
  • 24. 01/30/15 Distributed Computing, M. L. Liu24 Object Registry  The RMI API allows a number of directory services to be used[1] for registering a distributed object.  We will use a simple directory service called the RMI registry, rmiregistry, which is provided with the Java Software Development Kit (SDK)[2] . The RMI Registry is a service whose server, when active, runs on the object server’s host machine, by convention and by default on the TCP port 1099. [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 .
  • 25. 01/30/15 Distributed Computing, M. L. Liu25 The interaction between the stub and the skeleton A time-event diagram describing the interaction between the stub and the skeleton: s k e l e t o n m a r s h a l p a r a m e t e r s ; s e n d R e q u e s t u n m a r s h a l p a r a m e t e r s I n v o k e m e t h o d R e m o t e M e t h o d e x e c u t e c o d e a n d r e t u r n a v a l u e r e c e i v e r e t u r n v a l u e m a r s h a l r e p l y s e n d r e p l y u n m a r s h a l l r e p l y ; r e t u r n v a l u e t i m e ( b a s e d o n h t t p : / / ja v a . s u n . c o m . m a r k e t i n g / c o l l a t e r a l / ja v a r i m . h t m l ) s t u b
  • 26. 01/30/15 Distributed Computing, M. L. Liu26 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
  • 27. 01/30/15 Distributed Computing, M. L. Liu27 The Remote Interface  A Java interface is a class that serves as a template for other classes: it contains declarations or signatures of methods[1] whose implementations are to be supplied by classes that implements the interface.  A java remote interface is an interface that inherits from the Java Remote class, which allows the interface to be implemented using RMI syntax. Other than the Remote extension and the Remote exception that must be specified with each method signature, a remote interface has the same syntax as a regular or local Java interface. [1] They are called abstract methods.
  • 28. 01/30/15 Distributed Computing, M. L. Liu28 A sample remote interface // file: SomeInterface.java // to be implemented by a Java RMI server class. import java.rmi.* public interface SomeInterface extends Remote { // signature of first remote method public String someMethod1( ) throws java.rmi.RemoteException; // signature of second remote method public int someMethod2( float ) throws java.rmi.RemoteException; // signature of other remote methods may follow } // end interface
  • 29. 01/30/15 Distributed Computing, M. L. Liu29 A sample remote interface - 2  The java.rmi.Remote Exception must be listed in the throw clause of each method signature.  This exception is raised when errors occur during the processing of a remote method call, and the exception is required to be caught in the method caller’s program.  Causes of such exceptions include exceptions that may occur during interprocess communications, such as access failures and connection failures, as well as problems unique to remote method invocations, including errors resulting from the object, the stub, or the skeleton not being found.
  • 30. 01/30/15 Distributed Computing, M. L. Liu30 The Server-side Software An object server is an object that provides the methods of and the interface to a distributed object. Each object server must  implement each of the remote methods specified in the interface,  register an object which contains the implementation with a directory service. It is recommended that the two parts be provided as separate classes.
  • 31. 01/30/15 Distributed Computing, M. L. Liu31 The Remote Interface Implementation A class which implements the remote interface should be provided. The syntax is similar to a class that implements a local interface. import java.rmi.*; import java.rmi.server.*; /** * This class implements the remote interface SomeInterface. */ public class SomeImpl extends UnicastRemoteObject implements SomeInterface { public SomeImpl() throws RemoteException { super( ); } public String someMethod1( ) throws RemoteException { // code to be supplied } public int someMethod2( ) throws RemoteException { // code to be supplied } } // end class
  • 32. 01/30/15 Distributed Computing, M. L. Liu32 UML diagram for the SomeImpl class U n i c a s t R e m o t e O b je c t S o m e I n t e r f a c e S o m e I m p l U M L D i a g r a m f o r S o m e I m p l M e t h o d 1 M e t h o d 2 M e t h o d 2 M e t h o d 1 ... ...
  • 33. 01/30/15 Distributed Computing, M. L. Liu33 Stub and Skeleton Generations In RMI, each distributed object requires a proxy each for the object server and the object client, knowns as the object’s skeleton and stub respectively. These proxies are generated from the implementation of a remote interface using a tool provided with the Java SDK: the RMI compiler rmic. rmic <class name of the remote interface implementation> For example: rmic SomeImpl As a result of the compilation, two proxy files will be generated, each prefixed with the implementation class name: SomeImpl_skel.class SomeImpl_stub.class.
  • 34. 01/30/15 Distributed Computing, M. L. Liu34 The stub file for the object  The stub file for the object, as well as the remote interface file, must be shared with each object client – these file are required for the client program to compile.  A copy of each file may be provided to the object client by hand. In addition, the Java RMI has a feature called “stub downloading” which allows a stub file to be obtained by a client dynamically.
  • 35. 01/30/15 Distributed Computing, M. L. Liu35 The Object Server The object server class is a class whose code instantiates and exports an object of the remote interface implementation. Figure 10 shows a template for the object server class. import java.rmi.*; …… public class SomeServer { public static void main(String args[]) { try{ // code for port number value to be supplied SomeImpl exportedObj = new SomeImpl(); startRegistry(RMIPortNum); // register the object under the name “some” registryURL = "rmi://localhost:" + portNum + "/some"; Naming.rebind(registryURL, exportedObj); System.out.println("Some Server ready."); }// end try } // end main
  • 36. 01/30/15 Distributed Computing, M. L. Liu36 The Object Server - 2 // This method starts a RMI registry on the local host, if it // does not already exists at the specified port number. private static void startRegistry(int RMIPortNum) throws RemoteException{ try { Registry registry= LocateRegistry.getRegistry(RMIPortNum); registry.list( ); // The above call will throw an exception // if the registry does not already exist } catch (RemoteException ex) { // No valid registry at that port. System.out.println( "RMI registry cannot be located at port " + RMIPortNum); Registry registry= LocateRegistry.createRegistry(RMIPortNum); System.out.println( "RMI registry created at port " + RMIPortNum); } } // end startRegistry
  • 37. 01/30/15 Distributed Computing, M. L. Liu37 The Object Server - 3  In our object server template, the code for exporting an object is as follows: // register the object under the name “some” registryURL = "rmi://localhost:" + portNum + "/some"; Naming.rebind(registryURL, exportedObj);  The Naming class provides methods for storing and obtaining references from the registry. In particular, the rebind method allow an object reference to be stored in the registry with a URL in the form of rmi://<host name>:<port number>/<reference name>  The rebind method will overwrite any reference in the registry bound with the given reference name. If the overwriting is not desirable, there is also a bind method.  The host name should be the name of the server, or simply “localhost”. The reference name is a name of your choice, and should be unique in the registry.
  • 38. 01/30/15 Distributed Computing, M. L. Liu38 The RMI Registry  A server exports an object by registering it by a symbolic name with a server known as the RMI registry. // Create an object of the Interface SomeInterfacel obj = new SomeInterface(“Server1”); // Register the object; rebind will overwirte existing // registration by same name – bind( ) will not. Naming.rebind(“Server1”, obj);  A server, called the RMI Registry, is required to run on the host of the server which exports remote objects.  The RMIRegistry is a server located at port 1099 by default  It can be invoked dynamically in the server class: import java.rmi.registry.LocateRegistry; … LocateRegistry.createRegistry ( 1099 ); …
  • 39. 01/30/15 Distributed Computing, M. L. Liu39 The RMI Registry - 2  Alternatively, an RMI registry can be activated by hand using the rmiregistry utility which comes with the Java Software Development Kit (SDK), as follows: rmiregistry <port number> where the port number is a TCP port number. If no port number is specified, port number 1099 is assumed.  The registry will run continuously until it is shut down (via CTRL-C, for example)
  • 40. 01/30/15 Distributed Computing, M. L. Liu40 The Object Server - 5  When an object server is executed, the exporting of the distributed object causes the server process to begin to listen and wait for clients to connect and request the service of the object.  An RMI object server is a concurrent server: each request from an object client is serviced using a separate thread of the server. Note that if a client process invokes multiple remote method calls, these calls will be executed concurrently unless provisions are made in the client process to synchronize the calls.
  • 41. 01/30/15 Distributed Computing, M. L. Liu41 The Client-side Software The program for the client class is like any other Java class. The syntax needed for RMI involves  locating the RMI Registry in the server host, and  looking up the remote reference for the server object; the reference can then be cast to the remote interface class and the remote methods invoked.
  • 42. 01/30/15 Distributed Computing, M. L. Liu42 The Client-side Software - 2 import java.rmi.*; …. public class SomeClient { public static void main(String args[]) { try { String registryURL = "rmi://localhost:" + portNum + "/some"; SomeInterface h = (SomeInterface)Naming.lookup(registryURL); // invoke the remote method(s) String message = h.method1(); System.out.println(message); // method2 can be invoked similarly } // end try catch (Exception e) { System.out.println("Exception in SomeClient: " + e); } } //end main // Definition for other methods of the class, if any. }//end class
  • 43. 01/30/15 Distributed Computing, M. L. Liu43 Looking up the remote object The lookup method of the Naming class is used to retrieve the object reference, if any, previously stored in the registry by the object server. Note that the retrieved reference must be cast to the remote interface (not its implementation) class. String registryURL = "rmi://localhost:" + portNum + "/some"; SomeInterface h = (SomeInterface)Naming.lookup(registryURL);
  • 44. 01/30/15 Distributed Computing, M. L. Liu44 Invoking the Remote Method The remote interface reference can be used to invoke any of the methods in the remote interface, as in the example: String message = h.method1(); System.out.println(message);  Note that the syntax for the invocation of the remote methods is the same as for local methods.  It is a common mistake to cast the object retrieved from the registry to the interface implementation class or the server object class . Instead it should be cast as the interface class.
  • 45. 01/30/15 Distributed Computing, M. L. Liu 45 Steps for building an RMI application
  • 46. 01/30/15 Distributed Computing, M. L. Liu46 Algorithm for developing the server-side software 1. Open a directory for all the files to be generated for this application. 2. Specify the remote-server interface in SomeInterface.java. Compile it until there is no more syntax error. 3. Implement the interface in SomeImpl.java Compile it until there is no more syntax error. 4. Use the RMI compiler rmic to process the implementation class and generate the stub file and skelton file for the remote object: rmic SomeImpl The files generated can be found in the directory as SomeImpl_Skel.class and SomeImpl_Stub.class. Steps 3 and 4 must be repeated each time that a change is made to the interface implementation. 5. Create the object server program SomeServer.java. Compile it until there is no more syntax error. 6. Activate the object server java SomeServer  
  • 47. 01/30/15 Distributed Computing, M. L. Liu47 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. Alternatively, obtain a copy of the source file for the remote interface, and compile it using javac to generate the interface class file. 3. Obtain a copy of the stub file for the implementation of the interface: SomeImpl_Stub.class. 4. Develop the client program SomeClient.java, and compile it to generate the client class. 5. Activate the client. java SomeClient  
  • 48. 01/30/15 Distributed Computing, M. L. Liu48 Placement of files for a RMI application S o m e C l i e n t . c l a s s O b je c t C l i e n t h o s t O b je c t S e r v e r h o s t o b je c t s e r v e r d i r e c t o r y S o m e I n t e r f a c e . c l a s s S o m e I n t e r f a c e . c l a s s S o m e I m p l . c l a s s S o m e S e r v e r . c l a s s S o m e I m p l _ S k e l . c l a s s S o m e I m p l _ S t u b . c l a s s o b je c t c l i e n t d i r e c t o r y
  • 49. 01/30/15 Distributed Computing, M. L. Liu49 Testing and Debugging an RMI Application 1. Build a template for a minimal RMI program. Start with a remote interface with a single signature, its implementation using a stub, a server program which exports the object, and a client program which invokes the remote method. Test the template programs on one host until the remote method can be made successfully. 2. Add one signature at a time to the interface. With each addition, modify the client program to invoke the added method. 3. Fill in the definition of each remote method, one at a time. Test and thoroughly debug each newly added method before proceeding with the next one. 4. After all remote methods have been thoroughly tested, develop the client application using an incremental approach. With each increment, test and debug the
  • 50. 01/30/15 Distributed Computing, M. L. Liu50 Comparison of the RMI and the socket APIs The remote method invocation API is an efficient tool for building network applications. It can be used in lieu of the socket API in a network application. Some of the tradeoffs between the RMI API and the socket API are as follows:  The socket API is closely related to the operating system, and hence has less execution overhead. For applications which require high performance, this may be a consideration.  The RMI API provides the abstraction which eases the task of software development. Programs developed with a higher level of abstraction are more comprehensible and hence easier to debug.
  • 51. 01/30/15 Distributed Computing, M. L. Liu 51 The HelloWorld Sample
  • 52. 01/30/15 Distributed Computing, M. L. Liu52 Diagrams for the Hello application s a y H e l l o ( ) H e l l o I n t e r f a c e U n i c a s t R e m o t e O b j e c t H e l l o I m p lH e l l o S e r v e r l i s t R e g i s t r y ( ) s t a r t R e g i s t r y ( ) s e r v e rr e g i s t r yc l i e n t r e b i n d ( ) l o o k u p ( ) s a y H e l l o ( ) s e q u e n c e d i a g r a m U M L d i a g r a m H e l l o C l i e n t
  • 53. 01/30/15 Distributed Computing, M. L. Liu53 Source files for the Hello application  HelloInterface.java  HelloImpl.java  HelloClient.java
  • 54. 01/30/15 Distributed Computing, M. L. Liu54 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. S e r v e r C lie n t C lie n t C lie n t E x p e n s e R e c o r d s J D B C R M I R M I R M I A n E x p e n s e R e p o r t i n g S y s t e m , f r o m h t t p :/ / ja v a . s u n . c o m
  • 55. 01/30/15 Distributed Computing, M. L. Liu55 To be continued The Java RMI facility is rich in features. This chapter has presented a very basic subset of those features, as an illustration of a distributed object system. Some of the more interesting advanced features of RMI will be presented in the next chapter.
  • 56. 01/30/15 Distributed Computing, M. L. Liu56 Summary - 1  The distributed object paradigm is at a higher level of abstraction than the message-passing paradigm.  Using the paradigm, a process invokes methods of a remote object, passing in data as arguments and receiving a return value with each call, using syntax similar to local method calls.  In a distributed object system, an object server provides a distributed object whose methods can be invoked by an object client.
  • 57. 01/30/15 Distributed Computing, M. L. Liu57 Summary - 2  Each side requires a proxy which interacts with the system’s runtime support to perform the necessary IPC.  an object registry must be available which allow distributed objects to be registered and looked up.  Among the best-known distributed object system protocols are the Java Remote Method Invocation (RMI), the Distributed Component Object, Model (DCOM), the Common Object Request Broker Architecture (CORBA) , and the Simple Object Access Protocol (SOAP).
  • 58. 01/30/15 Distributed Computing, M. L. Liu58 Summary - 3  Java RMI is representative of distributed object systems.  The architecture of the Java Remote Method Invocation API includes three abstract layers on both the client side and the server side.  The software for a RMI application includes a remote interface, server-side software, and client- side software.  What are the tradeoffs between the socket API and the Java RMI API?