ORB aka object request broker, is the java implementation of the OMG's CORBA (Common Object Request Broker Architecture) specification, which enables the usage of remote objects usable like the local objects. It also lets objects communicate with each other independent of the platform and languages used to implement those objects.
The ORB is implemented as part of the java virtual machine and plays an integral part in the application server runtime environment. In the client/server communication, the ORB provides primarily the following functionality -
1) Provide a framework for clients to locate the remote objects on the server and invoke requests on them.
2) Manage the connections.
3) Manage the request and response messages to/from the remote Java objects.
4) Marshal/Demarshal, based on the CDR (Common Data Representation) , the messages sent over the wire.
Provide a framework for clients to locate the remote objects on the server and invoke requests
For a client to be able to successfully locate the remote object on the server, the remote object needs to be "registered to a naming registry" and "exported". The "bind" call will ensure that the remote object is registered to a naming registry and "javax.rmi.PortableRemoteObject.exportObject()" will ensure that the remote object is exported i.e. it is ready to be invoked. Once, the client does a look-up, "javax.rmi.PortableRemoteObject.narrow()" will have to be called on the reference returned by the look-up. The object returned by the "javax.rmi.PortableRemoteObject.narrow()" will be used to invoke the remote object.
Now lets look at what internally happens in the ORB when an javax.rmi.PortableRemoteObject.exportObject() -
1) The tie and stub classes associated with the remote implementation are loaded.
2) The tie class to the remote implementation class and tie class to the stub class are cached for future/faster look-up.
The "javax.rmi.PortableRemoteObject.narrow()" is fairly simple, it just checks whether the object returned by the look-up can be casted to the remote interface i.e. the object should extend javax.rmi.CORBA.Stub and implement the remote interface. The reference returned by the javax.rmi.PortableRemoteObject.narrow() will be used to invoke the remote function.
The stub and tie play a key role in the remote communication. The reference returned by the javax.rmi.PortableRemoteObject.narrow() is actually a stub. As the stub implements the "remote interface", the implemented remote functions will invoke the ORB to send the data to the server and receive the response from the server. At the server side, the data will be received by the ORB. The ORB will identify the corresponding tie and the tie will invoke the remote function implementation. Once the reply is received, the tie will pass the response data to the ORB and subsequently the data will sent to the stub at the client side.
In the next blog, we will explore how the ORB manages the connections.