EJB Architecture  «Prev 

EJB Proxy Pattern

Java RMI

In Java RMI, the clients of a remote object did not call methods on the remote object directly. Instead, they call methods on a stub, which passes the method call information over the network to the skeleton, which calls the method on the remote object. The EJB model extends this notion by introducing the idea of the EJB container as an additional element in the interaction. The container has two main functions:
  1. It intercepts all method calls made by the client and carries out various actions (concerned with security and transaction management, among other things) before delegating them to an instance of the implementation class itself. That is, the container provides proxies that isolate the EJB's implementation class from its clients.
  2. It provides general services to the EJB, such as database connection pooling.

1) The client invokes getBalance() on the stub
The client invokes getBalance() on the stub

2) The stub marshals the method call into the appropriate wire format message and sends it across the network
The stub marshals the method call into the appropriate wire format message and sends it across the network to the remote object's skeleton.

3) The skeleton listens on the network for messages
The skeleton listens on the network for messages. When the message arrives, the skeleton un-marshals it.

4) The skeleton invokes the getBalance() method of the remote object.
The skeleton invokes the getBalance() method of the remote object.

5) Remote object processes the call to getBalance() and returns the balance
Remote object processes the call to getBalance() and returns the balance

6) Return value is marshalled by the skeleton and returned to the stub
Return value is marshalled by the skeleton and returned to the stub

7) The stub un-marshals the return and passes it back to the client.
The stub un-marshals the return and passes it back to the client.