Looking Under the Hood of a Stateless Session Bean

Figure 5.1 shows the interactions between the client, the EJB container, and the stateless session bean.

Figure 5.1. Under the hood of a stateless session bean.


The following steps describe the sequence of interactions in detail:

1.
At startup, the EJB container registers all the deployed enterprise beans, including stateless session beans, with the Java Naming and Directory Interface (JNDI) service, based on the JNDI name specified in the deployment descriptor.

2.
The EJB container decides to instantiate a stateless session bean based on the caching policy. In this example, the EJB container instantiates the SignOn bean using the Class.newInstance("SignOnEJB.class") and then calls the methods setSessionContext() and ejbCreate() on the instance. Now the bean is ready to serve any client.

3.
The client looks up the home interface of the deployed enterprise bean via JNDI. For example, the remote home interface for the SignOn stateless bean can be located using the following code segment:

Context initialContext = new InitialContext();
Object obj = initialContext.lookup("day05/SignOn");
SignOnHome signOnHome = (SignOnHome)
javax.rmi.PortableRemoteObject.narrow(obj, SignOnHome.class);

4.
The client uses the remote home interface to create a remote sign-on session object. For example:

SignOn signOn =  (SignOn)signOnHome.create();

5.
The client calls a business method on the remote object. For example, the client verifies the login name and password as follows:

signOn.validateUser("student1", "password1");

The container assigns a stateless session bean from the instance pool to service the client request. The container calls the appropriate business method on the stateless session object instance. For example, the EJB container calls the validateUser() method on the stateless session bean instance. After the bean services the client method call, the container puts the session bean back into the instance pool.

6.
The EJB container decides to terminate the session bean instance by calling the ejbRemove() method of the bean instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.119.81