Communication in Distributed System
Communication in Distributed System
Chapter 2
COMMUNICATION
Contents
Vinaya Sawant 1
Chapter 2
3
Inter Process Communication
4
Message Passing v/s Shared Memory
Vinaya Sawant 2
Chapter 2
5
Message passing v/s Shared Memory Contd.
REMOTE PROCEDURE
Communication CALL (RPC)
Vinaya Sawant 3
Chapter 2
7
Introduction
• Middleware
Vinaya Sawant 4
Chapter 2
10
Basic RPC Model
11
Vinaya Sawant 5
Chapter 2
12
Steps of RPC
13
Elements of RPC Implementation
To achieve transparency
Client
Client stub
RPC Runtime
Server stub
Server
Vinaya Sawant 6
Chapter 2
14
RPC Components
RPC Execution 15
Vinaya Sawant 7
Chapter 2
16
Stub Generation
Manual generation
17
RPC Compilation
Vinaya Sawant 8
Chapter 2
18
RPC Implementation
RPC messages
Call / Request
Reply
19
RPC Call/ Request Message Format
Vinaya Sawant 9
Chapter 2
21
RPC Reply Message Format
22
Parameter Passing Semantics
Vinaya Sawant 10
Chapter 2
23
Call-by-value Semantic: Example
24
Byte Ordering
Vinaya Sawant 11
Chapter 2
28
Asynchronous RPC
29
Vinaya Sawant 12
Chapter 2
30
Advantages of RPC
33
Vinaya Sawant 13
Chapter 2
34
1. IDL File
syntax:
program <program_name> {
version <version_name> {
return_type function_name(arguments) = 1;
} = 1;
} = 700001;
program SUMPROG {
version SUMVERS {
int sum(int, int) =1;
} =1;
}=377;
35
2. Stub and skeleton
Vinaya Sawant 14
Chapter 2
36
3. Server and Client Applications
37
3. Server and Client Applications Contd.
Client Code
Create Interface
Add actionPerformed()
private void jButtonActionPerformed(java.awt.event.ActionEvent evt)
{
sum myClient = null;
try {
String server = JTextField1.getText ();
InetAddress addr = InetAddress.getByName (server);
myClient = new sum(addr, false);
//call the sum function
}
catch (Exception ex)
{
System.err.println ("Unable to make client call");
return;
}
}
Vinaya Sawant 15
Chapter 2
38
4. Run the Application
39
4. Run the Application Contd.
Vinaya Sawant 16
Chapter 2
40
4. Run the Application Contd.
41
RPC Practical Assignments
Sum
Sum of all numbers between range given
GCD and LCM
POWER
Area of rectangle
Largest of two
Prime
Factorial
Armstrong
Area of Circle
Reverse
Vinaya Sawant 17
Chapter 2
42
Vinaya Sawant 18
Chapter 2
45
Vinaya Sawant 19
Chapter 2
RMI Implementation
Vinaya Sawant 20
Chapter 2
51
Architecture of RMI
52
RMI mechanism
Vinaya Sawant 21
Chapter 2
Components of RMI
RMI Execution
Vinaya Sawant 22
Chapter 2
57
Remote Method Invocation: Steps
Types of Objects
Vinaya Sawant 23
Chapter 2
Java RMI
Case Study
Vinaya Sawant 24
Chapter 2
65
Advantages
68
RMI Application: Components
Vinaya Sawant 25
Chapter 2
69
Steps for Developing RMI Application
71
Remote interface: requirements
Must be public
Must extend java.rmi.Remote
All Methods
Exception: java.rmi.RemoteException
May extend another interface
Vinaya Sawant 26
Chapter 2
72
Extending from non-remote interface in RMI
public interface A {
public A_method() throws
java.io.RemoteException;
}
73
RemoteException class
Failure in communication
Failure while marshalling / unmarshalling parameters
Vinaya Sawant 27
Chapter 2
74
RMI bank interface
75
RemoteObject class and subclasses
UnicastRemoteObject:
Used for exporting a remote object with JRMP and obtaining a stub that
communicates to the remote object.
methods to create remote objects and export them
Vinaya Sawant 28
Chapter 2
77
Steps for Developing RMI Application
78
Step 1: Write and compile Java code for
interfaces
public interface Calculator extends java.rmi.Remote {
public long add (long a, long b)
throws java.rmi.RemoteException;
Vinaya Sawant 29
Chapter 2
Step 2: contd.. 80
Vinaya Sawant 30
Chapter 2
81
Step 3: Generate Stub and Skeleton class files from the
implementation class
rmic CalculatorImpl
82
Step 4: Write remote service host program: Server
The server must bind its name to the registry, the client will look
up the server name.
Use java.rmi.Naming class to bind the server name to registry.
In this example the name “CalculatorService”.
Vinaya Sawant 31
Chapter 2
83
Step 4: contd..
import java.rmi.Naming;
public class CalculatorServer {
public CalculatorServer() {
try {
Calculator c = new CalculatorImpl();
Naming.rebind("rmi://localhost:1099//CalculatorService", c);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
public static void main(String args[]) {
new CalculatorServer();
}
}
84
Step 5: Develop the client program
Lookup in registry
Vinaya Sawant 32
Chapter 2
85
Step 5: contd..
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
86
Step 6: Start the RMI registry and run
application
start rmiregistry
Run server
Run client
Vinaya Sawant 33
Chapter 2
87
Message
Passing
88
Introduction to Message Passing
Vinaya Sawant 34
Chapter 2
89
Message Passing v/s Shared Memory
91
Advantages and Disadvantages
of Message Passing
Hardware Match
Functionality
Performance: data locality
Responsibility of Programmer
Vinaya Sawant 35
Chapter 2
92
Features of Message Passing
Desirable Features
Uniform Semantics
Efficiency
Reliability
Correctness
Flexibility
Portability
Security
93
Message Passing Operation / Process
Vinaya Sawant 36
Chapter 2
94
Components of an IPC Message
96
IPC Message Format Contd
Vinaya Sawant 37
Chapter 2
Vinaya Sawant 38
Chapter 2
106
Message Buffering Strategies
Vinaya Sawant 39
Chapter 2
Null Buffering
Vinaya Sawant 40
Chapter 2
Single-message buffering
Vinaya Sawant 41
Chapter 2
Receiver overflow
handled using
Unsuccessful
communication
indication
Flow
control
mechanism
Multidatagram Messaging
Concept of MTU
Message sequencing and reassembly
Message contents
Message representation: tagged, untagged
Vinaya Sawant 42
Chapter 2
Group Communication
Unicast –one to one communication
Many-to-one group communication
One-to-many or multicast group communication
Vinaya Sawant 43
Chapter 2
Many-to-One Communication
Vinaya Sawant 44
Chapter 2
Multicast Communication
Broadcast
Communication
Types of Groups
Closed group
Open group
Peer group
Hierarchical group
Vinaya Sawant 45
Chapter 2
Group Management
Centralized approach
Distributed approach
Vinaya Sawant 46
Chapter 2
Reliability Mechanism
Classified based on number of receivers from which
sender expects a response
Message Ordering
Vinaya Sawant 47
Chapter 2
Vinaya Sawant 48
Chapter 2
Communication
MESSAGE-ORIENTED COMMUNICATION
Vinaya Sawant 49
Chapter 2
137
Message Oriented Communication
138
Persistence and Synchronicity in
Communication
Vinaya Sawant 50
Chapter 2
139
Persistent Communication
Persistent communication
Messages are stored until communication with next receiver is
possible
Examples: email, pony express
140
Transient Communication
Vinaya Sawant 51
Chapter 2
141
Synchronicity
Different forms of
142
Communication
Persistent
Transient
Asynchronous
Synchronous
Vinaya Sawant 52
Chapter 2
143
Combinations
Persistent Asynchronous
Persistent Synchronous
Transient Asynchronous
Transient Synchronous
Receipt-based
Delivery-based
Response-based
Different forms of
144
Communication
Neepa Shah
Vinaya Sawant 53
Chapter 2
Communication
Vinaya Sawant 54
Chapter 2
147
Message-oriented Persistent
Communication
Message queuing systems
Support asynchronous persistent communication
Intermediate storage for message while sender/receiver are
inactive
Example application: email
Communicate by inserting messages in queues
Sender is only guaranteed that message will be eventually
inserted in recipient’s queue – No guarantees on when or if the
message will be read – “Loosely coupled communication”
148
Message-oriented Persistent
Communication
Message-Queuing Model
Vinaya Sawant 55
Chapter 2
MQS
150
Requirements
Source and destination queue
Queue names
Mapping of queues to network locations
Queue manager
Relays
Vinaya Sawant 56
Chapter 2
151
Relationship between queue-level
addressing and network-level addressing
152
Message-oriented Persistent
Communication
General message-queuing systems vs. e-mail
E-mail aims at providing direct support for the end users (this is
why groupware is often based on e-mail systems)
General purpose message-queuing systems are set up to
enable persistent based communication between all kinds of
processes. Therefore they should also provide:
Guaranteed message delivery;
Message priorities;
Logging facilities;
Efficient multicasting;
Load balancing;
Fault tolerance;
• E.g.: IBM MQSeries
Vinaya Sawant 57
Chapter 2
153
General Architecture of a MQS
(Cont’d)
154
General Architecture of a MQS
(Cont’d)
Message Brokers..gateway
Vinaya Sawant 58