Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days

Now you will look at the different components that constitute a stateless session EJB.

Remote Interface

The remote interface, as you saw yesterday, contains a set of business methods that constitute the service that the stateless session bean provides. The remote interface of a stateless session bean is exactly the same as the remote interface for a stateful session bean and extends the javax.ejb.EJBObject interface.

The code snippet given here is exactly like the code snippet for the remote interface of a stateful session bean:

public interface MyRemoteIF extends javax.ejb.EJBObject { public void businessMethod1() throws javax.rmi.RemoteException { } public String businessMethod2() throws javax.rmi.RemoteException { } }

Home Interface

The home interface of a stateless session bean contains the factory methods used by a client application to initiate and control the life cycle of the stateless session bean. The home interface contains the create() and remove() methods that are invoked by a client application of the EJB. The primary difference between a stateless session bean and a stateful session bean is that the stateless session bean has only one create() method in the home interface without any parameters. The create() method cannot be overloaded in the home interface because a stateless session bean does not maintain any state information about the EJB client application and hence does not require any overloaded create() method with parameters. The session bean's home interface extends the javax.ejb.EJBHome interface. The provider of the EJB container supplies the implementation class that implements the methods in the session bean's remote interface. A code snippet is given here:

public interface MyHomeIF extends javax.ejb.EJBHome { public MyRemoteIF create() throws javax.rmi.RemoteException { } public MyRemoteIF create() throws javax.rmi.RemoteException { } }

Session Bean Implementation Class

The session bean implementation class for a stateless session bean is similar to the one that you studied for a stateful session bean. The differences are in the methods that are implemented in the stateless session bean class. The stateless session bean class provides the functionality for the business methods defined in the remote interface of the stateless bean and the ejbCreate() and ejbRemove() life-cycle methods. Because the stateless session bean is not activated or passivated, the ejbActivate() and ejbPassivate() methods are not provided. Here as well, the provider of the EJB container generates an intermediate implementation class that intercepts requests from the client application and delegates the business methods:

public interface MyBean implements javax.ejb.SessionBean { public void ejbCreate() throws javax.rmi.RemoteException { ... // functionality as required } public void setSessionContext(javax.ejb.SessionContext) throws javax.rmi.RemoteException { ... // functionality as required } public void ejbRemove() throws javax.rmi.RemoteException { ... // functionality as required } public void businessMethod1() throws javax.rmi.RemoteException { ... // business method functionality as required } public String businessMethod2() throws javax.rmi.RemoteException { ... // business method functionality as required } }

After this discussion of stateless session beans, you are now ready to work on your sample application.

Категории