0% found this document useful (0 votes)
16 views75 pages

Chapter 2

Uploaded by

amsaluestifanoos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views75 pages

Chapter 2

Uploaded by

amsaluestifanoos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

FUNDAMENTALS OF DISTRIBUTED SYSTEM

Chapter Two
Inter process communication

1
OUTLINE
ф Inter Process Communication: Introduction:
 The API for the Internet Protocols,
 External Data Representation and Marshalling,
 Client-Server Communication, Group Communication,
 Case Study: IPC in UNIX.
 Communication between Distributed Objects,

 Remote Procedure Call, Events and Notifications

2
INTRODUCTION
 Inter-Process Communication (IPC) is a mechanism that allows processes to
communicate with each other and synchronize their actions.
 The communication between these processes can be seen as a method of co-operation
between them.
 Inter process communication is at the heart of distributed computing.
 It makes no sense to study distributed systems without carefully examining the ways
that processes on different machines can exchange information.
 We separate inter process communication into two parts:
1. Networking
2. User views

3
INTRODUCTION…
 Networking: This deals with how processes communicate with one another via the various
protocol layers.
 The important issues in networking are routing, error control, flow control, authentication, etc.
This is the internal view.
 Users’ view: User processes have an abstract high-level view of the inter process communication
medium. This is the external view.
 User processes run on host machines that are connected to one another through a network, and
the network carries signals that propagate from one process to another. These signals represent
data.
 The processes may communicate across a LAN, or through the Internet, or a combination of
these, or via shared (virtual) address space.
 Distributed systems use the client–server model. A few systems also adopt the P2P model of
inter process communication, where there is no difference between servers and clients.
 User interfaces rely on programming tools available to a client for communicating with a server

4
INTER PROCESS COMMUNICATION (IPC)
 A process is a program in execution.
 A process can be executed in operating system into two types:
 Independent process.
 Co-operating process.
 A independent process is not affected by the execution of other processes, which
are running independently, will execute very efficiently.
 A co-operating process can be affected by other executing processes.
 Any process that shares data with other processes is co-operating process.
 co-operating process require IPC that allow them to exchange data and
information.

5
MODELS OF IPC

 There are two fundamental models of IPC


1.Shared Memory
2.Message passing
 In Shared Memory, a region of memory
that is shared by co-operating processes is
established. Processes can the exchange
information by reading and writing data to
the shared region.
 In message passing model, a
communication takes place by means of
message exchange between co-operating
processes.
 The communication through message
passing is harder than using primitive
based memory shared. Shared Message Passing
memory

6
WHY IPC
 Information Sharing
 Resource Sharing
 Increasing Computational Speed
 Convenience,
 Synchronization
 Modularity.

7
APPLICATION PROGRAM INTERFACE (API) FOR
INTERNET PROTOCOLS

is a programming interface between application programs and communication subsystems


based on open network protocols.
 The API lets any application program operating in its own Multiple Virtual Storage MVS
address space to access and use communication services provided by an MVS subsystem that
implements this interface.
 TCP access, which provides communication services using TCP/IP protocols, is an example of
such a subsystem.
 This programmer's reference describes an interface to the transport layer of the Basic Reference
Model of Open Systems Interconnection (OSI).
 Although the API is capable of interfacing to proprietary protocols, the Internet open network
protocols are the intended providers of the transport service.
 This document uses the term "open" to emphasize that any system conforming to one of these
standards can communicate with any other system conforming to the same standard, regardless
of vendor.

8
CHARACTERISTICS OF INTERCOMMUNICATION

 Message passing between a pair of processes can be supported by


two message communication operations, send and receive,
defined in terms of destinations and messages.
 To communicate, one process sends a message (a sequence of
bytes) to a destination and another process at the destination
receives the message.
 Sending processes cause messages to be added to remote queues
and receiving processes remove messages from local queues.
 Communication between the sending and receiving processes
may be either synchronous or asynchronous.
9
Characteristics of intercommunication

 Characteristics of IPC
 Synchronous and asynchronous communication
 In the synchronous form of communication, the sending and receiving
processes synchronize at every message.
 In this case, both send and receive are blocking operations.
 Blocking send has the sender block until the message is received.
 Blocking receive has the receiver block until a message is available

10
CHARACTERISTICS OF INTERCOMMUNICATION

 In the asynchronous form of communication, the use of the


