0% found this document useful (0 votes)
18 views26 pages

Unit 3

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)
18 views26 pages

Unit 3

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/ 26

Unit 3

1)Difference between RMI & RPC?

S.NO RPC RMI

RPC is a library and OS


1. Whereas it is a java platform.
dependent platform.

RPC supports procedural RMI supports object-oriented


2.
programming. programming.

RPC is less efficient in While RMI is more efficient


3.
comparison of RMI. than RPC.

While it creates less overhead


4. RPC creates more overhead.
than RPC.

The parameters which are


While in RMI, objects are
5. passed in RPC are ordinary or
passed as parameter.
normal data.
RPC is the older version of While it is the successor
6.
RMI. version of RPC.

There is high Provision of ease While there is low Provision of


7.
of programming in RPC. ease of programming in RMI.

RPC does not provide any While it provides client level


8.
security. security.

While it’s development cost is


9. It’s development cost is huge.
fair or reasonable.

There is a huge problem of While there is possible


10.
versioning in RPC. versioning using RDMI.

There is multiple codes are While there is multiple codes


11. needed for simple application are not needed for simple
in RPC. application in RMI.
Can be complex due to Generally simpler to use and
12.
low-level implementation implement

2)Explain the features of distributed object model [7M, CO3, Understand]

The distributed applications consist of two parts - a client part and a server part. A typical server
part of such an application defines several distributed objects and allows clients to request them
by obtaining references to them. The client part obtains a reference to one or more objects from
the server part, and calls their methods.
RMI-P4 provides the mechanism by which client and server parts communicate.
Features
Object reference
Interfaces
Actions
Exceptions

The RMI-P4 implements the following functions that an application based on the Distributed
Object Model requires: Locate the distributed object Communicate with the distributed object
Load classes of objects
Object Reference: In a distributed object model, an object reference is a handle or
identifier that clients use to access remote objects. It abstracts the details of object
location and communication, allowing clients to interact with remote objects as if they
were local.
Interfaces: Interfaces define the contract or set of methods that objects must
implement to provide a specific functionality. In distributed systems, interfaces facilitate
communication between clients and remote objects by specifying the methods that
clients can invoke on those objects.

Actions: Actions refer to the operations or methods that can be performed on objects in
a distributed environment. These actions represent the functionality exposed by remote
objects, which clients can invoke through method calls to achieve desired tasks or
behaviors.

Exceptions: Exceptions in distributed systems are used to handle errors and exceptional
conditions that may occur during remote method invocations. They allow for graceful
error handling and recovery, enabling robust and reliable communication between
clients and remote objects.

3)Write a RMI program that demonstrates the invocation of remote object services. For
example when a client sends a message "hello", the server responds with "Hi, You
There". [7M, CO3, Apply]
Here's a simple RMI (Remote Method Invocation) program that demonstrates the invocation of
remote object services. In this example, when a client sends a message "hello" to the server,
the server responds with "Hi, You There".

First, let's define the remote interface `HelloService`:

```java
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface HelloService extends Remote {


String sayHello(String message) throws RemoteException;
}
```

Next, let's implement the server class `HelloServiceImpl`:

```java
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class HelloServiceImpl extends UnicastRemoteObject implements HelloService {


protected HelloServiceImpl() throws RemoteException {
super();
}

@Override
public String sayHello(String message) throws RemoteException {
if ("hello".equalsIgnoreCase(message)) {
return "Hi, You There";
} else {
return "Unknown message";
}
}
}
```

Then, let's write the server program `HelloServer`:

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;

public class HelloServer {


public static void main(String[] args) {
try {
// Create the remote object
HelloService helloService = new HelloServiceImpl();

// Register the remote object with the RMI registry


LocateRegistry.createRegistry(1099);
Naming.rebind("HelloService", helloService);

System.out.println("Server started");
} catch (Exception e) {
e.printStackTrace();
}
}
}
```

Finally, let's write the client program `HelloClient`:

import java.rmi.Naming;

public class HelloClient {


public static void main(String[] args) {
try {
// Look up the remote object from the RMI registry
HelloService helloService = (HelloService)
Naming.lookup("rmi://localhost/HelloService");

// Invoke the remote method


String response = helloService.sayHello("hello");
System.out.println("Response from server: " + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}

To run the program:


1. Compile all Java files.
2. Start the RMI registry by running `rmiregistry` command in the terminal.
3. Start the server by running `java HelloServer` command.
4. Start the client by running `java HelloClient` command.
You should see the client sending "hello" to the server and receiving "Hi, You There" as the
response.

4)What is the importance of distributed garbage collection? Explain the Distributed


garbage collector algorithm.[7M, CO3, Understand]

Distributed garbage collection (DGC) is essential in distributed systems to reclaim


memory resources allocated to objects that are no longer in use across multiple nodes.

Importance of Distributed Garbage Collection:


1. Memory Management:
● Distributed systems often allocate memory dynamically to create and
manipulate objects across multiple nodes.
● Without distributed garbage collection, unused objects may accumulate
over time, leading to memory leaks and exhaustion of system resources.
2. Resource Efficiency:
● DGC helps in reclaiming memory occupied by unreachable objects,
allowing the system to reuse memory for new object allocations.
● By efficiently managing memory resources, DGC improves the overall
performance and responsiveness of distributed applications.
3. Scalability:
● In large-scale distributed systems with numerous interconnected nodes,
effective garbage collection is crucial for scalability.
● DGC ensures that memory resources are efficiently utilized across all
nodes, enabling the system to scale to handle increasing workloads.
4. Fault Tolerance:
● Distributed systems are prone to failures such as node crashes or network
partitions.
● DGC helps in detecting and collecting garbage across distributed nodes
even in the presence of failures, maintaining system stability and
reliability.
5. Consistency and Correctness:
● Proper garbage collection ensures the consistency and correctness of
distributed system states by removing stale or obsolete objects from
memory.
● By cleaning up unreachable objects, DGC prevents dangling references
and inconsistencies in distributed data structures.

Distributed Garbage Collector Algorithm,

1. Mark Phase: Nodes traverse their local memory heap, marking reachable objects.
2. Synchronization: Nodes exchange information to ensure a consistent view of live
objects.
3. Reference Counting or Tracing: Nodes determine unreachable objects using
reference counting or tracing algorithms.
4. Collection: Unreachable objects are reclaimed, freeing up memory space.
5. Finalization (Optional): Finalization methods may be invoked on collected objects
before memory reclamation.

5)Explain about different programming models

1. Imperative Programming Model:


● Describes step-by-step instructions to perform tasks.
● Example: C, Pascal.
2. Object-Oriented Programming (OOP) Model:
● Organizes code around objects with data and behavior.
● Example: Java, Python.
3. Functional Programming Model:
● Treats computation as mathematical functions.
● Focuses on immutability and higher-order functions.
● Example: Haskell, Lisp.
4. Event-Driven Programming Model:
● Programs respond to events or user actions.
● Uses event handlers or callbacks.
● Example: JavaScript.
5. Concurrent and Parallel Programming Models:
● Handles multiple tasks executing simultaneously.
● Example: Java threads, MPI.
6. Service-Oriented Architecture (SOA) Model:
● Breaks applications into interoperable services.
● Promotes loose coupling and reuse.
● Example: Web services.
7. Component-Based Programming Model:
● Divides software into reusable components.
● Encourages modularity and code reuse.
● Example: JavaBeans, .NET components.
8. Distributed Programming Model:
● Focuses on applications running across multiple systems.
● Involves communication and synchronization mechanisms.
● Example: CORBA, RMI.
6)Explain RMI Invocation Semantics? How to implement transparency in it. [7M, CO3,
Understand]

The RMI (Remote Method Invocation) 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 JVM.

The RMI provides remote communication between the applications using two objects
stub and skeleton.

RMI uses stub and skeleton object for communication with the remote object.

A remote object is an object whose method can be invoked from another JVM. Let's
understand the stub and skeleton objects:

stub

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. When
the caller invokes method on the stub object, it does the following tasks:

1. It initiates a connection with remote Virtual Machine (JVM),


2. It writes and transmits (marshals) the parameters to the remote Virtual Machine
(JVM),
3. It waits for the result
4. It reads (unmarshals) the return value or exception, and
5. It finally, returns the value to the caller.

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:
1. It reads the parameter for the remote method
2. It invokes the method on the actual remote object, and
3. It writes and transmits (marshals) the result to the caller.

In the Java 2 SDK, an stub protocol was introduced that eliminates the need for

skeletons.

To implement transparency in RMI:

1. Location Transparency:
● Use a naming service like RMI registry to map logical object names to
network addresses.
2. Access Transparency:
● Define remote interfaces for methods available for remote invocation.
● RMI generates stubs and skeletons automatically, handling network
communication transparently.
3. Failure Transparency:
● RMI handles failures and exceptions automatically, retrying failed method
calls and propagating exceptions between client and server.
4. Consistency:
● RMI maintains consistency by ensuring synchronous invocation
semantics and preserving the order of method calls.

7)With case study explain the concept of event and notification.
Publish-subscribe paradigm: publisher sends notifications, i.e. objects representing
events
Subscriber registers interest to receive notifications

The object of interest: where events happen, change of state as a result of its
operations being invoked

Events: occurs in the object of interest

Notification: an object containing information about an event

Subscriber: registers interest and receives notifications

Publisher: generate notifications, usually an object of interest

Observer objects: decouple an object of interest from its subscribers (not important)

Case Study: Jini Distributed Event Specification

Scenario: Distributed Sensor Network

In our scenario, we have sensors scattered around gathering data like temperature and
humidity. Let's use Jini's Distributed Event Specification (DES) to get alerts when certain
conditions are met.
Implementation:

1. Sensor Setup:
● Each sensor registers with the Jini lookup service.
● Sensors announce what data they can provide, like high temperature or
low humidity.
2. Client Subscription:
● Clients interested in specific data types subscribe to the Jini event service.
● They specify what conditions they want, such as temperature above 30°C.
3. Event Handling:
● When a sensor detects an event, like high temperature, it informs the Jini
event service.
● The event service sends this information to all subscribed clients.

Benefits:

1. Easy Setup:
● Sensors and clients can join or leave the network without any hassle.
2. Instant Alerts:
● Clients get real-time notifications when events occur.
3. Flexible Configuration:
● Clients can choose what data they want and under what conditions they
receive alerts.

Conclusion:

With Jini DES, managing events in a distributed sensor network becomes


straightforward. It allows for quick setup, instant notifications, and flexible
customization, making it perfect for various applications.

8)What is meant by light weight remote procedure call?

Lightweight Remote Procedure Call (RPC) means a simple and efficient way for

programs to communicate across a network. It's "lightweight" because it keeps things

simple and fast, avoiding unnecessary complexity and overhead. With lightweight RPC,

programs can call functions on remote servers just like they would call functions locally,

making distributed programming easier.


Lightweight RPC means keeping remote procedure calls simple, fast, and efficient:

1. Minimal Overhead: It reduces unnecessary communication overhead to transmit

data efficiently between client and server.

2. Simple Interface: It provides an easy-to-use interface for calling remote

procedures, similar to local method calls, without complex setup.

3. Efficient Serialization: It uses efficient techniques to convert data into a format

that can be sent over the network quickly, improving performance.

4. Low Latency: It aims to minimize delays by optimizing network communication

and processing on both ends, ensuring quick response times.

5. Scalability: It's designed to handle many remote calls at once without slowing

down, thanks to features like connection pooling and thread management.

9)Discuss about various remote procedure calls? [7M, CO3, Understand]

Remote Procedure Call or RPC is a powerful technique for constructing distributed,


client-server-based applications. It is also known as a function call or a subroutine call

1. Callback RPC:
● Enables a peer-to-peer communication model where processes can act as
both clients and servers.
● Allows processes to handle interactive application problems remotely.
● Provides clients with a handle to server services.
● Involves callback functions that make the client process wait for a
response.
● Manages callback deadlocks to prevent system hang-ups.
2. Broadcast RPC:
● Involves broadcasting a client's request message to all servers on the
network.
● Each server processes the request using the appropriate method.
● Allows specifying that the client's request message should be broadcast.
● Helps reduce network load by distributing processing tasks across
multiple servers.
3. Batch-mode RPC:
● Queues and separates RPC requests on the client-side before sending
them as a batch to the server over the network.
● Minimizes overhead by sending multiple requests in one batch.
● Efficient for applications with lower call rates that can benefit from
batching requests.
● Requires a reliable transmission protocol to ensure all requests are
delivered successfully.

10)How could an interrupt be communicated to a user-level server? [7M, CO3, Analyze

Communicating an interrupt to a user-level server involves several steps to ensure


timely and appropriate handling of the interrupt. Here's a high-level overview of the
process:

1. Interrupt Handling Mechanism:


● The operating system provides mechanisms for handling interrupts, such
as signal handling in Unix-like systems or interrupt service routines (ISRs)
in embedded systems.
● When an interrupt occurs, the operating system invokes the appropriate
handler to handle the interrupt.
2. Signal Delivery:
● The operating system delivers the interrupt signal to the user-level server
process.
● In Unix-like systems, interrupts are often delivered to processes as signals.
The operating system sends a signal, such as SIGINT (interrupt signal) or
SIGTERM (termination signal), to the server process.
3. Signal Handling in User-Level Server:
● The user-level server process registers signal handlers to handle specific
interrupt signals.
● Upon receiving the interrupt signal, the registered signal handler is invoked
to perform the necessary actions.
● For example, the server may gracefully shut down, release resources, or
log the interrupt event.
4. Interrupt Processing:
● Inside the signal handler, the server may perform interrupt-specific
processing tasks.
● This could involve saving critical state information, handling pending
requests, or taking appropriate recovery actions.
5. Synchronization and Coordination:
● Depending on the nature of the interrupt and the server's state,
synchronization and coordination mechanisms may be necessary.
● For example, the server may need to coordinate with other processes or
threads to ensure consistent system behavior during interrupt handling.
6. Error Handling and Recovery:
● The server should handle errors or exceptions that may occur during
interrupt processing.
● This includes error recovery mechanisms to restore the server to a stable
state after handling the interrupt.
7. Notification and Logging:
● Optionally, the server may notify users or administrators about the
interrupt event.
● This could involve logging the event to a file, sending notifications over a
network, or displaying messages to users

11)What is middleware? List the various layers present in it.


In distributed systems, middleware is a software component that provides
services between two or more applications and can be used by them.
Middleware can be thought of as an application that sits between two
separate applications and provides service to both.
12)Explain the design issues of RPC? [13][7M, CO3, Understand]
13)Explain with a neat sketch communication between objects?
Communication Between Objects:

In object-oriented programming (OOP), objects interact with each other by sending


messages. This interaction forms the basis of communication between objects.

Explanation:

1. Objects:
● Objects are instances of classes in OOP. Each object has its own state
(attributes) and behavior (methods).
2. Message Passing:
● Communication between objects occurs through message passing. An
object sends a message to another object to request a specific behavior
or to obtain information.
3. Sender Object:
● The sender object initiates the communication by sending a message to
the receiver object.
4. Receiver Object:
● The receiver object receives the message sent by the sender object and
responds accordingly.
5. Message:
● The message contains information about the requested behavior or the
data to be exchanged between objects.
6. Method Invocation:
● Upon receiving the message, the receiver object invokes the appropriate
method to perform the requested behavior or to process the received data.
7. Response:
● After processing the message, the receiver object may send a response
back to the sender object, depending on the nature of the communication.

14)What do you mean by code migration? To what extent does java RMI reply on code
migration. [7M, CO3, Understand

Code Migration:

Code migration refers to the process of transferring executable code from one
computing environment to another. This can involve moving code between different
machines, platforms, or execution contexts. The goal of code migration is to enable the
execution of code in a remote or distributed environment, allowing applications to
dynamically adapt to changing conditions, optimize resource utilization, or enhance
system performance.

Java RMI and Code Migration:

Java Remote Method Invocation (RMI) is a Java technology that allows communication
between Java objects in different Java virtual machines (JVMs), typically across a
network. While Java RMI primarily focuses on remote method invocation, it does not
heavily rely on code migration as a core feature. However, code migration can still play a
role in certain aspects of Java RMI-based applications:

1. Dynamic Code Loading:


● Java RMI allows for dynamic class loading, where classes can be loaded
and instantiated remotely at runtime. This enables RMI clients to invoke
methods on remote objects without having prior knowledge of the classes
involved.
● In certain scenarios, this dynamic code loading capability can be
considered a form of code migration, as classes are effectively migrated
from the server to the client JVM.
2. Custom Class Loading:
● Developers can implement custom class loading mechanisms in Java RMI
applications to dynamically load classes from remote locations.
● This approach allows applications to load classes dynamically based on
runtime conditions, potentially enabling code migration scenarios where
classes are fetched from remote repositories or servers.
3. Versioning and Upgrades:
● Java RMI applications may involve versioned interfaces and
implementations, where different versions of classes are deployed on
client and server sides.
● When updates or upgrades are made to the server-side classes, clients
may need to dynamically fetch and load the updated classes to ensure
compatibility and consistency.

15)Illustrate the various participants in distributed event notification. [7M, CO3, Apply]
1. Event Source:
● The event source is the entity or component that generates events. It
could be a sensor, application, or system component that produces event
data.
● Example: A temperature sensor in a smart home system that generates
events when the temperature exceeds a certain threshold.
2. Event Producer:
● The event producer is responsible for capturing events from the event
source and forwarding them to the event notification system.
● Example: A middleware component in the smart home system that
collects temperature readings from multiple sensors and sends event
notifications to subscribers.
3. Event Notification System:
● The event notification system is a centralized or distributed infrastructure
that manages the dissemination of events to interested subscribers.
● It receives events from event producers, maintains subscriptions, and
delivers events to subscribers.
● Example: A message broker or publish-subscribe system deployed in the
smart home system that routes temperature events to subscribed clients.
4. Subscriber:
● Subscribers are entities or components that register interest in specific
types of events and receive notifications when those events occur.
● They subscribe to event topics or channels to receive relevant event data.
● Example: A mobile application or dashboard interface used by
homeowners to receive alerts when the temperature in different rooms
exceeds predefined thresholds.
5. Event Channel/Topic:
● Event channels or topics are logical channels through which events are
organized and delivered to subscribers.
● They provide a means of categorizing events based on their type, source,
or other attributes.
● Example: A "temperature_alerts" topic in the event notification system that
delivers temperature-related events to subscribed clients.
6. Event Dispatcher:
● The event dispatcher is responsible for routing events from the event
notification system to the appropriate subscribers based on their
subscriptions.
● It ensures that events are delivered to the correct destinations in a timely
manner.
● Example: A component within the event notification system that routes
temperature events to subscribers based on their geographical location or
notification preferences.
7. Event Consumer:
● Event consumers are the ultimate recipients of event notifications. They
process and act upon the received events based on their application logic.
● Example: An automation system within the smart home that adjusts
thermostat settings or sends alerts to homeowners based on received
temperature events.
16)Create distributed objects for client and server and explain the establishment of
communication between them using java. [7M, CO3, Apply]

1. Remote Interface:
● Define an interface that extends java.rmi.Remote.
● Declare the methods that the client can invoke remotely.
2. Implement Remote Interface:
● Create a class that implements the remote interface.
● Implement the methods declared in the interface.
3. Create Server Application:
● Create a server application that exports the remote object and binds it to
the RMI registry.
● Start the RMI registry to listen for client requests.
Client Side:

1. Look Up Remote Object:


● In the client application, look up the remote object from the RMI registry
using its name or URL.
2. Invoke Remote Method:
● Once the remote object is obtained, invoke its methods as if they were
local.

Explanation:

● The server hosts remote objects that provide certain functionalities.


● The client accesses these functionalities by invoking methods on the remote
objects.
● Java RMI handles the communication between client and server transparently,
allowing method calls to be made across the network.

Server Side:
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

// Define a remote interface


interface RemoteService extends Remote {
String sayHello() throws RemoteException;
}

// Implement the remote interface


class RemoteServiceImpl extends UnicastRemoteObject implements RemoteService {
protected RemoteServiceImpl() throws RemoteException {
super();
}

// Implement the method defined in the remote interface


public String sayHello() throws RemoteException {
return "Hello from server!";
}
}

// Server class
public class Server {
public static void main(String[] args) {
try {
// Create and export the remote object
RemoteService service = new RemoteServiceImpl();

// Create RMI registry on default port (1099)


Registry registry = LocateRegistry.createRegistry(1099);

// Bind the remote object to the RMI registry


registry.bind("RemoteService", service);

System.out.println("Server started.");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}

Client Side:

import java.rmi.Naming;

// Client class
public class Client {
public static void main(String[] args) {
try {
// Look up the remote object from the RMI registry
RemoteService service = (RemoteService)
Naming.lookup("//localhost/RemoteService");

// Invoke remote method


String response = service.sayHello();
System.out.println("Response from server: " + response);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}

17)Explain the features of distributed object model


1. Transparency: Hides the complexity of network communication, making remote
objects appear as local objects to the programmer.
2. Location Transparency: Objects can be located anywhere on the network, and
clients do not need to know their physical location.
3. Access Transparency: Allows clients to access remote objects using the same
method as local objects, without worrying about network protocols.
4. Concurrency Transparency: Handles concurrency issues transparently, allowing
multiple clients to access remote objects concurrently.
5. Failure Transparency: Handles network failures and system crashes gracefully,
ensuring robustness and reliability.
18)Explain design issues and implementation of RMI?

Design Issues:

1. Interface Definition:
● Define the remote interface that extends java.rmi.Remote.
● Declare methods in the interface that can be invoked remotely.
2. Object Serialization:
● Ensure that objects passed between client and server are serializable.
● Use java.io.Serializable interface for classes that need to be serialized.
3. Naming and Registry:
● Use the RMI registry to bind remote objects and make them accessible to
clients.
● Ensure that clients can look up remote objects using a well-known name
or URL.
4. Security:
● Implement security measures to prevent unauthorized access and ensure
data integrity.
● Use authentication, encryption, and access control mechanisms provided
by Java security APIs.
5. Exception Handling:
● Handle RemoteExceptions and other exceptions gracefully to ensure
robust error handling.
● Define custom exception classes to convey meaningful error messages to
clients.

Implementation:

1. Remote Interface:
● Define a remote interface that extends java.rmi.Remote.
● Declare methods that need to be invoked remotely.
2. Remote Object Implementation:
● Create a class that implements the remote interface.
● Extend java.rmi.server.UnicastRemoteObject to make the object remotely
accessible.
3. Server Application:
● Create a server application that instantiates and exports the remote
object.
● Bind the remote object to the RMI registry using java.rmi.registry.Registry.
4. Client Application:
● Create a client application that looks up the remote object from the RMI
registry.
● Cast the remote object to the remote interface and invoke its methods.
5. Exception Handling:
● Handle RemoteExceptions and other exceptions in both server and client
applications.
● Implement error recovery and retry mechanisms if necessary.

You might also like