Ch4 Communicaton
Ch4 Communicaton
2
Distributed
Layered protocols Systems
3
Distributed
Layered Protocols (1) Systems
4
Distributed
Layered protocol Systems
5
Distributed
Layered Protocols (2) Systems
Every layer adds a header to the front of the message
But some put trailer either
6
Distributed
Low level layers Systems
7
Distributed
Transport Layer Systems
Accordingly, the TCP/IP has merged everything above transport layer into application layer
10
Distributed
2. Middleware Systems
11
Distributed
Middleware Protocols Systems
The session and presentation layer have been replaced by a single middleware layer that contains application-independent protocols.
Supports
Communication protocols, Naming protocols, Security protocols, Scaling mechanisms, such as replication and caching
12
Distributed
Types of Communications Systems
Persistent communication
A message is stored at a communication server as long as it takes to deliver it.
The sending application can exit after submitting
The receiving application does not have to be active
Transient communication-message is stored as long as the sending/receiving is executing
Comm. server discards message when it cannot be delivered at the next server, or at the receiver.
Asynchronous communication
Sender continues immediately after submitting a message
Synchronous communication
Sender will wait until it is certain that the message is received
13
Distributed
Communication in Client/Server Systems
14
Distributed
Message-oriented middleware(MoM) Systems
15
Distributed
Remote procedure call Systems
Conclusion
Communication between caller & callee can be hidden by using procedure-call
mechanism. 16
Distributed
RPC between Client and Server Systems
18
Distributed
RPC Steps Systems
1) The client procedure calls the client stub in the normal way.
2) The client stub builds a message and calls the local OS.
3) The client’s OS sends the message to the remote OS.
4) The remote OS gives the message to the server stub.
5) The server stub unpacks the parameters and calls the server.
6) The server does the work and returns the result to the stub.
7) The server stub packs it in a message and calls its local OS.
8) The server’s OS sends the message to the client’s OS.
9) The client’s OS gives the message to the client stub.
10) The stub unpacks the result and returns to the client.
19
Case Study:
Remote Method Invocation (RMI)
Distributed
“The network is the computer” Systems
method call
SomeClass AnotherClass
returned object
computer 1 computer 2
If the network is the computer, we ought to be able to put the two classes on different
computers
21
Distributed
RMI and other technologies Systems
CORBA (Common Object Request Broker Architecture) has long been king
for RPC.
CORBA supports object transmission between virtually any languages
Objects have to be described in IDL (Interface Definition Language), which looks a l
ot like C++ data definitions
CORBA is complex and flaky
Microsoft supported CORBA, then COM, now .NET
RMI is purely Java-specific
Java to Java communications only
As a result, RMI is much simpler than CORBA
22
Distributed
What is needed for RMI Systems
Java makes RMI (Remote Method Invocation) fairly easy, but there are some ex
tra steps
To send a message to a remote “server object,”
The “client object” has to find the object
Do this by looking it up in a registry
The client object then has to marshal the parameters (prepare them for trans-
mission)
Java requires Serializable parameters
The server object has to unmarshal its parameters, do its computation, and marshal its response
The client object has to unmarshal the response
Much of this is done for you by special software implemented as part of
rmi package
23
Distributed
Terminology Systems
RMI requires
For RMI, you need to be running two processes
The Client
The Server
You also need TCP/IP active
24
Distributed
Interfaces Systems
Therefore,
In order to use a remote object, the client must know its behavior (interface), but
does not need to know its implementation (class)
In order to provide an object, the server must know both its interface (behavior)
and its class (implementation)
In short,
The interface must be available to both client and server processes
The class should only be on the server
25
Distributed
Classes Systems
26
Distributed
Conditions for serializability Systems
If an object is to be serialized:
The class must be declared as public
The class must implement Serializable
The class must have a no-argument constructor
All fields of the class must be serializable: either primitive types or
serializable objects
27
Distributed
Remote interfaces and class Systems
28
Distributed
The server class Systems
The server class needs to register its server object on the registry:
Registry reg= LocateRegistry.createRegistry(port);
reg.rebind(“HelloServer”, new Hello());
Note:
• We can use unused port The default port is 1099
• “HelloServer” is just a name we use to refer to the remote object from the client
The above code snippet requires the following:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
30
Distributed
Hello world server: interface Systems
• Step 1: Create interface class that imports java.rmi.*; and extends the Remot
e class
import java.rmi.*;
31
Distributed
Interface implementation: class Systems
Step 2: Create class that implements the interface defined in prevous step and extends
UnicastRemoteObject
import java.rmi.*;
import java.rmi.server.*;
Step 3: Create server class that register an instance of implementation classs defined in the prevous step.
class HelloServer {
public static void main (String[] argv) {
try {
Registry reg= LocateRegistry.createRegistry(5555);
reg.rebind(“HelloServer”, new Hello());
System.out.println("Hello Server is ready.");
}
catch (Exception e) {
System.out.println("Hello Server failed: " + e);
}
}
}
33
Distributed
The hello world client program Systems
Step 4: Create client program that consumes services provided by the server
class HelloClient {
public static void main (String[] args) {
HelloInterface hello;
try {
Registry r= LocateRegistry.getRegistry(“localhost”,5555);
hello = (HelloInterface)r.lookup(HelloServer);
System.out.println(hello.say(“Mulugeta”));
}
catch (Exception e) {
System.out.println("HelloClient exception: " + e);
}
}
}
34
Distributed
Trying RMI Systems
35
Distributed
Summary Systems
36
Distributed
References Systems
Trail: RMI
by Ann Wollrath and Jim Waldo
http://java.sun.com/docs/books/tutorial/rmi/index.html
38