send operation is non blocking in that the sending process is
allowed to proceed as soon as the message has been copied to
a local buffer, and the transmission of the message proceeds in
parallel with the sending process.
 The receive operation can have blocking and non-blocking
variants.
 Non blocking is considered asynchronous
 Non blocking send has the sender send the message and continue
 Non blocking receive has the receiver receive a valid message or
null
11
Characteristics of intercommunication

 Message destinations
 The messages in the Internet protocols, messages are sent to (Internet address,
local port) pairs.
 A local port is a message destination within a computer, specified as an integer.
 A port has exactly one receiver but can have many senders.
 Processes may use multiple ports to receive messages.
 Any process that knows the number of a port can send a message to it.
 Client programs refer to services by name and use a name server or binder to
translate their names into server locations at runtime.
 This allows services to be relocated but not to migrate – that is, to be moved
while the system is running.

12
Characteristics of intercommunication

 Reliability
 A point-to-point message service can be described as reliable if messages are
guaranteed to be delivered.
 A point-to-point message service can be described as unreliable if messages are
not guaranteed to be delivered in the face of even a single packet dropped or
lost.
 Ordering
 Some applications require that messages be delivered in the order in which
they were transmitted by the sender.
 The delivery of messages out of sender order is regarded as a failure by such
applications.

13
EXTERNAL DATA REPRESENTATION

 Data structures are used to represent the information held in running applications.
 The information consists of a sequence of bytes in messages that are moving between
components in a distributed system.
 So, conversion is required from the data structure to a sequence of bytes before the transmission
of data.
 On the arrival of the message, data should also be able to be converted back into its original data
structure.
 Different types of data are handled in computers, and these types are not the same in every
position where data must be transmitted.
 Individual primitive data items can have a variety of data values, and not all computers store
primitive values like integers in the same order.

14
EXTERNAL DATA REPRESENTATION & MARSHALING…

 Different architectures also represent floating-point numbers differently.


 Integers are ordered in two ways, big-endian order, in which the Most
Significant Byte (MSB) is placed first, and little-endian order, in which the
Most Significant Byte (MSB) is placed last or the Least Significant Byte
(LSB) is placed first.
 Most applications on UNIX systems use ASCII character coding, which uses
one byte per character, whereas the Unicode standard uses two bytes per
character and allows for the representation of texts in many different
languages.
 There should be a means to convert all of this data to a standard format so
that it can be sent successfully between computers.

15
EXTERNAL DATA REPRESENTATION
 If the two computers are known to be of the same type, the external format
conversion can be skipped otherwise before transmission, the values are
converted to an agreed-upon external format, which is then converted to
the local format on receiving.
 For that, values are sent in the sender’s format, along with a description of
the format, and the recipient converts them if necessary. It’s worth noting,
though, that bytes are never changed during transmission.
 Any data type that can be supplied as a parameter or returned, as a result,
must be able to be converted and the individual primitive data values
expressed in an accepted format to support Remote Procedure Call (RPC)
or Remote Method Invocation (RMI) mechanisms.
 External Data Representation is a standard for representing data structures
16
and primitive values that have been agreed upon.
MARSHALLING
 Marshalling: is the process of transferring and formatting a
collection of data structures into an external data
representation type appropriate for transmission in a message.
( write or transmit).
 Unmarshalling: The converse of this process is
unmarshalling, which involves reformatting the transferred
data upon arrival to recreate the original data structures at the
destination.(read)
 Approaches of data representation
 There are three ways to successfully communicate between
various sorts of data between computers.1. Common Object
Request Broker Architecture (CORBA), 2. Java’s Object
Serialization, 3. Extensible Markup Language (XML): 17
COMMON OBJECT REQUEST BROKER ARCHITECTURE
(CORBA)
 CORBA is a specification defined by the Object Management
Group (OMG) that is currently the most widely used
middleware in most distributed systems.
 It allows systems with diverse architectures, operating
systems, programming languages, and computer hardware to
work together.
 It allows software applications and their objects to
communicate with one another.
 It is a standard for creating and using distributed objects. It is
made up of five major components.
 Components and their function are given below:
18
COMMON OBJECT REQUEST BROKER ARCHITECTURE
(CORBA)
 Object Request Broker (ORB): It provides a communication
infrastructure for the objects to communicate across a network.
 Interface Definition Language (IDL): It is a specification language used
to provide an interface in a software component.
 To exemplify, it allows communication between software components written
in C++ and Java.
 Dynamic Invocation Interface (DII): Using DII, client applications are
