|Skip Navigation Links|
|Exit Print View|
|Oracle GlassFish Server 3.1-3.1.1 High Availability Administration Guide|
Stateful session beans (SFSBs) contain client-specific state. There is a one-to-one relationship between clients and the stateful session beans. At creation, the EJB container gives each SFSB a unique session ID that binds it to a client.
However, if an SFSB participates in a bean-managed transaction, the transaction might be committed in the middle of the execution of a bean method. Since the bean’s state might be undergoing transition as a result of the method invocation, this is not an appropriate time to checkpoint the bean’s state. In this case, the EJB container checkpoints the bean’s state at the end of the corresponding method, provided the bean is not in the scope of another transaction when that method ends. If a bean-managed transaction spans across multiple methods, checkpointing is delayed until there is no active transaction at the end of a subsequent method.
The state of an SFSB is not necessarily transactional and might be significantly modified as a result of non-transactional business methods. If this is the case for an SFSB, you can specify a list of checkpointed methods, as described in Specifying Methods to Be Checkpointed
If a distributable web application references an SFSB, and the web application’s session fails over, the EJB reference is also failed over.
If an SFSB that uses session persistence is undeployed while the GlassFish Server instance is stopped, the session data in the persistence store might not be cleared. To prevent this, undeploy the SFSB while the GlassFish Server instance is running.
To enable availability for the EJB container use the asadmin set command to set the following three properties for the configuration:
For example, if config1 is the configuration name, use the following commands:
asadmin> set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service. ejb-container-availability.availability-enabled="true" asadmin> set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service. ejb-container-availability.sfsb-persistence-type="file" asadmin> set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service. ejb-container-availability.sfsb-ha-persistence-type="replicated"
If availability is disabled, the local file system is used for SFSB state passivation, but not persistence. To change where the SFSB state is stored, change the Session Store Location setting in the EJB container. For information about configuring store properties, see the Administration Console online help.
You can enable SFSB availability for an individual application or EJB module during deployment:
If you are deploying with the Administration Console, check the Availability Enabled checkbox.
To enable availability and select methods to be checkpointed for an individual SFSB, use the glassfish-ejb-jar.xml deployment descriptor file.
To enable high availability session persistence, set availability-enabled="true" in the ejb element.
Example 10-1 Example of an EJB Deployment Descriptor With Availability Enabled
<glassfish-ejb-jar> ... <enterprise-beans> ... <ejb availability-enabled="true"> <ejb-name>MySFSB</ejb-name> </ejb> ... </enterprise-beans> </glassfish-ejb-jar>
If enabled, checkpointing generally occurs after the bean completes any transaction, even if the transaction rolls back. To specify additional optional checkpointing of SFSBs at the end of non-transactional business methods that cause important modifications to the bean’s state, use the checkpoint-at-end-of-method element in the ejb element of the glassfish-ejb-jar.xml deployment descriptor file.
The non-transactional methods in the checkpoint-at-end-of-method element can be:
create() methods defined in the home interface of the SFSB, if you want to checkpoint the initial state of the SFSB immediately after creation
For SFSBs using container managed transactions only, methods in the remote interface of the bean marked with the transaction attribute TX_NOT_SUPPORTED or TX_NEVER
For SFSBs using bean managed transactions only, methods in which a bean managed transaction is neither started nor committed
Any other methods mentioned in this list are ignored. At the end of invocation of each of these methods, the EJB container saves the state of the SFSB to persistent store.
Note - If an SFSB does not participate in any transaction, and if none of its methods are explicitly specified in the checkpoint-at-end-of-method element, the bean’s state is not checkpointed at all even if availability-enabled="true" for this bean.
For better performance, specify a small subset of methods. The methods should accomplish a significant amount of work or result in important modification to the bean’s state.
Example 10-2 Example of EJB Deployment Descriptor Specifying Methods Checkpointing
<glassfish-ejb-jar> ... <enterprise-beans> ... <ejb availability-enabled="true"> <ejb-name>ShoppingCartEJB</ejb-name> <checkpoint-at-end-of-method> <method> <method-name>addToCart</method-name> </method> </checkpoint-at-end-of-method> </ejb> ... </enterprise-beans> </glassfish-ejb-jar>