Client View of Bean  «Prev  Next»

Lesson 2The client-bean relationship
Objective Relationship between Client and the EJB.

Relationship between Client and EJB

Describe in detail the relationship between the client and the EJB.
A client makes use of the services of a bean. In this lesson we look at the entities involved and how they enable this to happen.
Sequence of Operations The series of images below shows each of the entities involved in the sequence of operations. Each diagram illustrates the next step in the sequence, such that the client can:
  1. Look up the bean's information in the Name Service
  2. Create an instance of the bean to use
  3. Execute the bean instance's methods
  4. Remove the bean instance

1) The container creates the home object; the home objects listens for client requests.
1) The container creates the home object; the home objects listens for client requests.

2)The container register the name of the service and uploads the home object stub to the Name Service.
2) The container registers the name of the service and uploads the home object stub to the Name Service. The stub is a remote reference and contains the information to access the bean's home object.

3) The client looks up the service name and downloads home object's stub
3) The client looks up the service name and downloads home object's stub.


4) Using the home object's stub, the client requests the home object to create the bean.
4) Using the home object's stub, the client requests the home object to create the bean; the container creates both the bean and its the EJBObject; it then returns the EJBObject's remote reference to the client.

5) The client uses the remote reference to the EJBObject to invoke the business methods of the bean.
5) The client uses the remote reference to the EJBObject to invoke the business methods of the bean.

6) The client requests the EJBOjbect to remove the bean and its associated remote object.
6) The client requests the EJBOjbect to remove the bean and its associated remote object.

  1. The container creates the home object; the home objects listens for client requests.
  2. The container registers the name of the service and uploads the home object stub to the Name Service. The stub is a remote reference and contains the information to access the bean's home object.
  3. The client looks up the service name and downloads home object's stub.
  4. Using the home object's stub, the client requests the home object to create the bean; the container creates both the bean and its the EJBObject; it then returns the EJBObject's remote reference to the client.
  5. The client uses the remote reference to the EJBObject to invoke the business methods of the bean.
  6. The client requests the EJBOjbect to remove the bean and its associated remote object.


home Interface

The home interface is defined by the bean developer. However, by the time the bean instance is ready in the container, the deployment process will have created the home object class and the container will have instantiated it. The home object listens on the network. The stub downloaded from the Name Service is the stub to the home object.
The EJBObject object is a proxy for the bean. Do not confuse this proxy with the EJBObject stub, downloaded to the client, which is a proxy for the EJBObject itself. It is built at deployment time to make the bean's business methods available to the client. It is the part of the container that hides the actual bean instance from the client. The only access to the bean instance is through its specific EJBObject. This allows the container to interpose itself between the client's call and the invocation of the method.
The EJBObject also contains methods to remove beans, compare beans, and acquire a handle[1] to the bean. The home object is sometimes known as the bean factory[2] . In the next lesson I will explain how you write the code for the home interface that is used by the container to build the home object. In addition, you will be introduced to the home object and the home interface it implements.

[1]Handle: An object which contains all the information required to access an existing remote session bean.
[2]Bean factory: That part of an object monitor that is responsible for creating (manufacturing) the bean when required.

SEMrush Software