permitted to use server objects without even knowing their types at
compile time.
 Here client obtains an instance of a CORBA object and then invocation
requests can be made dynamically on the corresponding object.
 Interface Repository (IR): As the name implies, interfaces can be added
to the interface repository.
 The purpose of IR is that a client should be able to find an object which is not
known at compile-time and information about its interface then request is
made to be sent to ORB.
 Object Adapter (OA): It is used to access ORB services like object 19
reference generation.
COMMON OBJECT REQUEST BROKER ARCHITECTURE
(CORBA)

20
COMMON OBJECT REQUEST BROKER ARCHITECTURE
(CORBA)
 Data Representation in CORBA:
 Common Data Representation (CDR) is used to describe
structured or primitive data types that are supplied as
arguments or results during remote invocations on CORBA
distributed objects.
 It allows clients and servers’ built-in computer languages to
communicate with one another. To exemplify, it converts
little-endian to big-endian.
 Primitive types are: short (16-bit), long (32-bit), unsigned
short, unsigned long, float (32-bit), double (64-bit), char,
boolean (TRUE, FALSE), octet (8-bit), and any (which can
represent any basic or constructed type), as well as a variety
of composite types. 21
COMMON OBJECT REQUEST BROKER ARCHITECTURE
(CORBA)
 CORBA CDR Constructed Types:
 Let’s have a look at Types with their representation:
 sequence: It refers to length (unsigned long) to be followed by elements in order
 string: It refers to length (unsigned long) followed by characters in order (can also
have wide characters)
 array: The elements of the array follow order and length is fixed so not specified.
 struct: in the order of declaration of components
 enumerated: It is unsigned long and here, the values are specified by the order
declared.
 union: type tag followed by the selected member

22

Common Object Request Broker Architecture (CORBA)

 Example
struct Person {
string name;
string place;
long year;
};
 Marshalling CORBA: From the specification of the categories of data items to be
transmitted in a message, Marshalling CORBA operations can be produced
automatically.
 CORBA IDL describes the types of data structures and fundamental data items and
provides a language/notation for specifying the types of arguments and results of
RMI methods.

23
JAVA’S OBJECT SERIALIZATION

 Java Remote Method Invocation (RMI) allows you to pass both objects and primitive
data values ​as arguments and method calls.
 In Java, the term serialization refers to the activity of putting an object (an instance of a
class) or a set of related objects into a serial format suitable for saving to disk or
sending in a message.
 Java provides a mechanism called object serialization.
 This allows an object to be represented as a sequence of bytes containing information
about the object’s data and the type of object and the type of data stored in the object.
 After the serialized object is written to the file, it can be read from the file and
deserialized. You can recreate an object in memory with type information and bytes that
represent the object and its data.

24
JAVA’S OBJECT SERIALIZATION

25

Java’s Object Serialization
 Moreover, objects can be serialized on one platform and deserialized on completely different platforms as
the whole process is JVM independent.
 For example, the Java class equivalent to the Person struct defined in CORBA IDL might be:
import java.io.*;
public class Person implements Serializable {

public String name;


public String place;
public int phonenumber;
public void letter() {
System.out.println("Issue a letter to " + name + " " + place);
}
}

26
EXTENSIBLE MARKUP LANGUAGE (XML)
 Clients communicate with web services using XML, which is
also used to define the interfaces and other aspects of web
services.
 However, XML is utilized in a variety of different
applications, including archiving and retrieval systems; while
an XML archive is larger than a binary archive, it has the
advantage of being readable on any machine.
 Other XML applications include the design of user interfaces
and the encoding of operating system configuration files.
 Clients, for example, typically interface with web servers via
Simple Object Access Protocol SOAP messages.
 SOAP is an XML standard with tags that web services and
27
their customers can utiliz
EXTENSIBLE MARKUP LANGUAGE (XML)…
Example
XML definition of the Person struct:
<person id="9865">
<name>John</name>
<place>England</place>
<year>1876</year>
<!-- comment -->
</person>

28
EXTENSIBLE MARKUP LANGUAGE (XML)…
 To transmit data across COM object boundaries, the Microsoft
Component Object Model (COM) interface pointers employ
marshalling.
 When a common-language-runtime-based type has to connect
with other unmanaged types via marshalling, the same thing
happens in the.NET framework.
 DCOM stands for Distributed Component Object Model.

29
EXTENSIBLE MARKUP LANGUAGE (XML)…
 Scripts and applications based on the Cross-Platform Component Object
Model (XPCOM) technology are two further examples where marshalling is
crucial.
 The Mozilla Application Framework makes heavy use of XPCOM, which
makes considerable use of marshalling.
 So, XML (Extensible Markup Language) is a text-based format for expressing
structured data. It was designed to represent data sent in messages exchanged
by clients and servers in web services
 The primitive data types are marshalled into a binary form in the first two
ways- CORBA and Java’s object serialization.
 The primitive data types are expressed textually in the third technique (XML).
A data value’s textual representation will typically be longer than its binary
representation. The HTTP protocol is another example of the textual approach.
 On the other hand, type information is included in both Java serialization and
XML, but in distinct ways.
 Although Java serializes all of the essential type information, XML documents
can refer to namespaces, which are externally specified groups of names (with 30
types).
SOCKETS
 Both forms of communication (UDP and TCP) use the socket
abstraction, which provides an endpoint for communication
between processes.
 Sockets originate from BSD UNIX but are also present in most
other versions of UNIX, including Linux as well as Windows and
the Macintosh OS.
 Interprocess communication consists of transmitting a message
between a socket in one process and a socket in another process, as
illustrated fig socket port
 For a process to receive messages, its socket must be bound to a
local port and one of the Internet addresses of the computer on
which it runs.
 Messages sent to a particular Internet address and port number can
be received only by a process whose socket is associated with that
Internet address and port number.
31
SOCKETS…

Fig. Sockets and ports

For a process to receive messages, its socket must be bound to a local port and one of
the Internet addresses of the computer on which it runs. Messages sent to a particular
Internet address and port number can be received only by a process whose socket is
associated with that Internet address and port number.
32
SOCKETS
 A socket is one endpoint of a two-way communication link between two
programs running on the network.
 Interprocess communication consists of transmitting a message between a

socket in one process and a socket in another process.


 The java API for interprocess communication in the internet provides both

datagram and stream communication. Both forms of communication, UDP


and TCP, use the socket abstraction, which provides and endpoint for
communication between processes.
 Interprocess communication consists of transmitting a message between a

socket in one process and a socket in another process.


The two communication patterns that are most used in distributed
programs:
 Client-Server communication: The request and reply messages provide the

basis for remote method invocation (RMI) or remote procedure call (RPC).
33
 Group communication: The same message is sent to several processes.
GROUP COMMUNICATION

 What is a group?
 A number of processes which cooperate to provide a service.
 An abstract identity to name a collection of processes.
 Group Communication: For coordination among processes of
a group.
 Who Needs Group Communication?
 Highly available servers (client-server)
 Database Replication
 Multimedia Conferencing
 Online Games
 Cluster management
34
CLIENT SERVER COMMUNICATION

 Client and server communication take place when both are


connected to each other via a network.
 Client and the server are two individual computing systems having
their own operating system, applications and functions.
 When connected via a network they are able to share their
applications with each other.
 It is not necessary that client and server use a same platform as
operating system, many varied operating systems can be connected
with each other for advanced communication using communication
protocol.
 The responsibility of implementing the communication protocol lies
with an application known as communication software.
35
CLIENT SERVER COMMUNICATION…

 The between client and server can


be explained as follows:
 Data resides in the server.
 Client system sends a query to the server
 Server searches the data for the information to be exchanged
 Server sends the requested data in the form of final result

36
JAVA API FOR INTERNET ADDRESSES
 UDP Datagram Communication
 The application program interface to UDP provides a message passing abstraction.
 Message passing is the simplest form of interprocess communication.
 API enables a sending process to transmit a single message to a receiving process.
 The independent packets containing theses messages are called datagrams.
 In the Java and UNIX APIs, the sender specifies the destination using a socket.
 A datagram is transmitted between processes when one process sends it and another receives
it.
 The following are the steps in socket communication:
 Creating a socket
 Binding a socket to a port and local Internet address
 A client binds to any free local port
 A server binds to a server port
 Receive() returns Internet address and port of sender, along with the message. 37
JAVA API FOR INTERNET ADDRESSES

 Issues in datagram communication:


 Message size:
 The receiving process needs to specify an fixed size array to receive a
message.
 If the message is too big for the array, it is truncated.
 Any application requiring messages larger than the maximum must
fragment them.

38
JAVA API FOR INTERNET ADDRESSES
 Blocking :
 Sockets normally provide non-blocking sends and blocking receives for datagram communication.
 The send() returns after delivering the message to the UDP and IP protocols. These protocols are now
responsible for transmitting the message to its destination
 The message is placed in a queue for the socket that is bound to the destination port.
 Messages are discarded at the destination if no process has a socket bound to the destination port.
 The receive()blocks until a datagram is received, unless a timeout has been set on the socket.
 Timeouts:
 The receive() cannot wait indefinitely. This situation occurs when the sending process may have crashed
or the expected message may have been lost.
 To avoid this timeouts can be set on sockets.
 The timeouts must be much larger than the time required to transmit a message.

39
JAVA API FOR INTERNET ADDRESSES

 Receive from any:


 The receive() does not specify an origin for messages. This
can get datagrams addressed to its socket from any origin.
 The receive() returns the Internet address and local port of the
sender, allowing the recipient to check where the message
came from.
 It is possible to connect a datagram socket to a particular
remote port and Internet address, in which case the socket is
only able to send messages to and receive messages from that
address.
40
JAVA API FOR INTERNET ADDRESSES

 Failure model for UDP datagrams suffer from following


failures:
 Omission failure: Messages may be dropped occasionally
 Ordering: Messages can be delivered out of order.

41
JAVA API FOR UDP DATAGRAMS
 The Java API provides datagram communication by two classes:
1. DatagramPacket
 It provides a constructor to make an array of bytes comprising:

 Message content
 Length of message
 Internet address
 Local port number - It provides another similar constructor for
receiving a message.

42
JAVA API FOR INTERNET ADDRESSES
2. DatagramSocket:
 This class supports sockets for sending and receiving UDP

datagram.
 It provides a constructor with port number as argument.

 No-argument constructor is used to choose a free local port.

43
 DatagramSocket methods are:
1. send and receive: These methods are used for transmitting
 datagrams between a pair of sockets.

 Syntax:

 send(packet);
 receive();
2. setSoTimeout: This method allows a timeout to be set. With a timeout set, the
receive method will block for the time specified and then throw an
InterruptedIOException.
 Syntax:

 setSotimeout(time in seconds);
3. connect: This method is used for connecting to a particular remote port and
Internet address, in which case the socket is only able to send messages to and
receive messages from that address.
Syntax: int connect(in sockfd, const structsockaddr *addr, socklen_taddrlen);

44
Arrays of bytes Message length Internet address Port number
containing message
UDP Client server Server program
Communication Datagram Packet import java.net.*;
Client Program
import java.net.*; import java.io.*;
public class UDPServer
import java.io.*; {
public class UDPClient public static void main(String args[])
{ {
public static void main(String args[]) DatagramSocketaSocket = null;
try
{ {
DatagramSocketaSocket = null; aSocket = new DatagramSocket(6789);
try { byte[] buffer = new byte[1000];
aSocket = new DatagramSocket(); // Create an object for the while(true)
{
datagram class DatagramPacket request = new DatagramPacket(buffer, buffer.length);
byte [] m = args[0].getBytes(); //Buffer to get data aSocket.receive(request);
InetAddressaHost = InetAddress.getByName(args[1]); // Get DatagramPacket reply = new DatagramPacket(request.getData(),
Inetaddress request.getLength(), request.getAddress(), request.getPort());
aSocket.send(reply);
intserverPort = 6789; }
DatagramPacket request = }
new DatagramPacket(m, m.length(), aHost, serverPort); catch (SocketException e)
aSocket.send(request); //Sent the packet {
System.out.println("Socket: " + e.getMessage());
byte[] buffer = new byte[1000]; }
DatagramPacket reply = new DatagramPacket(buffer, catch (IOException e)
buffer.length); {
aSocket.receive(reply); System.out.println("IO: " + e.getMessage());
}
System.out.println("Reply: " + new String(reply.getData())); finally
} {
catch (SocketException e){System.out.println("Socket: " + if (aSocket != null) aSocket.close();}
e.getMessage()); }
}
}
catch (IOException e){System.out.println("IO: " + e.getMessage()); 45
}
finally { if(aSocket != null) aSocket.close();} } }
TCP STREAM COMMUNICATION
 The API to the TCP protocol provides the abstraction of a stream of bytes to
be written to or read from.
 The following features are hidden stream abstraction:
 Message sizes
 Lost messages
 Flow control
 Message destinations

46
WORKING OF STREAM COMMUNICATION

 The pair of sockets in the client and server are connected by a pair of streams, one in each
direction. Thus each socket has an input stream and an output stream.
 One of the pair of processes can send information to the other by writing to its output stream,
