Sun GlassFish Enterprise Server 2.1 Developer's Guide

Session Managers

A session manager automatically creates new session objects whenever a new session starts. In some circumstances, clients do not join the session, for example, if the session manager uses cookies and the client does not accept cookies.

Enterprise Server offers these session management options, determined by the session-manager element’s persistence-type attribute in the sun-web.xml file:


Note –

If the session manager configuration contains an error, the error is written to the server log and the default (memory) configuration is used.


For more information, see session-manager in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

The memory Persistence Type

This persistence type is not designed for a production environment that requires session persistence. It provides no session persistence. However, you can configure it so that the session state in memory is written to the file system prior to server shutdown.

To specify the memory persistence type for the entire web container, use the configure-ha-persistence command. For details, see the Sun GlassFish Enterprise Server 2.1 Reference Manual.

To specify the memory persistence type for a specific web application, edit the sun-web.xml file as in the following example. The persistence-type property is optional, but must be set to memory if included. This overrides the web container availability settings for the web application.

<sun-web-app>
...
<session-config>
	<session-manager persistence-type="memory" />
		<manager-properties>
			<property name="sessionFilename" value="sessionstate" />
		</manager-properties>
	</session-manager>
	...
</session-config>
...
</sun-web-app>

The only manager property that the memory persistence type supports is sessionFilename, which is listed under manager-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

For more information about the sun-web.xml file, see Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

The file Persistence Type

This persistence type provides session persistence to the local file system, and allows a single server domain to recover the session state after a failure and restart. The session state is persisted in the background, and the rate at which this occurs is configurable. The store also provides passivation and activation of the session state to help control the amount of memory used. This option is not supported in a production environment. However, it is useful for a development system with a single server instance.


Note –

Make sure the delete option is set in the server.policy file, or expired file-based sessions might not be deleted properly. For more information about server.policy, see The server.policy File.


To specify the file persistence type for the entire web container, use the configure-ha-persistence command. For details, see the Sun GlassFish Enterprise Server 2.1 Reference Manual.

To specify the file persistence type for a specific web application, edit the sun-web.xml file as in the following example. Note that persistence-type must be set to file. This overrides the web container availability settings for the web application.

<sun-web-app>
...
<session-config>
	<session-manager persistence-type="file">
		<store-properties>
			<property name="directory" value="sessiondir" />
		</store-properties>
	</session-manager>
	...
</session-config>
...
</sun-web-app>

The file persistence type supports all the manager properties listed under manager-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide except sessionFilename, and supports the directory store property listed under store-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

For more information about the sun-web.xml file, see Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

The replicated Persistence Type

The replicated persistence type uses other servers in the cluster for session persistence. Clustered server instances replicate session state in a ring topology. Each backup instance stores the replicated data in memory. This allows sessions to be distributed. For details, see Distributed Sessions and Persistence. In addition, you can configure the frequency and scope of session persistence. The other servers are also used as the passivation and activation store. Use this option in a production environment that requires session persistence.


Note –

Some topics in the documentation pertain to features that are available only in domains that are configured to support clusters. Examples of domains that support clusters are domains that are created with the cluster profile or the enterprise profile. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server 2.1 Administration Guide.


To use the replicated persistence type, you must enable availability. Select the Availability Service component under the relevant configuration in the Admin Console. Check the Availability Service box. To enable availability for the web container, select the Web Container Availability tab, then check the Availability Service box. All instances in an Enterprise Server cluster should have the same availability settings to ensure consistent behavior. For details, see the Sun GlassFish Enterprise Server 2.1 High Availability Administration Guide.

To change settings such as persistence frequency and persistence scope for the entire web container, use the Persistence Frequency and Persistence Scope drop-down lists on the Web Container Availability tab in the Admin Console, or use the asadmin set command. For example:


asadmin set server-config.availability-service.web-container-availability.persistence-frequency=time-based

For more information, see the description of the asadmin set command in the Sun GlassFish Enterprise Server 2.1 Reference Manual.

To specify the replicated persistence type for a specific web application, edit the sun-web.xmlfile as in the following example. Note that persistence-type must be set to replicated. This overrides the web container availability settings for the web application.

<sun-web-app>
...
<session-config>
	<session-manager persistence-type="replicated">
		<manager-properties>
			<property name="persistenceFrequency" value="web-method" />
		</manager-properties>
		<store-properties>
			<property name="persistenceScope" value="session" />
		</store-properties>
	</session-manager>
	...
</session-config>
...
</sun-web-app>

The replicated persistence type supports all the manager properties listed under manager-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide except sessionFilename, and supports the persistenceScope store property listed under store-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

For more information about the sun-web.xml file, see Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

The ha Persistence Type

The ha persistence type uses the high-availability database (HADB) for session persistence. The HADB must be installed and the enterprise profile must be selected. For information about profiles, see Usage Profiles in Sun GlassFish Enterprise Server 2.1 Administration Guide.

The HADB allows sessions to be distributed. For details, see Distributed Sessions and Persistence. In addition, you can configure the frequency and scope of session persistence. The HADB is also used as the passivation and activation store. Use this option in a production environment that requires session persistence.

The HADB must be configured and enabled before you can use distributed sessions. For configuration details, see the description of the configure-ha-cluster command in the Sun GlassFish Enterprise Server 2.1 Reference Manual.

To enable the HADB, select the Availability Service component under the relevant configuration in the Admin Console. Check the Instance Level Availability box. To enable availability for the web container, select the Web Container Availability tab, then check the Availability Service box. All instances in an Enterprise Server cluster should have the same availability settings to ensure consistent behavior. For details, see the Sun GlassFish Enterprise Server 2.1 High Availability Administration Guide.

To change settings such as persistence frequency and persistence scope for the entire web container, see the description of the configure-ha-persistence command in the Sun GlassFish Enterprise Server 2.1 Reference Manual.

To specify the ha persistence type for a specific web application, edit the sun-web.xml file as in the following example. Note that persistence-type must be set to ha. This overrides the web container availability settings for the web application.

<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>
...
</sun-web-app>

The ha persistence type supports all the manager properties listed under manager-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide except sessionFilename, and supports the persistenceScope store property listed under store-properties in Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.

For more information about the sun-web.xml file, see Sun GlassFish Enterprise Server 2.1 Application Deployment Guide.