CS6320:  SW Engineering of Web Based Systems

 

Session Beans

(for OLD EJB Session Bean 2.* information)

 

Characteristics:

  • Represent a "conversation" between a "client" and server.
  • Execute on behalf of a single client.
    • Can not be shared by more than one client at the same time.
    • Also can not be called by same client using mutliple threads.
  • Can be transaction-aware and use security
  • Do not directly represent data in a database
    • but, can access and update data on behalf of client
  • Are usually relatively short-lived.
    • should be removed by client or when EJB container shuts down or crashes.

Session Bean Example

 

 

//STEP 1 THE INTERFACE CLASS - publishes the business classes.
package helloworld;
/**
* Interface of the HelloWorld example.
* @author You
*/
public interface HelloWorldInterface {
      /**                               
        * Hello world.            
       */                                
         void helloWorld();
}

 

//STEP 2 THE BEAN CLASS - creates the buisness classes.

This bean will be a stateless session bean, thus the class will be annotated with @Stateless annotation.

The interface must be a remote interface to be available for remote clients. This is done by using the @Remote annotation.

package helloword;
import javax.ejb.Remote;
import javax.ejb.Stateless;

/**
* Business code for the HelloWorld interface.
* @author Me
*/

@Stateless
@Remote(HelloWorldInterface.class)
public class HelloWorldBean implements HelloWorldInterface {
    /**
      * Hello world implementation. */
       public void helloWorld() {
                   System.out.println("Hello world !");

        }

}

Passivation and Activation

  • Only for Stateful Session Beans

  • Passivation = (@Passsivation activation tag before method)mechanism by which container stores bean's state into a "back store" (file system or database).
    • container starts as soon as number of allocated statefull session beans exceeds a threshold (specified in vendor deployment descriptor) and for some containers can specify max idle time after which will passivate.

      e.g. WebLogic server:

      <stateful-session-cache>
            <max-beans-in-cache>1000</max-beans-in-cache>
      </stateful-session-cache>

    • Serializes all non-transient variables to a persistent store


  • Activation = (@Activation tag before method)mechanism by which container activates a passivated instance when bean's client decides to continue interactions with a bean.

 

© Lynne Grewe