and the other process obtains the information by reading from its input stream.
 When an application closes a socket, this indicates that it will not write any more data to its
output stream. Any data in the output buffer is flushed to the other end of the stream and put
in the queue at the destination socket, with an indication that the socket is closed.
 The process at the destination can read the data in the queue, but any further reads after the
queue is empty will result in an indication of end of stream.
 When a process exits or fails, all of its sockets are eventually closed and any process
attempting to communicate with it will discover that its connection has been broken.

47
This form of stream communication has the following issues:
 Matching of data items: Two communicating processes need to

agree as to the contents of the data transmitted over a stream.


 Blocking: The process that writes data to a stream may be blocked

by the TCP flow-control mechanism if the socket at the other end


is queuing as much data as the protocol allows.
 Threads: When a server accepts a connection, it generally creates

a new thread in which to communicate with the new client. In an


environment in which threads are not provided, an alternative is
to test whether input is available from a stream before attempting
to read it;

48
 Java API for TCP streams
 The Java interface to TCP streams is provided in the classes:
 ServerSocket: It is used by a server to create a socket at server
port to listen for connect requests from clients.
 Syntax:
 publicServerSocket(int port, InetAddress address) ;
 Socket: It is used by a pair of processes with a connection. The
client uses a constructor to create a socket and connect it to the
remote host and port of a server. It provides methods for
accessing input and output streams associated with a socket.
 Syntax:
 public Socket(InetAddress host, int port, InetAddresslocalAddress, intlocalPort);

49
TCP CLIENT SERVER COMMUNICATION

 import java.net.*; import java.io.*; public class TCPClient { public


static void main (String args[]) { Socket s = null; try { intserverPort =
7896; s = new Socket(args[1], serverPort); DataInputStream in = new
DataInputStream( s.getInputStream()); DataOutputStream out = new
DataOutputStream( s.getOutputStream()); out.writeUTF(args[0]); //
UTF is a string encoding; String data = in.readUTF();
System.out.println("Received: "+ data) ; } catch
(UnknownHostException e) {
System.out.println("Sock:"+e.getMessage()); } catch (EOFException e)
{ System.out.println("EOF:"+e.getMessage()); } catch (IOException e)
{ System.out.println("IO:"+e.getMessage()); } finally { if(s!=null) try {
s.close(); } catch (IOException e) {/*close failed*/ } } } }

50
TCP SERVER
import java.net.*; import java.io.*;
public class TCPServer { public static void main (String args[]) { try{ intserverPort = 7896;
ServerSocketlistenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket =
listenSocket.accept();
Connection c = new Connection(clientSocket); } }
catch(IOException e) {System.out.println("Listen :"+e.getMessage());} } }
class Connection extends Thread { DataInputStream in;
DataOutputStream out; Socket clientSocket;
public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new
DataInputStream( clientSocket.getInputStream());
out =new DataOutputStream( clientSocket.getOutputStream());
this.start(); } catch(IOException e) {System.out.println("Connection:"+e.getMessage());} } public
void run(){ try { // an echo server String data = in.readUTF(); out.writeUTF(data); }
catch(EOFException e) {System.out.println("EOF:"+e.getMessage()); }
catch(IOException e) {System.out.println("IO:"+e.getMessage()); }
finally { try {clientSocket.close();}catch (IOException e){/*close failed*/}} } }

51
CASE STUDY: IPC IN UNIX
 The IPC primitives in BSD 4.x versions of UNIX are provided as system
calls that are implemented as a layer over the Internet TCP and UDP
protocols.
 Message destinations are specified as socket addresses
 a socket address consists of an Internet address and a local port number.
 The inter process communication operations are based on the socket
abstraction.
 messages are queued at the sending socket until the networking protocol has
transmitted them, and until an acknowledgement arrives, if the protocol
requires one.
 When messages arrive, they are queued at the receiving socket until the
receiving process makes an appropriate system call to receive them.

52
CASE STUDY: IPC IN UNIX…
 Any process can create a socket for use in communication with another process.
 This is done by invoking the socket system call, whose arguments specify the
communication domain (normally the Internet), the type (datagram or stream) and
sometimes a particular protocol.
 The protocol (for example, TCP or UDP) is usually selected by the system according to
whether the communication is datagram or stream.

Server Address and Client Address are Socket Address


53
CASE STUDY: IPC IN UNIX…

 The socket call returns a descriptor by which the socket may be referenced in
