2080 4

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]

Advanced Java ProgrammingChapter 8: RMI and CORBAIntroduction to CORBA, RMI vs CORBA, Architecture of CORBA,

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 rmic compiler 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

FeatureRMICORBA
Full FormRemote Method InvocationCommon Object Request Broker Architecture
LanguageJava only (Java-specific)Language independent (C++, Java, Python, etc.)
PlatformJava Virtual Machine (JVM) dependentPlatform and language independent
ProtocolUses JRMP (Java Remote Method Protocol)Uses IIOP (Internet Inter-ORB Protocol)
Ease of UseSimple and easy to implementComplex to implement and configure
Object BrokerRMI Registry acts as brokerObject Request Broker (ORB) is used
Interface DefinitionDefined using Java interfacesDefined using IDL (Interface Definition Language)
PerformanceFaster within Java environmentRelatively slower due to overhead
InteroperabilityLimited to Java applications onlyHigh interoperability across languages and platforms
StandardJava 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.