CSC419 ยท 2080 ยท 5 marks
List the steps to create an RMI application. Differentiate between RMI and CORBA.
List the steps to create an RMI application. Differentiate between RMI and CORBA. [5]
Quick answer
RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed applications in Java, allowing an object to invoke methods on an object running in another JVM.
RMI Application Creation Steps and RMI vs CORBA
Steps to Create an RMI Application
RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed applications in Java, allowing an object to invoke methods on an object running in another JVM. The following steps are required:
Step 1: Define the Remote Interface
- Create an interface that extends
java.rmi.Remote - Declare all methods that can be invoked remotely
- Each method must throw
java.rmi.RemoteException
public interface MyRemote extends Remote {
public String sayHello() throws RemoteException;
}
Step 2: Implement the Remote Interface
- Create a class that implements the remote interface
- Extend
UnicastRemoteObject - Implement all declared remote methods
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {
public String sayHello() throws RemoteException {
return "Hello from Server!";
}
}
Step 3: Generate Stub and Skeleton
- As noted in the reference, RMI uses two objects: stub and skeleton for remote communication
- Stub: Client-side proxy that forwards calls to the remote object
- Skeleton: Server-side object that receives calls and passes them to the actual object
- Use
rmiccompiler to generate these:rmic MyRemoteImpl
Step 4: Start the RMI Registry
- Start the RMI registry service (acts as a naming service)
- Run:
rmiregistry(default port 1099)
Step 5: Register the Remote Object (Server Side)
- Bind the remote object to the RMI registry using
Naming.rebind()
MyRemote obj = new MyRemoteImpl();
Naming.rebind("MyRemoteService", obj);
Step 6: Write and Run the Client
- Look up the remote object from the registry using
Naming.lookup() - Invoke remote methods through the stub
MyRemote obj = (MyRemote) Naming.lookup("rmi://localhost/MyRemoteService");
System.out.println(obj.sayHello());
Difference Between RMI and CORBA
| Feature | RMI | CORBA |
|---|---|---|
| Full Form | Remote Method Invocation | Common Object Request Broker Architecture |
| Language | Java only (Java-specific) | Language independent (C++, Java, Python, etc.) |
| Platform | Java Virtual Machine (JVM) dependent | Platform and language independent |
| Protocol | Uses JRMP (Java Remote Method Protocol) | Uses IIOP (Internet Inter-ORB Protocol) |
| Ease of Use | Simple and easy to implement | Complex to implement and configure |
| Object Broker | RMI Registry acts as broker | Object Request Broker (ORB) is used |
| Interface Definition | Defined using Java interfaces | Defined using IDL (Interface Definition Language) |
| Performance | Faster within Java environment | Relatively slower due to overhead |
| Interoperability | Limited to Java applications only | High interoperability across languages and platforms |
| Standard | Java standard (Sun/Oracle) | Industry standard by OMG (Object Management Group) |
Summary
RMI is simpler and best suited for pure Java distributed applications, while CORBA is more powerful and suitable for heterogeneous, multi-language distributed systems requiring high interoperability.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.