subsequent system calls. The socket lasts until it is closed or until every process
with the descriptor exits. A pair of sockets may be used for communication in both
or either direction between processes in the same or different computers.

 Before a pair of processes can communicate, the recipient must bind its socket
descriptor to a socket address. The sender must also bind its socket descriptor to a
socket address if it requires a reply. The bind system call is used for this purpose;
its arguments are a socket descriptor and a reference to a structure containing the
socket address to which the socket is to be bound. Once a socket has been bound,
its address cannot be changed.
54
CASE STUDY: IPC IN UNIX…

 It might seem more reasonable to have one system call for both socket creation and
binding a name to a socket, as for example in the Java API. The supposed
advantage of having two separate calls is that sockets can be useful without socket
addresses.

 Socket addresses are public in the sense that they can be used as destinations by
any process. After a process has bound its socket to a socket address, the socket
may be addressed indirectly by another process referring to the appropriate socket
address. Any process, for example a server that plans to receive messages via its
socket, must first bind that socket to a socket address and make the socket address
known to potential clients.
55
COMMUNICATION BETWEEN DISTRIBUTED OBJECTS
 Distributed object communication realizes communication between distributed objects in the
distributed computing environment.
 The main role is to interconnect objects residing in non-local memory space and allow them to
perform remote calls and exchange data. Distributed object middleware offers a programming
abstraction based on object-oriented principles.
description about relation between objects and distributed objects:

56
COMMUNICATION BETWEEN DISTRIBUTED OBJECTS…

Differences between objects and distributed objects

57
COMMUNICATION BETWEEN DISTRIBUTED OBJECTS
 Distributed object is an object accessed by remotely
 This means that distributed object can be used like a regular object,
but from anywhere on the network.
 The object is typically considered to encapsulate data and behavior.
 Distributed object model is a software module that are designed to
work together, but reside either in multiple computers connected via
network or in different computer inside the same computer.
 Distributed object is the states of an object consists of the value of
its instance variable since object based programs are logically
portioned, the physical distribution of objects into different
processes or computers in distributed system.
 Distributed object system may adopt the client server architecture.
 Objects are managed servers and their clients invoke their methods 58
using remote method invocation.
COMMUNICATION BETWEEN DISTRIBUTED OBJECTS
 Communication between distributed objects
 Various middleware language like RMI required to make successful communication
between distributed objects.
 Stub and skeleton objects works as Communication objects in distributed system.
 RMI means remote method invocation. Whenever needed RMI invokes the methods at a
client and server side objects.

Communication between distributed objects

59
COMMUNICATION BETWEEN DISTRIBUTED OBJECTS

 As shown in above diagram, in RMI communication follows


the following steps
 A stub is defined on client side (Machine A)
 Then stub passes caller data over the network to server
skeleton (machine B)
 The skeleton then passes received data to the called object
 Skeleton waits for a response and returns the result to the
client stub (Machine A)

60
REMOTE METHOD INVOCATION
 Remote Method Invocation (RMI) is an API that provides a
mechanism to create distributed application in java
 The RMI allows an object to invoke methods on an object
running in another Java virtual machine JVM.
 RMI provides a remote communication between the
applications using two objects stub and skeleton.
 Understanding stub and skeleton
 RMI uses stub and skeleton object for communication with
remote object
 A remote object is an object whose method can be invoked
from another JVM 61
REMOTE PROCEDURE CALL
 Remote Procedure Call (RPC) is a protocol that one program can
use to request a service from a program located in another computer
in a network without having to understand network details.
 Remote Procedure Call RPC is an intercrosses communication
technique.
 It is used for client-server applications
 RPC mechanisms are used when a computer program cause a
procedure or subroutine to execute in different address space, which
is coded as normal procedure call without the programmer
specifically coding the details for remote interaction
 This procedure call manages low level transport protocol like UDP
or TCP
62
 It is used for carrying the message data between programs.
REMOTE PROCEDURE CALL SEMANTICS

63
REMOTE PROCEDURE CALL
 Is a special case of the general message-passing model of IPC.
 Providing the programmers with familiar a mechanism for
building distributed system is one of primary motivations for
developing the RPC facility.
 While RPC facility is not a universal panacea for all types of
distributed application, it does provide a valuable
communication mechanism that is suitable for building a
failrly large nmbers of distributed applications
 The popularity of RPC as the primary mechanism for
