When one service passes an object which is the proxy for another service, the RMI callback mechanism occurs. The methods will be invoked by the recipient in the object it received and be calling back to the calling point. The stub contains the information that is needed to call back to server at the time of the need.
During communication between two machines through RPC or RMI, parameters are packed into a message and then sent over the network. This packing of parameters into a message is called marshalling. On the other side these packed parameters are unpacked from the message which is called unmarshalling.
Server side stub is refered to as a skeleton.
The role of the stubs is to marshal and unmarshal the messages that are sent and received on the client or the server side.
The Stub/Skeleton Layer:
The stub/skeleton layer sits in between application layer and the rest of the RMI system and acts as an interface. This layer transmits the information to remote layer. This transmission is done through the marshalling of streams. These streams performs the object serialization.
A stub is a remote object at the client-side. This stub implements all the interfaces which remote object implementation supports.
A skeleton is a remote object at the server-side. This stub consists of methods that invokes dispatch calls to the remote implementation of objects.
The Remote Reference Layer:
The lower level transport interfaces is dealt by this layer. This layer carries a specific remote reference protocol independent of stub and skeletons.
Every remote object is implemented by choosing their individual remote reference subclasses.
The Transport Layer:
The transport layer sets up the connections to remote address spaces, manages them, monitors the connection liveliness, and listens the incoming calls.
The transport layer maintains the remote object’s table available in the address space, in a table. For incoming calls, the transport layer establishes a connection. It locates the target dispatcher of the remote calls and passes the connection to the dispatcher.