lab manual distributed systems_01
lab manual distributed systems_01
LABORATORY
MANUAL
Department
Of
Information Technology
Distributed Systems
Semester: - VI
Academic Year:
Name
Subject
Departmen
t
Semester Branch
Certificate
Software Required:
1. Jdk-1_5_0
2. Weblogic.
3. .net
Hardware Required:
LIST OF EXPERIMENTS
University of Mumbai
Branch:- Information
Class: T.E Semester: VI
Technology
SYLLABUS
• IT systems are more and more integrated with other software systems.
• The knowledge of integrating these systems by using Distributed systems
can be a key competence for IT engineers.Distributed systems is commonly understood
as an intermediary software layer between the application and the operating
system, which encapsulates the heterogeneity of the underlying communication
network, operating system or hardware platform.
• This course provides details about the modern component platforms. Based on
practical examples, details about modern middleware technologies are studied.
Students get the chance to gain in-depth knowledge popular middleware
platforms.
Sr
Hour
n
s
o Module Contents
1 Fundamentals Introduction, Distributed Computing Models, Software
Concepts, Issues in designing Distributed System, Client –
Server Model
Text Books
Sunita Mahajan, Seema Shah, “ Distributed Computing”, Oxford, second edition.
Andrew S. Tanenbaum & Maarten van Steen “ Distributed Systems : Principles and
paradigms” Prentice Hall of India Private Limited
G. Sudha Sadasivam, Radha Shankarmani, "Middleware and Enterprise Integration
Technologies " , Wiley Precise Textbook
References:
1. Pradeep K. Sinha “Distributed Operating Systems”, Prentice Hall of India Private
Term work should consist of at least 10 practical experiments with 1 mini project
and assignments covering the topics of the syllabus
Assignments 05 Marks
Attendance 05 Marks
Software: Jdk1.6
Theory:
The client-server model has become one of the central ideas of network computing.
Many business applications being written today use the client-server model. So do the
Internet's main application protocols, such as HTTP, SMTP, Telnet, DNS. In
marketing, the term has been used to distinguish distributed computing by smaller
dispersed computers from the "monolithic" centralized computing of mainframe
computers. But this distinction has largely disappeared as mainframes and their
applications have also turned to the client-server model and become part of network
computing.
Each instance of the client software can send data requests to one or more connected
servers. In turn, the servers can accept these requests, process them, and return the
requested information to the client.
The most basic type of client-server architecture employs only two types of hosts:
clients and servers. This type of architecture is sometimes referred to as two-tier. It
allows devices to share files and resources. The two tier architecture means that the
client acts as one tier and application in combination with server acts as another tier.
The interaction between client and server is often described using sequence diagrams.
Sequence diagrams are standardized in the Unified Modeling Language.
Disadvantages
Traffic congestion on the network has been an issue since the inception of the client-
server paradigm.As the number of simultaneous client requests to a given server
increases, the server can become overloaded. Contrast that to a P2P network, where its
aggregated bandwidth actually increases as nodes are added, since the P2P network's
overall bandwidth can be roughly computed as the sum of the bandwidths of every
node in that network.
The client-server paradigm lacks the robustness of a good P2P network. Under client-
server, should a critical server fail, clients’ requests cannot be fulfilled.
Program:
Output:
SOFTWARE: Jdk1.6.0
THEORY:
Remote Method Invocation (RMI)
The only hint that it is a remote method is the “Naming.lookup”call with a URL
(Hidden) Java RMI classes do all the “heavy lifting” – opening network sockets,
transfer the function arguments, retrieve the results,close the network sockets
On the server side, there is a “Naming.rebind” call in the main method (to bind the
server to a network location/URL)
● Again, the Java RMI classes to the “heavy lifting” -- converting the remote method
call into a “regular” method call on “normal” Java code running within the server.
System Architecture
3 independent layers:
o Stub-skeleton layer - client stubs and server skeletons
o Remote reference layer - Semantics of remote reference
Stub-skeleton Layer
ALGORITHM:
Program:
OUTPUT:
SOFTWARE: Jdk1.6.0
THEORY:
Logical clocks
A logical clock is a mechanism for capturing chronological and causal
relationships in a distributed system. Distributed system may have no
physically synchronous global clock, and logical clock allow to get
global ordering on events from different processes in such systems.
First implementation, the Lamport timestamps, was proposed by Leslie
Lamport in 1978 (Turing Award in 2013).
In logical clock systems each process have two data structures with
logical local time and logical global time. Logical local time is used by
the process to mark its own events, and logical global time is the local
information about global time. A special protocol is used to update
logical local time after each local event, and logical global time when
processes exchange data.[1]
Lamport’s algorithm
Lamport’s algorithm remedies the situation by forcing a resequencing of
timestamps to ensure that the happens before relationship is properly depicted
forevents related to sending and receiving messages. It works as follows:Each
process has a clock, which can be a imple counter thatis incremented for each
event.The sending of a message is an event and each message carries with it a
timestamp obtained from the current value of the clock at that process (sequence
number). The arrival of a message at a process is also an event will also receive
a timestamp – by the receiving process, of course. The process’ clock is
cremented prior to timestamping the event, as it would be for any other event. If
the clock value is less than the timestamp in the received message, the system’s
clock is adjusted to the (message’s timestamp + 1). Otherwise nothing is done.
The event is now timestamped.
- Each message carries a timestamp of the sender’s clock.
- When a message arrives:
if receiver’s clock < message_timestamp set system clock to
(message_timestamp+ 1)
–else do nothing
- Clock must be advanced between any two events in the same process.
- Algorithm allows us to maintain time ordering among related events
Program:
Experiment No 4
AIM: Implementation of Mutual exclusion.
SOFTWARE: Jdk1.6.0
THEORY:
MUTUAL EXCLUSION
When a process has to read or update certain shared data structures, it first enters
a critical region to achieve mutual exclusion and ensure that no other process
will use the shared data structures at the same time. In single- processor systems,
critical regions are protected using semaphores, monitors, and similar constructs.
A Centralized Algorithm
0 1 2 0 1 2 0 1 2
request ok request Release
ok
3 3 No reply 3
Queue is 2
empty
FIG (a) Process 1 asks the coordinator for permission to enter a critical
region. Permission is granted. (b) Process 2 then asks permission to enter the
same critical region. The coordinator does not reply. (c) When process 1 exits
the critical region, it tells the coordinator, which then replies to 2
A Token Ring Algorithm
Fig(b):Token Ring
For this algorithm, we assume that there is a group of processes with noinherent
ordering of processes, but that some ordering can be imposed on the group. For
example, we can identify each process by its machine address and process ID to
obtain an ordering. Using this imposed ordering, a logical ring is constructed in
software. Each process is assigned a position in the ring and each process must
know who is next to it in the ring (Figure b).The ring is initialized by giving a
token to process 0. The token circulates around the ring (process n passes it to
(n+1)mod ringsize.When a process acquires the token, it checks to see if it is
attempting to enter the critical section. If so, it enters and does its work. On exit,
it passes the token to itsneighbor.If a process isn't interested in entering a critical
section, it simply asses the token along.
Output:
Experiment No. 5
AIM: Implementation of Election.
SOFTWARE: Jdk1.6.0
THEORY:
Election algorithms
We often need one process to act as a coordinator. It may not matter which
process does this, but there should be group agreement on only one. An
assumption in election algorithms is that all processes are exactly the same with
no distinguishing characteristics. Each process can obtain a unique identifier (for
example, a machine address and process ID) and each process knows of every
other process but does not know which is up and which is down.Bully
algorithmThe bully algorithm selects the process with the largest identifier as the
coordinator. It works as follows:
3.A process announces its victory by sending all processes a message telling
them that it is the new coordinator.
The ring algorithm uses the same ring arrangement as in the token ring mutual
exclusion algorithm, but does not employ a token. Processes are physically or
logically ordered so that each knows its successor.If any process detects failure,
it constructs an electionmessage with its process I.D. (e.g. network address and
local process I.D.) and sends it to its successor.If the successor is down, it skips
over it and sends the message to the next party. This process is repeated until a
running process is located.At each step, the process adds its own process I.D. to
the list in the message.Eventually, the message comes back to the process that
started it:
3.The list is circulated again, with each process selecting the highest numbered
ID in
the list to act as coordinator.
Program:
Experiment No: 07
Aim: Program to implement multithreaded client server using socket
Theory:
A socket is the one end-point of a two-way communication link between two programs
running over the network. Running over the network means that the programs run on
different computers, usually referred as the local and the remote computers. However one
can run the two programs on the same computer. Such communicating programs constitutes a
client/server application. The server implements a dedicated logic, called service. The clients
connect to the server to get served, for example, to obtain some data or to ask for the
computation of some data. Different client/server applications implement different kind of
services.
A socked is a complex data structure that contains an internet address and a port number. A
socket, however, is referenced by its descriptor, like a file which is referenced by a file
descriptor.
1. When the server receives a connection request on its specific server port, it creates a
new socket for it and binds a port number to it.
2. It sends the new port number to the client to inform it that the connection is
established.
3. The server goes on now by listening on two ports:
o it waits for new incoming connection requests on its specific port, and
o it reads and writes messages on established connection (on new port) with the
accepted client.
The server communicates with the client by reading from and writing to the new port. If
other connection requests arrive, the server accepts them in the similar way creating a new
port for each new connection. Thus, at any instant, the server must be able to communicate
simultaneously with many clients and to wait on the same time for incoming requests on its
specific server port. The communication with each client is done via the sockets created for
each communication.
The java.net package in the Java development environment provides the class Socket that
implements the client side and the class serverSocket class that implements the server side
sockets.
1) Opening a socket
2) The client side
Socket MyClient;
MyClient = new Socket("MachineName", PortNumber);
This code, however, must be put in a try/catch block to catch the IOException:
Socket MyClient;
where
When programming a server, a server socket must be created first, like below:
ServerSocket MyService;
try {
MyServerice = new ServerSocket(PortNumber);
}
catch (IOException e) {
System.out.println(e);
}
The server socket is dedicated to listen to and accept connections from clients.
After accepting a request from a client the server creates a client socket to
communicate (to send/receive data) with the client, like below :
Now the server can send/receive data to/from the clients. Since the sockets are like
the file descriptors the send/receive operations are implemented like read/write file
operations on the input/output streams.
On the client side, you can use the DataInputStream class to create an input
stream to receive responses from the server:
DataInputStream input;
try {
catch (IOException e) {
System.out.println(e);
The class DataInputStream allows you to read lines of text and Java primitive
data types in a portable way. It has several read methods such as read, readChar,
readInt, readDouble, and readLine. One has to use whichever function
depending on the type of data to receive from the server.
On the server side, the DataInputStream is used to receive inputs from the client:
try {
catch (IOException e) {
System.out.println(e);
On the client side, an output stream must be created to send the data to the server
socket using the class PrintStream or DataOutputStream of java.io package:
PrintStream output;
try {
catch (IOException e) {
System.out.println(e);
The class PrintStream implements the methods for displaying Java primitive data
types values, like write and println methods. Also, one may want to use the
DataOutputStream:
DataOutputStream output;
try {
catch (IOException e) {
System.out.println(e);
On the server side, one can use the class PrintStream to send data to the client.
PrintStream output;
try {
catch (IOException e) {
System.out.println(e);
4. Closing sockets
Closing a socked is like closing a file. You have to close a socket when you do not
need it any more. The output and the input streams must be closed as well but
before closing the socket.
On the client side you have to close the input and the output streams and the socket
like below:
try {
output.close();
input.close();
MyClient.close();
catch (IOException e) {
System.out.println(e);
On the server you have to close the input and output streams and the two sockets
as follows:
output.close();
input.close();
serviceSocket.close();
MyService.close();
catch (IOException e) {
System.out.println(e);
Usually, on the server side you need to close only the client socket after the client
gets served. The server socket is kept open as long as the server is running. A new
client can connect to the server on the server socket to establish a new connection,
that is, a new client socket.
SOFTWARE:
THEORY:
SOFTWARE:
THEORY:
Enterprise Bean
Purpose
Type
Session Bean:
A session bean represents a single client inside the J2EE server. To access an application
that is deployed on the server, the client invokes the session bean's methods.
As its name suggests, a session bean is similar to an interactive session. A session bean
is not shared--it may have just one client, in the same way that an interactive session may have
just one user. Like an interactive session, a session bean is not persistent. When the client
terminates, its session bean appears to terminate and is no longer associated with the client.
The state of an object consists of the values of its instance variables. In a stateful session
bean, the instance variables represent the state of a unique client-bean session. Because the
client interacts ("talks") with its bean, this state is often called the conversational state.
A stateful session bean is an enterprise bean (EJB component) that acts as a server-side
extension of the client that uses it. The stateful session bean is created by a client and will
work for only that client until the client connection is dropped or the bean is explicitly
removed. The stateful session bean is EJB component that implements the
javax.ejb.SessionBean interface and is deployed with the declarative attribute "stateful".
Stateful session beans are called "stateful" because they maintain a conversational state with
the client. In other words, they have state or instance fields that can be initialized and changed
by the client with each method invocation. The bean can use the conversational state as it
process business methods invoked by the client.
Stateful session beans are usually developed to act as agents for the client, managing
the interaction of other beans and performing work on behalf of the client application. An
example is a shopping cart stateful session bean that tracks a client's product choices and can
execute a sale when requested. Below is partial example of a stateful session bean that is used
as a shopping cart.
Program:
Output:
Experiment No. 9
SOFTWARE:
THEORY:
CORBA, which stands for Common Object Request Broker Architecture, is an
industry standard developed by the (a consortium of more than 700 companies) to aid in
distributed objects programming.
CORBA is just a specification for creating and using distributed objects;
CORBA is not a programming language. The CORBA architecture is based on the object
model. This model is derived from the abstract core object model defined by the OMG in the
Object Management Architecture Guide,
CORBA -based system is a collection of objects that isolates the requestors of
services (clients) from the providers of services (servers) by a well-defined encapsulating
interface. It is important to note that CORBA objects differ from typical programming objects
in three ways:
• CORBA objects can run on any platform.
• CORBA objects can be located anywhere on the network.
• CORBA objects can be written in any language that has IDL mapping.
CORBA ARCHITECTURE
The OMG ’s Object Management Architecture ( OMA ) tries to define the various
high-level facilities that are necessary for distributed object-oriented computing. The core of
the OMA is the Object Request Broker (ORB), a mechanism that provides object location
tranparency,communication, and activation. Based on the OMA , the CORBA specification
which provides a description of the interfaces and facilities that must be provided by
compliant ORB s was released.
CORBA is composed of five major components: ORB , IDL , dynamic invocation
interface ( DII ), interface repositories (IR), and object adapters (OA).
The CORBA specification must have software to implement it. The software that
implements the CORBA specification is called the ORB. The ORB, which is the heart of
CORBA, is responsible for all the mechanisms required to perform these tasks:
Diagram:
Diagram:
.
CLIENT AND OBJECT IMPLEMENTATIONS
OBJECT SERVICES
The OMA, which is shown in figure 11.4, is the next higher level that builds upon the
CORBA architecture. The goal of the OMA is to allow applications to provide their basic
functionality through a standard interface.
CORBAservices and CORBAfacilities. CORBAservices provides basic services that
almost every object needs; this includes naming service and event service. The
CORBAfacilities provides higher-level functionality at the application level
Program:
Output:
Experiment No: 10
What is .NET?
The .NET Framework introduces a completely new model for the programming
and deployment of applications. .NET is Microsoft's vision of "software as a
service", a development environment in which you can build, create, and deploy
your applications and the next generation of components, the ability to use the
Web rather than your own computer for various services.
Program:
Output: