Distributed ProgrammingSolutions
Distributed ProgrammingSolutions
Classification of Middleware:
Communication Middleware: This type of middleware focuses on
facilitating communication between distributed components or
systems. Examples include message-oriented middleware (MOM), remote
procedure call (RPC) middleware, and distributed object middleware.
12) Compare and contrast the four main deployment models for the cloud.
a) Public Cloud:
- Public cloud services are offered by third-party providers
over the internet.
b) Private Cloud:
- Private cloud infrastructure is operated solely for a single
organization.
c) Hybrid Cloud:
- Hybrid cloud combines public and private cloud resources,
allowing data and applications to be shared between them.
d) Community Cloud:
- Community cloud infrastructure is shared among several
organizations with common concerns (e.g., industry-specific
regulations, security requirements).
Exercise
We have two services implanted in from of objects: ObjectString and
ObjectCalculation. The first realizes string operations and the second arithmetic
operations. For simplicity, ObjectString has only one method NbOccurrences which
ObjectCalculation has a single method add which sums two numbers. The code of these
return a+b;
}
public int NbOccurrences(String c, String mot) {
int length=OriginalString.length();
int Nb=0;
Nb++;
}
return Nb;
1. We wish these methods to be remotely accessible. Give the structure of the interfaces that will
be share by clients and servers knowing that each method belongs to a distinct object.
To make the methods `add` and `NbOccurrences` remotely accessible, we
need to define interfaces for both `ObjectString` and
`ObjectCalculation`. These interfaces will be shared by clients and
servers to ensure consistency in method signatures and communica tion.
Below is the structure of the interfaces:
Explanation:
import java.rmi.RemoteException;
public class ObjectCalculationImpl implements ObjectCalculationInterface
{
try {
return a + b;
} catch (Exception e) {
try {
int Nb = 0;
if (mot.substring(i, i + 1).equals(c))
Nb++;
return Nb;
} catch (Exception e) {
}
Explanation:
- This ensures that any exceptions occurring during the remote method
invocation are properly handled and propagated back to the client.
3. Given the fact that, any java method called by a remote java program must belong to a remote
object, write the java classes that represent the object ObjectString and the object
ObjectCalculation respectively.
-To represent the objects `ObjectString` and `ObjectCalculation` as
remote objects in Java, we can use Java Remote Method Invocation (RMI).
Each object should implement a remote interface that defines the methods
accessible remotely. Here are the Java classes for the remote objects:
import java.rmi.Remote;
import java.rmi.RemoteException;
// Implementation of ObjectString
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
super();
}
@Override
int Nb = 0;
if (String.valueOf(mot.charAt(i)).equals(c))
Nb++;
return Nb;
// Implementation of ObjectCalculation
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
super();
@Override
return a + b;
i. ObjectStringImpl.java:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
super();
@Override
int Nb = 0;
if ((mot.substring(i, i + 1)).equals(c))
Nb++;
return Nb;
}
}
ii. ObjectCalculationImpl.java :
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
super();
@Override
return a + b;
5. Write the commands to type on the computer user.coltech.cm to make available the methods
add and NbOccurrences for remote invocation on the port 2001.
To make the methods `add` and `NbOccurrences` available for remote
invocation on port 2001 on the computer `user.coltech.cm`, you would
typically follow these steps:
java -Djava.rmi.server.codebase=file:/path/to/classes/ -
Djava.rmi.server.hostname=user.coltech.cm ObjectStringImpl
java -Djava.rmi.server.codebase=file:/path/to/classes/ -
Djava.rmi.server.hostname=user.coltech.cm ObjectCalculationImpl
6. Write the java client program that will run on another computer.
To create a Java client program that interacts with the remote services
ObjectString and ObjectCalculation, we'll use Remote Method Invocation
(RMI) for communication between the client and the server. Below is the
Java client program:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
try {
} catch (Exception e) {
e.printStackTrace();
}}