Overview
One of the high availability methods provided by glassfish, is session replication.
With session replication enabled, the server distributes session data across the cluster. If one cluster instances crashes, the session is still available on the other instances.
Requirements
- A recent glassfish installation (versions prior to 2.1.1 had some bugs).
- A configured cluster (Look here who to install a glassfish cluster).
- All cluster instances located in the same subnet. (later glassfish version should support different subnets)
Configure session replication
- Add a <distributable /> tag to your web.xml
<web-app> <distributable /> ... </web-app>
- Add following lines to your sun-web.xml
<session-config> <session-manager persistence-type="replicated"> <manager-properties> <property name="persitencerequency" value="web-method" /> </manager-properties> <store-properties> <property name="persistenceScope" value="session" /> </store-properties> </session-manager> </session-config>- persistenceType=”replicated” says, that the session should be replicated along the cluster.
- persistenceFrequency=”web-method” says that the session state should be stored after processing a request, but before sending the response. (other values: time-based)
- persistenceScope=”session” says that the whole session state should be stored. (other values: modified-session, modified-attribute)
- Deploy application
- using the web-interface: check the Availability checkbox.
- using the cli: add –availabilityenabled=true parameter.
Notes
- Be sure that all classes that are going to be stored in a session implements the Serializable interface.
If not, the server can’t serialize it and replication won’t work. - As already mentioned, the instances have to be on the same subnet, otherwise session replication will not work.
1 comment
Emmanuel says:
January 18, 2012 at 22:28 (UTC 2 )
Hello, thanks for the post. I have a questions though. I am working on a web site and I want two or more applications to be available from the site, either using subdomains or directories. Is there a way to configure glassfish such that the session information can be shared between two different applications? That is, when I put something inside the HttpSession object in one application, I want to be able to access it in another application.