Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

{info:title="Jetty 7"
This feature is only available with release jetty-7.x

Icon
 

Session Clustering using a Database

There are a number of different clustering solutions available for use with jetty: WADI, which shares the sessions in memory as needed in a distributed manner and Terracotta, which is a highly-efficient distributed object solution.

Jetty now provides a third alternative, which persists sessions to a shared database. Each jetty instance locally caches sessions for which it has received requests, writing any changes to the session through to the database as the request exits the server. Sessions must obey the Serialization contract, and servlets must call the Session.setAttribute() method to ensure that changes are persisted.

The persistent session mechanism is designed to work in conjunction with a load balancer that supports stickiness. Stickiness can be based on various data items, such as source IP address or characteristics of the session id or a load-balancer specific mechanism. For those load balancers that examine the session id, the Jetty persistent session mechanism appends a node id to the session id which can be used for routing.

Configuration

There are 2 components to session management in Jetty: a session id manager and a session manager. The session id manager's job is to ensure that session ids are unique across all webapps hosted on a jetty instance and thus there can only be one per jetty instance. The session manager's job is to handle the session lifecycle (create/update/invalidate/expire) on behalf of a web application, and thus there is one per web application instance. They also cooperate and collaborate with the org.mortbay.handler.SessionHandler to ensure cross-context dispatch works as expected.

Configuring the JDBCSessionIdManager

We need to configure an org.mortbay.jetty.servlet.JDBCSessionIdManager instance, either in embedded code or in a jetty.xml file. Here is an example of a jetty.xml setup:

<Set name="sessionIdManager">
<New id="jdbcidmgr" class="org.mortbay.jetty.servlet.JDBCSessionIdManager">
<Arg><Ref id="Server"/></Arg>
<Set name="workerName">fred</Set>
<Set name="DatasourceName">javax.sql.DataSource/default</Set>
<Set name="scavengeInterval">60</Set>
</New>
</Set>

You'll notice that the JDBCSessionIdManager needs access to a database. The above configures it with the name of a javax.sql.DataSource that is defined elsewhere. Consult [] for more information on how to configure database access with jetty. If you don't wish to use a DataSource, you can configure jdbc Driver information instead. Here's an example:

<Set name="sessionIdManager">
<New id="jdbcidmgr" class="org.mortbay.jetty.servlet.JDBCSessionIdManager">
<Arg><Ref id="Server"/></Arg>
<Set name="workerName">fred</Set>
<Call name="setDriverInfo">
<Arg>com.mysql.jdbc.Driver</Arg>
<Arg>jdbc:mysql://127.0.0.1:3306/sessions?user=janb</Arg>
</Call>
<Set name="scavengeInterval">60</Set>
</New>
</Set>

  • No labels
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery