0% found this document useful (0 votes)
10 views

Lecture 8 - Distributed Java Programming

This lecture covers the fundamentals of distributed systems, including their definition, functions, and differences from centralized systems. It introduces middleware, specifically Java RMI (Remote Method Invocation), which allows remote communication between Java programs. The document also outlines the steps to create a distributed application using Java RMI, including creating remote interfaces and server-client interactions.

Uploaded by

laugitonga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lecture 8 - Distributed Java Programming

This lecture covers the fundamentals of distributed systems, including their definition, functions, and differences from centralized systems. It introduces middleware, specifically Java RMI (Remote Method Invocation), which allows remote communication between Java programs. The document also outlines the steps to create a distributed application using Java RMI, including creating remote interfaces and server-client interactions.

Uploaded by

laugitonga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Distributed

Systems Using
Java
Lecture 8
Lecture Outline

• Introduction to Distributed Systems


• The Middleware
• Distributed Objects
• Java RMI
• RMI vs other technologies
Distributed Systems

INTRODUCTION
Distributed Systems
• A distributed system is a network that consists of
autonomous computers that are connected using a
distribution middleware.

• They help in sharing different resources and capabilities


to provide users with a single and integrated coherent
network.
Distributed Systems

“ A distributed system runs on a collection of computers that do


not have shared memory, yet looks like a single computer to its
users.”

“A distributed system is one in which hardware or software


components located at networked computers communicate and
coordinate their actions only by message passing.” [Coulouris]
Distributed Systems vs
Central Systems
Centralized Systems Distributed Systems
– Centralized systems have – Distributed systems have
non-autonomous autonomous components
components – Distributed systems may be
– Centralized systems are built using heterogeneous
technology
often build using
homogeneous technology – Distributed system
components may be used
– Multiple users share the exclusively
resources of a centralized – Distributed systems are
system at all times executed in concurrent
– Centralized systems have a processes
single point of control and – Distributed systems have
of failure multiple points of failure
Distributed Systems
• Networks focuses
on packets, routing,
etc., whereas
distributed systems Distributed Systems
focus on
applications.
Computer Networks
• Every distributed
system relies on
services provided by
a computer
network.
Distributed Systems - Functions
• The most important functions of distributed computing are:

• Resource sharing - whether it’s the hardware, software or


data that can be shared
• Openness - how open is the software designed to be
developed and shared with each other
• Concurrency - multiple machines can process the same
function at the same time
• Scalability - how do the computing and processing
capabilities multiply when extended to many machines
• Fault tolerance - how easy and quickly can failures in parts
of the system be detected and recovered
• Transparency - how much access does one node have to
locate and communicate with other nodes in the system.
Distributed Systems - Reasons

• Functional Separation
• Inherent Distribution
• Power imbalance and Load variation
• Reliability
• Resource sharing
Distributed Systems - Reasons

• Functional Separation:

– Existence of computers with different capability &


purpose:

• Clients and Servers


• Data collection and data processing

Processing Data storage Presentation

CPU Memory Cost?


Distributed Systems - Reasons
• Inherent distribution:

• Information
– Different information is created and
maintained by different persons (e.g., Web
pages);

• People
– Computer supported collaborative work
(virtual teams, engineering, virtual surgery)

• Retail store and inventory systems for supermarket


chain
Distributed Systems - Reasons

• Power imbalance and load variation:

• Distribute computational load among different


computers

Cluster:
“A type of parallel or distributed processing system,
which consists of a collection of interconnected stand-
alone computers cooperatively working together as a
single, integrated computing resource”
Distributed Systems - Reasons

• Reliability:
– Long term preservation and data backup
(replication) at different location.

• Economies:
– Sharing a printer by many users and reduce
the cost of ownership.
– Building a supercomputer out of a network of
computers.
Distributed Systems - Examples

• Internet
• Intranet
• Mobile/Ubiquitous Computing
• Automatic Teller Machine Network
The Internet

intranet %
%
% ISP

backbone

satellite link

desktop computer:
server:
network link:

The Internet is a vast collection of computer networks of many


different types and hosts various types of services.
The Intranet
email server Desktop
computer s
print and other servers

Local area
Web server network

email server
print
File server
other servers

the rest of
the Internet
router/firewall

A portion of Internet that is separately administered & supports internal


sharing of resources (file/storage systems and printers)
Mobile/Ubiquitous Computing

Internet

Host intranet WAP


Wireless LAN Home intranet
gateway

Mobile
phone
Printer Laptop
Camera Host site

Portable and handheld devices in a distributed system


Automated Teller Machine (ATM)
Network
Distributed Systems in Java

MIDDLEWARE
Introduction
• A distributed system is a network that
consists of autonomous computers that are
connected using a distribution middleware.

• Middleware in this context is a software that


provides services beyond those provided by
the operating system to enable the various
components of a distributed system to
communicate and manage data.

• Middleware supports and simplifies complex


distributed applications.
Introduction
• Middleware is a
software layer that Applications and services
provides:

Middleware
– programming
abstraction
– masking Operating System
heteorogeneity of:
• underlying
Computer and Network
networks hardware
• hardware
• operating systems
Distributed Object Middleware

• Distributed object middleware provides:

– encapsulation in object-based solutions – well suited


to distributed programming
– data abstraction – clean separation between the
specification of an object and its implementation ⇒
programmers to deal solely in terms of interfaces and
not concern with implementation details
– more dynamic and extensible solutions

• Examples of distributed objects middleware:


– Java RMI(Remote Method Invocation)
– CORBA (Common Object Request Broker Architecture)
Distributed Java Programming

JAVA RMI
Java RMI

• RMI stands for Remote Method Invocation. It


is a mechanism that allows an object residing
in one system (JVM) to access/invoke an
object running on another JVM.
• RMI is used to build distributed applications; it
provides remote communication between Java
programs.
• It is provided in the package java.rmi.
2025-03-24 Advanced OOP - Kurui Daniel 24
Java RMI cont’d

• In an RMI application, we write two programs, a


server program (resides on the server) and a
client program (resides on the client).
• Inside the server program, a remote object is
created and reference of that object is made
available for the client (using the registry).
• The client program requests the remote objects
on the server and tries to invoke its methods.

2025-03-24 Advanced OOP - Kurui Daniel 25


Java RMI Cont’d

2025-03-24 Advanced OOP - Kurui Daniel 26


Java RMI Cont’d
• Transport Layer − This layer connects the client
and the server. It manages the existing connection
and also sets up new connections.
• Stub − A stub is a representation (proxy) of the
remote object at client. It resides in the client
system; it acts as a gateway for the client program.
• Skeleton − This is the object which resides on the
server side. stub communicates with this skeleton
to pass request to the remote object.
• RRL(Remote Reference Layer) − It is the layer
which manages the references made by the client
to the remote object.
2025-03-24 Advanced OOP - Kurui Daniel 27
How it works

• When the client makes a call to the remote object,


it is received by the stub which eventually passes
this request to the RRL.
• When the client-side RRL receives the request, it
invokes a method called invoke() of the object
remoteRef. It passes the request to the RRL on the
server side.
• The RRL on the server side passes the request to
the Skeleton (proxy on the server) which finally
invokes the required object on the server.
• The result is passed all the way back to the client.

2025-03-24 Advanced OOP - Kurui Daniel 28


The message

• Whenever a client invokes a method that


accepts parameters on a remote object, the
parameters are bundled into a message
before being sent over the network.
• These parameters may be of primitive type
or objects.
• In case of primitive type, the parameters are
put together and a header is attached to it.
2025-03-24 Advanced OOP - Kurui Daniel 29
The message cont’d

• In case the parameters are objects, then


they are serialized.
• This process is known as marshalling.
• At the server side, the packed parameters
are unbundled and then the required
method is invoked.
• This process is known as unmarshalling.

2025-03-24 Advanced OOP - Kurui Daniel 30


Stub

A remote object is an object whose method


can be invoked from another JVM.
• The stub is an object, acts as a gateway for
the client side.
• All the outgoing requests are routed
through it.
• It resides at the client side and represents
the remote object.

2025-03-24 Advanced OOP - Kurui Daniel 31


Stub cont’d

When the caller invokes method on the stub


object, it does the following tasks:
– It initiates a connection with remote Virtual
Machine (JVM),
– It writes and transmits (marshals) the
parameters to the remote Virtual Machine
(JVM),
– It waits for the result
– It reads (unmarshals) the return value or
exception, and
– It finally, returns the value to the caller.
2025-03-24 Advanced OOP - Kurui Daniel 32
Skeleton

• The skeleton is an object, acts as a gateway for the server


side object.
• All the incoming requests are routed through it.
• When the skeleton receives the incoming request, it does
the following tasks:
– It reads the parameter for the remote method
– It invokes the method on the actual remote object,
and
– It writes and transmits (marshals) the result to the
caller.

2025-03-24 Advanced OOP - Kurui Daniel 33


System Diagram

remote object
(server)
RMI Registry

• RMI registry is a namespace on which all


server objects are placed.
• Each time the server creates an object, it
registers this object with the RMIregistry
(using bind() or reBind() methods).
• These are registered using a unique name
known as bind name.
• To invoke a remote object, the client needs a
reference of that object.
• At that time, the client fetches the object
from the registry using its bind name (using
lookup() method).

2025-03-24 Advanced OOP - Kurui Daniel 35


Requirements for distributed applications

• If any application performs these tasks, it can


be distributed application.
– The application need to locate the remote
method
– It need to provide the communication with the
remote objects.
– The application need to load the class definitions
for the objects.

• The RMI application have all these features,


so it is called the distributed application.
2025-03-24 Advanced OOP - Kurui Daniel 36
Distributed Java Programming

RMI IMPLEMENTATION
Steps to writing a Java distributed
Application

1. Create the remote interface


2. Provide the implementation of the remote
interface
3. Develop server program
4. Develop client program
5. Compile application
6. Execute the application

2025-03-24 Advanced OOP - Kurui Daniel 38


1. Create the remote interface
• A remote interface provides the description of all the methods of a
particular remote object.
• The client communicates with this remote interface.
• To create a remote interface −
– Create an interface that extends the predefined interface
Remote which belongs to the package.
– Declare all the business methods that can be invoked by the
client in this interface.
– Since there is a chance of network issues during remote calls, an
exception named RemoteException may occur; throw it.
– Following is an example of a remote interface. Here we have
defined an interface with the name Student and it has the
methods: called insert(), update(), delete() & select().

2025-03-24 Advanced OOP - Kurui Daniel 39


Remote interface

2025-03-24 Advanced OOP - Kurui Daniel 40


2. Implementing Remote Interface

• We need to implement the remote


interface created in the earlier step.
• We can write an implementation class
separately or we can directly make the
server program implement this interface.
• To develop an implementation class −
– Extend the UnicastRemoteObject
– Implement the interface created in the previous step.
– Provide implementation to all the abstract methods of the
remote interface.
2025-03-24 Advanced OOP - Kurui Daniel 41
Remote interface

2025-03-24 Advanced OOP - Kurui Daniel 42


3. Develop the Server Program

• To develop a server program −


– Create a client class for example StudentRMIServer.
– Create an object of the implementing class:

– Declare a main method and inside it, implement the following


steps
– Create an object registry of the class Registry
– Cal the createRegistry() method of the LocateRegistry class and
use 1099 as an argument (default RMI port number)

– Bind the registry:

2025-03-24 43
Code for Server Program

2025-03-24 Advanced OOP - Kurui Daniel 44


4. Developing client program

• Write a client program in it, fetch the remote object and invoke the required
method using this object.
• To develop a client program −
• Create a client class from where your intended to invoke the remote object.
– Get the RMI registry using the getRegistry() method of the
LocateRegistry class which belongs to the package java.rmi.registry.
– Fetch the object from the registry using the method lookup() of the
class Registry which belongs to the package java.rmi.registry.
– To this method, you need to pass a string value representing the bind
name as a parameter. This will return you the remote object.
– The lookup() returns an object of type remote, down cast it to the type
Student.
– Finally invoke the required method using the obtained remote object.

2025-03-24 Advanced OOP - Kurui Daniel 45


Code for client program

2025-03-24 Advanced OOP - Kurui Daniel 46


5. Execute the application

• Step 1 − Start the rmi registry using the


start rmiregistry command
• Step 2 − Run the server class file by typing
command java Server
• Step 3 − Run the client class file by typing
command java Client

2025-03-24 Advanced OOP - Kurui Daniel 47


Thank you!

Any Questions?

You might also like