This chapter explains how to enable and configure high availability session persistence.
Application Server provides high availability session persistence through failover of HTTP session data and stateful session bean (SFSB) session data. Failover means that in the event of an server instance or hardware failure, another server instance takes over a distributed session.
A distributed session can run in multiple Sun Java System Application Server instances, if:
Each server instance has access to the same session state data. Application Server provides the following types of high availability storage for HTTP session and stateful session bean data:
In-memory replication on other servers in the cluster. In-memory replication is enabled by default with the cluster profile.
The use of in-memory replication requires the Group Management Service (GMS) to be enabled. For more information about GMS, see Group Management Service.
If server instances in a cluster are located on different machines, ensure that the following prerequisites are met:
To ensure that GMS and in-memory replication function correctly, the machines must be on the same subnet.
To ensure that in-memory replication functions correctly, the system clocks on all machines in the cluster must be synchronized as closely as possible.
High-availability database (HADB). For information about how to enable this database, see configure-ha-cluster(1).
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
Each server instance has the same distributable web application deployed to it. The web-app element of the web.xml deployment descriptor file must contain the distributable element.
The web application uses high-availability session persistence. If a non-distributable web application is configured to use high-availability session persistence, the server writes an error to the log file.
The web application must be deployed using the deploy or deploydir command with the --availabilityenabled option set to true. For more information on these commands, see deploy(1) and deploydir(1).
When a session fails over, any references to open files or network connections are lost. Applications must be coded with this restriction in mind.
You can only bind certain objects to distributed sessions that support failover. Contrary to the Servlet 2.4 specification, Sun Java System Application Server does not throw an IllegalArgumentException if an object type not supported for failover is bound into a distributed session.
You can bind the following objects into a distributed session that supports failover:
Local home and object references for all EJB components.
Colocated stateless session, stateful session, or entity bean reference .
Distributed stateless session, stateful session, or entity bean reference.
JNDI Context for InitialContext and java:comp/env.
UserTransaction objects. However, if the instance that fails is never restarted, any prepared global transactions are lost and might not be correctly rolled back or committed.
Serializable Java types.
You cannot bind the following object types into sessions that support failover:
JDBC DataSource
Java Message Service (JMS) ConnectionFactory and Destination objects
JavaMail™ Session
Connection Factory
Administered Objects
Web service reference
In general, for these objects, failover will not work. However, failover might work in some cases, if for example the object is serializable.
This section explains how to set up high availability session persistence, with the following topics:
High availability session persistence is incompatible with dynamic deployment, dynamic reloading, and auto-deployment. These features are for development, not production environments, so you must disable them before enabling HA session persistence. For information about how to disable these features, see Sun Java System Application Server 9.1 Application Deployment Guide.
Create an Application Server cluster.
For more information, see To Create a Cluster .
If you are using HADB to store session state data, create an HADB database for the cluster.
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
If you are using in-memory replication on other servers in the cluster for session state data, omit this step.
For more information about creating an HADB database, see configure-ha-cluster(1).
Set up HTTP load balancing for the cluster.
For more information , see Setting Up HTTP Load Balancing
Enable availability for the desired application server instances and web or EJB containers.
Then configure the session persistence settings. Choose one of these approaches:
Use Admin Console. See Enabling Availability for a Server Instance.
Use the asadmin command-line utility. See set(1) and configure-ha-persistence(1).
Restart each server instance in the cluster.
If the instance is currently serving requests, quiesce the instance before restarting it so that the instance gets enough time to serve the requests it is handling. For more information, see Disabling (Quiescing) a Server Instance or Cluster
Enable availability for any specific SFSB that requires it.
Select methods for which checkpointing the session state is necessary. See Configuring Availability for an Individual Bean
Make each web module distributable if you want it to be highly available.
Enable availability for individual applications, web modules, or EJB modules during deployment.
See Configuring Availability for an Individual Application or EJB Module
In the Administration Console, check the Availability Enabled box, or use the asadmin deploy command with the --availabilityenabled option set to true.
You can enable session availability at five different scopes (from highest to lowest):
Server instance, enabled by default. Enabling session availability for the server instance means that all applications running on the server instance can have high-availability session persistence. For instructions, see next section, Enabling Availability for a Server Instance .
Container (web or EJB), enabled by default. For information on enabling availability at the container level, see:
Application, disabled by default.
Standalone web or EJB module, disabled by default.
Individual SFSB, disabled by default.
To enable availability at a given scope, you must enable it at all higher levels as well. For example, to enable availability at the application level, you must also enable it at the server instance and container levels.
The default for a given level is the setting at the next level up. For example, if availability is enabled at the container level, it is enabled by default at the application level.
When availability is disabled at the server instance level, enabling it at any other level has no effect. When availability is enabled at the server instance level, it is enabled at all levels unless explicitly disabled.
To enable availability for a server instance, use the asadmin set command to set the configuration’s availability-service.availability-enabled property to true.
For example, if config1 is the configuration name:
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service.availability-enabled="true" |
In the tree component, expand the Configurations node.
Expand the node for the configuration you want to edit.
Select the Availability Service node.
In the Availability Service page, enable instance level availability by checking the Availability Service box.
To disable it, uncheck the box.
Additionally, you can change the Store Pool Name if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
Click on the Save button.
Stop and restart the server instance.
Java EE applications typically have significant amounts of session state data. A web shopping cart is the classic example of session state. Also, an application can cache frequently-needed data in the session object. In fact, almost all applications with significant user interactions need to maintain session state.
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
If you are using HADB, enable and configure web container availability by using the asadmin configure-ha-persistence. For more information about this command, see configure-ha-persistence(1).
Alternatively, use the asadmin set command to set the configuration’s availability-service.web-container-availability.availability-enabled property to true and then configure-ha-persistence to set properties as desired.
If you are using in-memory replication to store session state data, you must use the asadmin set command to enable web container availability and to set properties. You can use the configure-ha-persistence command only with HADB.
For example, use the set command as follows, where config1 is the configuration name:
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service.web-container-availability.availability-enabled="true" asadmin configure-ha-persistence --user admin --passwordfile secret.txt --type ha --frequency web-method --scope modified-session --store jdbc/hastore --property maxSessions=1000:reapIntervalSeconds=60 cluster1 |
In the tree component, select the desired configuration.
Click on Availability Service.
Select the Web Container Availability tab.
Check the Availability Service box to enable availability. To disable it, uncheck the box.
Change other settings, as described in the following section, Availability Settings
Restart the server instance.
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
The Web Container Availability tab of the Availability Service enables you to change these availability settings:
Persistence Type: Specifies the session persistence mechanism for web applications that have availability enabled. Allowed values are memory (no persistence) file (the file system), replicated (memory on other servers), and ha (HADB).
HADB must be configured and enabled before you can use ha session persistence. For configuration details, see configure-ha-cluster(1).
If web container availability is enabled, the default persistence type depends on the profile, as shown in the following table.
Profile |
Persistence Type |
---|---|
Developer |
memory |
Cluster |
replicated |
Enterprise |
ha |
For production environments that require session persistence, use ha or replicated. The memory persistence type and the file persistence type do not provide high availability session persistence.
If web container availability is disabled, the default persistence type memory.
Persistence Frequency: Specifies how often the session state is stored. Applicable only if the Persistence Type is ha or replicated. Allowed values are:
web-method - The session state is stored at the end of each web request prior to sending a response back to the client. This mode provides the best guarantee that the session state is fully updated in case of failure. This is the default.
time-based - The session state is stored in the background at the frequency set by the reapIntervalSeconds store property. This mode provides does not guarantee that session state is fully updated. However, it can provide a significant performance improvement because the state is not stored after each request.
Persistence Scope : Specifies how much of the session object and how often session state is stored. Applicable only if the Persistence Type is ha or replicated. Allowed values are as follows:
session - The entire session state is stored every time. This mode provides the best guarantee that your session data is correctly stored for any distributable web application. This is the default.
modified-session - The entire session state is stored if it has been modified. A session is considered to have been modified if HttpSession.setAttribute() or HttpSession.removeAttribute() was called. You must guarantee that setAttribute() is called every time an attribute is changed. This is not a Java EE specification requirement, but it is required for this mode to work properly.
modified-attribute - Only modified session attributes are stored. For this mode to work properly, you must follow a few guidelines:
Call setAttribute() every time the session state is modified.
Make sure there are no cross-references between attributes. The object graph under each distinct attribute key is serialized and stored separately. If there are any object cross references between the objects under each separate key, they are not serialized and deserialized correctly.
Distribute the session state across multiple attributes, or at least between a read-only attribute and a modifiable attribute.
Single Sign-On State: Check this box to enable persistence of the single sign-on state. To disable it, uncheck the box. For more information, see Using Single Sign-on with Session Failover
HTTP Session Store: You can change the HTTP Session Store if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).
To enable and configure availability for an individual web application, edit the application deployment descriptor file, sun-web.xml. The settings in an application’s deployment descriptor override the web container’s availability settings.
The session-manager element’s persistence-type attribute determines the type of session persistence an application uses. It must be set to ha or replicated to enable high availability session persistence.
For more information about the sun-web.xml file, see The sun-web.xml File in Sun Java System Application Server 9.1 Application Deployment Guide.
<sun-web-app> ... <session-config> <session-manager persistence-type=ha> <manager-properties> <property name=persistenceFrequency value=web-method /> </manager-properties> <store-properties> <property name=persistenceScope value=session /> </store-properties> </session-manager> ... </session-config> ...
In a single application server instance, once a user is authenticated by an application, the user is not required to re-authenticate individually to other applications running on the same instance. This is called single sign-on. For more information, see User Authentication for Single Sign-on in Sun Java System Application Server 9.1 Developer’s Guide.
For this feature to continue to work even when an HTTP session fails over to another instance in a cluster, single sign-on information must be persisted to the HADB. To persist single sign-on information, first, enable availability for the server instance and the web container, then enable single-sign-on state failover.
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
You can enable single sign-on state failover with the Admin Console in the Web Container Availability tab of the Availability Service, as described in Configuring Availability for the Web Container. You can also use the asadmin set command to set the configuration’s availability-service.web-container-availability.sso-failover-enabled property to true.
For example, use the set command as follows, where config1 is the configuration name:
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849 config1.availability-service.web-container-availability. sso-failover-enabled="true"
Applications that can be accessed through a single name and password combination constitute a single sign-on group. For HTTP sessions corresponding to applications that are part of a single sign-on group, if one of the sessions times out, other sessions are not invalidated and continue to be available. This is because time out of one session should not affect the availability of other sessions.
As a corollary of this behavior, if a session times out and you try to access the corresponding application from the same browser window that was running the session, you are not required to authenticate again. However, a new session is created.
Take the example of a shopping cart application that is a part of a single sign-on group with two other applications. Assume that the session time out value for the other two applications is higher than the session time out value for the shopping cart application. If your session for the shopping cart application times out and you try to run the shopping cart application from the same browser window that was running the session, you are not required to authenticate again. However, the previous shopping cart is lost, and you have to create a new shopping cart. The other two applications continue to run as usual even though the session running the shopping cart application has timed out.
Similarly, suppose a session corresponding to any of the other two applications times out. You are not required to authenticate again while connecting to the application from the same browser window in which you were running the session.
This behavior applies only to cases where the session times out. If single sign-on is enabled and you invalidate one of the sessions using HttpSession.invalidate() , the sessions for all applications belonging to the single sign-on group are invalidated. If you try to access any application belonging to the single sign-on group, you are required to authenticate again, and a new session is created for the client accessing the application.
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.
An SFSB’s state can be saved in a persistent store in case a server instance fails. The state of an SFSB is saved to the persistent store at predefined points in its life cycle. This is called checkpointing. If enabled, checkpointing generally occurs after the bean completes any transaction, even if the transaction rolls back.
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 Application Server instance is stopped, the session data in the persistence store might not be cleared. To prevent this, undeploy the SFSB while the Application Server instance is running.
Select the EJB Container Availability tab.
Check the Availability Service box.
To disable availability, uncheck the box.
Change other settings as described in Availability Settings
Click on the Save button.
Restart the server instance.
To enable availability for the EJB container use the asadmin set command to set the following three properties for the configuration:
availability-service.ejb-container-availability.availability-enabled
availability-service.ejb-container-availability.sfsb-persistence-type
availability-service.ejb-container-availability.sfsb-ha-persistence-type
For example, if config1 is the configuration name, use the following commands:
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.availability-enabled="true"
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.sfsb-persistence-type="file"
asadmin set --user admin --passwordfile password.txt --host localhost --port 4849config1.availability-service.ejb-container-availability.sfsb-ha-persistence-type="ha"
The HADB software is supplied with the Application Server standalone distribution of Sun Java System Application Server. For information about available distributions of Sun Java System Application Server, see Distribution Types and Their Components in Sun Java System Application Server 9.1 Installation Guide. HADB features are available only in the enterprise profile. For information about profiles, see Usage Profiles in Sun Java System Application Server 9.1 Administration Guide.
The EJB Container Availability tab of the Availability Service enables you to change these settings:
HA Persistence Type: Specifies the session persistence and passivation mechanism for SFSBs that have availability enabled. Allowed values are file (the file system), replicated (memory on other servers), and ha (HADB). The default value is ha. For production environments that require session persistence, use ha or replicated.
SFSB Persistence Type: Specifies the passivation mechanism for SFSBs that do not have availability enabled. Allowed values are file (the default), replicated, and ha.
If either Persistence Type is set to file, the EJB container specifies the file system location where the passivated session bean state is stored. Checkpointing to the file system is useful for testing but is not for production environments. For information about configuring store properties, see the Admin Console online help.
HA persistence enables a cluster of server instances to recover the SFSB state if any server instance fails. HADB is also used as the passivation and activation store. Use this option in a production environment that requires SFSB state persistence. For more information, see configure-ha-cluster(1).
SFSB Store Pool Name: You can change the SFSB Store Pool Name if you changed the JDBC resource used for connections to the HADB for session persistence. For details, see configure-ha-cluster(1).
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 Admin Console online help.
You can enable SFSB availability for an individual application or EJB module during deployment:
If you are deploying with the Admin Console, check the Availability Enabled checkbox.
If you are deploying using use the asadmin deploy or asadmin deploydir commands, set the --availabilityenabled option to true. For more information, see deploy(1) and deploydir(1).
To enable availability and select methods to be checkpointed for an individual SFSB, use the sun-ejb-jar.xml deployment descriptor file. .
To enable high availability session persistence, set availability-enabled="true" in the ejb element. To control the size and behavior of the SFSB cache, use the following elements:
max-cache-size : specifies the maximum number of session beans that are held in cache. If the cache overflows (the number of beans exceeds max-cache-size), the container then passivates some beans or writes out the serialized state of the bean into a file. The directory in which the file is created is obtained from the EJB container using the configuration APIs.
resize-quantity
cache-idle-timeout-in-seconds
removal-timeout-in-seconds
victim-selection-policy
For more information about sun-ejb-jar.xml, see The sun-ejb-jar.xml File in Sun Java System Application Server 9.1 Application Deployment Guide.
<sun-ejb-jar> ... <enterprise-beans> ... <ejb availability-enabled="true"> <ejb-name>MySFSB</ejb-name> </ejb> ... </enterprise-beans> </sun-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 sun-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.
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.
<sun-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> </sun-ejb-jar>