distributed application is due to the following features:
64
REMOTE PROCEDURE CALL
1. Simple call syntax
2. Familiar semantics (b/ce similar to local procedure call)
3. its specified a well-defined interface. This property is used
to support compile time type checking and automated
interface generation
4. Its easy of use . The clean and simple semantics of a
procedure call makes it easier to build a distributed
computational and to get them right.
5. Its efficiency. Procedure call are simple enough for
communication to be quite rapid
6. It can be used as an IPC mechanism to communicate
between proceses on different machines as well as between
65
different proceses on the same machine,
IMPLEMENTING REMOTE PROCEDURE CALL

 The stub is an object, acts as a gateway for the client side. All the outgoing to requests are
routed through it.
 It resides at the client side and represented the remote object
 To hide the underlying communication network, RPC communication package known as
RPC Runtime is used on both the sides.
 The implementation of RPC involves the five elements of program:
1. Client
2. Client stub
3. RPC Runtime
4. Server stub
5. Server

66
REMOTE PROCEDURE CALL
 The client, the client stub, and one instance of RPCRuntime
execute on the client machine
 The server, the server stub, and one instance RPCRuntime execute
on the server machine
 As far as, the client is concerned, romete services are accessed by
the user.
 Client stub is responsible for the following two tasks
 One receipt of call request from the client
 It packs a specification of the target procedure and the arguments
into messages and
 Asks the local Runtime to send it to the server stub
 One receipt the result of procedure execution, it uplinks the result
and passes it to the client. 67
RPCRUNTIME
 RPCRuntime handles transmission of messages across the
network between client and server machine
 It is responsible
 Retransmission

 Acknowledgment

 Routing

 Encryption

68
SERVER STUB
 Server stub is responsible for the following two tasks
 On receipt of call request message from local RPCRuntime,
it unpacks it and makes a perfectly normal call to invoke the
appropriate procedure in the server
 On receipt of the result of procedure execution from the
server, it unpacks the result into a message and then asks the
local RPCRuntime to send it to the client stub.

69
RPC MESSAGES
 RPC messages
 RPC system is independent of transport prortocol and is not
concerned as to how a message is passed from one proceses to
another.
 Types of message involved in the implementation of RPC
system
 Call messages
 Reply messages

70
EVENTS AND NOTIFICATIONS
 What is the idea behind the use of events? Publish-subscribe paradigm:
 One object react to a change occurring in
another object The generator publish the type
 Example: of events that it will make
 manipulating with the mouse or entering text in available for observation by
a text box via the keyboard is an event which is
followed by a notification to the objects that are other objects
responsible for displaying a view of current
state. The receives subscribe to the
 Communicate a shape added to a drawing types of events that are of
 Modification to a document interest to them
 Person has entered or left room
 Piece of equipment or an electronically tagged
book is at a new location The receives receive
notifications of events when
the occur
71
EVENTS AND NOTIFICATIONS…
 Events  Distributed event-based systems
 They extend the local event model by
 Are the action performs on objects allowing multiple objects at different
 Different event types may refer to locations to be notified of event taking
the different methods executed by place at an object
the object of interest  They have tow main characteristics
 Heterogeneous: Components in a
 Notification: distributed system that were no designed
 Objects that represent events to interpreted can be made to work
 They may be: together
 Asynchronous
 Stored
Prevent publisher needing to synchronize
 Sent in message with subscribes
 Queried Publishers subscribe need to be decoupled

72
EVENTS AND NOTIFICATIONS…
 Mushroom:  an information provider processes
 Is distributed event based system  It receives new trading information
designed to support collaborative work,
in which the user interface display from a single external source
objects representing users and  It implies the information to the
information's objects such as appropriate stock object
documents and notepads within shared
workspaces called network places.  Each of the updates to a stock object
 The sate of each place is replicated at is refereed as an event
the computers of users currently that  The sock object notifies all of the
place dealers who have subscribed to the
 Evets are used to describe changes to corresponding stock
objects and to a users focus of interest
 There is a separate information
provider process for each external
source

73
EVENTS AND NOTIFICATIONS…
 Simple dealing room system:
 It takes is to allow dealers using computers to see the latest information about the market
prices of the stocks they deal in.
 It could be modeled by with two different tasks
 An information provider process
 a dealer processes
 A dealer processes
 It creates an object to represent each named stock that the user asks to have displayed
 The local object subscribes to the object representing that stock at the relevant information
provider
 The local then receives all the information sent to it in notification and display it to the user.

74
THANK YOU FOR YOUR ATTENTION

75

You might also like