100 likes | 285 Views
Session Beans. Celsina Bignoli bignolic@smccd.net. Session Beans. reusable components that implement business logic business rules algorithms workflows. Session Bean Lifetime. short lived object lifetime of a session of the client code calling the bean
E N D
Session Beans Celsina Bignoli bignolic@smccd.net
Session Beans • reusable components that implement • business logic • business rules • algorithms • workflows
Session Bean Lifetime • short lived object • lifetime of a session of the client code calling the bean • client code calls a session bean container create instance of the bean • client disconnects container may destroy the bean instance • not shared between multiple clients • non-persistent objects • do not survive server crashes
Types of Session Bean • Stateful session beans • retain (conversational) state for a client that span several method requests or transactions • Stateless session beans • they do not hold state between requests • they only hold state for a single method call • container may destroy them after servicing a request or use the same bean for all clients • All instances are exactly the same
Examples • Stateless Session Bean Examples • Credit card verification • Data compression • Stateful Session Bean Examples • Shopping Cart • Banking
Pooling Stateful Session Beans • Pooling stateful beans is more complicated since they retain a state for a particular client • Yet, resources on the server are limited, some pooling is required • Application servers use a mechanism similar to OS swapping • When a bean is not in use its state is passivated, i.e. swapped out and saved on hard disk • When the original client calls a method the state for that client is activated, i.e. it is swapped in
Pooling Stateful Session Beans(2) • The bean receiving the activated state might not be the original bean • Passivation/activation can entail input/output bottleneck • Passivation can occur at any time and it is responsibility of the container • Passivation cannot occur on beans involved in a transaction • Most container use a Most Recently Used (MRU) passivation strategy • Containers usually use a just-in-time algorithm to activate beans
Conversational State Rules • During passivation the EJB container uses serialization to convert a Bean’s conversational state to a bit-blob and stores it to disk • Possible because javax.ejb.EnterpriseBean extends java.io.Serializable
Passivation 2: Pick the least recently used bean EJB Object Enterprise Bean Remote interface 3: Call ejbPassivate() 1:Invoke Business method 4: Serialize the bean state 5:Store passivated Bean state Client Other Enterprise Beans
Activation 3: Reconstruct bean EJB Object Enterprise Bean Remote interface 4: Call ejbActivate() 1:Invoke Business method 5 : Invoke business method 2: Retrieve passivated state Client Other Enterprise Beans