Subscribe to RSS feed

«

»

Oct
31

Enable glassfish session replication

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

  1. Add a <distributable /> tag to your web.xml
    <web-app>
      <distributable />
      ...
    </web-app>
  2. 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)
  3. 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.

Further reading

The replicated Persistence Type

2 comments

  1. higkoo says:

    How can I disable the session ?

    1. Dirk Reske says:

      What do you mean with “disable the session” ?

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>