RMI is a java technology that enables you to access an object that doesn’t belong to your local heap. In another way It allows one JVM to communicate with another JVM to invoke an object method on it.
-How does that happen??
The applications using RMI are divided in two categories ( Clients-Servers) Clients want to invoke the method on the remote Server which has the method. To make it Simple the Server Keeps telling clients I am (Server’s name) and clients are looking for a specific Server name thats called lookup service. But before that happens all servers register on an application called rmiregistry (many servers can connect to same registry) so when a client request to connect to a specific server it connects to the registry and look for his server. Unlike classic Socket design you don’t have to specify the machine you are working on by using an address to connect your server thats why RMI is considered a tolerant system so servers can run on any machine on the network ( Note : RMI servers defualt port is 1099).
Now Since we’ve had some introduction to RMI let’s get to our topic – Server types-. Here I am going to talk about 3 types ( Unicast servers – Activation servers – RMI/IIOP servers).I’ll avoid going deep here instead I will give you a keywords to search for if you are interested.
Unicast Servers :-
In RMI remote objects are remote servers which implement a remote interface and it’s exported to RMI system. RMI provides several base classes which can be used to define server classes like Remote Object – Remote Server – UnicastRemoteObject.
Our UnicastRemoteObject supports a simple transient point to point RMI servers. so it’s TCP/IP server which listens to a TCP port.
To get to some implementation. Our Unicast remote object server may extend the UnicastRemoteObject class and as any other servers it must extend Remote interface directly or indirectly. The previous sentence comes up with a question..can it extend another class??-Yes it can extend RemoteObject or RemoteServer .
Unicast servers is automatically exported (Registered on the rmiregistry) on construction. Derived classes can choose between 3 ways to export the server
- export on a default port chosen on runtime (Port no.1099) which looks like this exportObject( Remote Server)
- export on specified port which must have registry waiting on it unless it will throw a ConnectionException: connection refused because there was no registery there so it was a locked port. And it looks like this exportObject( Remote Server, int port);
- exported on a specified port with a specified Client and server Socket-Factories (RMIClientSocketFactory – RMIServerSocketFactory)
Activation Servers :-
Unlike unicast servers which are unreferenced when they exit and the remote reference does no longer to anything and everytime the client has to log to the server has to go through the stub to gain the remote reference. The Activation servers removes these restrictions, the remote reference of an activation server remains valid or working as long as it’s server is registered. And once the reference gets a request the server restars if it’s not already running. The activation server also exports itself on construction and registered by Activatable.register . Activation servers are registered to specific Activation Group and activation group is a group of zero.
When a client recives a stub of an activatable server this stub contains a special form of RemoteRef which intially contains null. And real RemoteRef and the ActivationID for the Remote Object when the stub is first used it interact with the activation system deamon (rmid) and the result is a live RemoteRef which the stub can use them to invoke the remote method.
RMI/IIOP Servers :-
IIOP is a transport protocol adopted by the object management system Group (www.omg.org) for CORBA. RMI over IIOP allows Java programmers to use RMI interfaces but use IIOP as the underlying transport layer.
Using RMI over IIOP allows the developers to work using java with out having to use CORBA IDL. COBRA IDL can be produced automatically from remote RMI/IIOP interfaces, then they can be generated into stubs and skeletons.
PortableRemoteObject is a class for RMI servers which communicate over RMI/IIOP it’s same as UnicastRemoteObject..it provides exportObject and unexportObject. The difference is
- ProtableRemoteObject communicate via IIOP not JRMP
- PortableRemoteObject Doesn’t participate in DGC(Distributed Garbage collection)
- PortableRemoteObject must be complied with rmic with <option>
- PortableRemoteObject doesn’t support explict port number or Socket-Factories