| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Chapter 10. Session Management</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="jetty-admin-guide.html" title="Part III. Jetty Administration Guide"><link rel="prev" href="startup-jpms.html" title="Startup using the Java Platform Module System (JPMS)"><link rel="next" href="sessions-details.html" title="Session Components"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script> |
| hljs.initHighlightingOnLoad(); |
| </script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.4.28.v20200408</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 10. Session Management</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="startup-jpms.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><th width="60%" align="center">Part III. Jetty Administration Guide<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="sessions-details.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| 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 for sponsored feature development |
| </p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="session-management"></a>Chapter 10. Session Management</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="session-management.html#jetty-sessions-architecture">Session Architecture</a></span></dt><dt><span class="section"><a href="sessions-details.html">Session Components</a></span></dt><dt><span class="section"><a href="session-configuration-housekeeper.html">The SessionIdManager and the Housekeeper</a></span></dt><dt><span class="section"><a href="session-configuration-sessioncache.html">The L1 Session Cache</a></span></dt><dt><span class="section"><a href="configuring-sessions-memory.html">Non-Persistent Sessions</a></span></dt><dt><span class="section"><a href="configuring-sessions-file-system.html">Persistent Sessions: File System</a></span></dt><dt><span class="section"><a href="configuring-sessions-jdbc.html">Persistent Sessions: JDBC</a></span></dt><dt><span class="section"><a href="configuring-sessions-mongo.html">Persistent Sessions: MongoDB</a></span></dt><dt><span class="section"><a href="configuring-sessions-infinispan.html">Persistent Sessions: Inifinspan</a></span></dt><dt><span class="section"><a href="configuring-sessions-hazelcast.html">Persistent Sessions: Hazelcast</a></span></dt><dt><span class="section"><a href="configuring-sessions-gcloud.html">Persistent Sessions: Google Cloud DataStore</a></span></dt><dt><span class="section"><a href="session-configuration-memcachedsessiondatastore.html">Persistent Sessions: The L2 Session Data Cache</a></span></dt><dt><span class="section"><a href="sessions-usecases.html">Session Use Cases</a></span></dt></dl></div><p>Sessions are a concept within the Servlet api which allow requests to store and retrieve information across the time a user spends in an application. |
| Choosing the correct session manager implementation is an important consideration for every application as each can fit and perform optimally in different situations. |
| If you need a simple in-memory session manager that can persist to disk then session management using the local file system can be a good place to start. |
| If you need a session manager that can work in a clustered scenario with multiple instances of Jetty, then the JDBC session manager can be an excellent option. |
| Jetty also offers more niche session managers that leverage backends such as MongoDB, Inifinispan, or even Google’s Cloud Data Store.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jetty-sessions-architecture"></a>Session Architecture</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="session-management.html#_changes_in_session_architecture">Changes in Session Architecture</a></span></dt><dt><span class="section"><a href="session-management.html#_session_architecture_hierarchy">Session Architecture Hierarchy</a></span></dt><dt><span class="section"><a href="session-management.html#_configuring_sessions_in_the_jetty_distribution">Configuring Sessions in the Jetty Distribution</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_changes_in_session_architecture"></a>Changes in Session Architecture</h3></div></div></div><p>The architecture of Session Management Jetty changed significantly in Jetty 9.4. |
| These changes have resulted in Sessions not only being easier to configure but making them much more pluggable for various technologies.</p><p>In previous versions of Jetty, users were required to configure a separate <code class="literal">SessionIdManager</code> for each kind of session clustering technology being implemented (JDBC, MongoDB..etc.). |
| In Jetty 9.4, there is now a single <code class="literal">SessionIdManager</code> implementation which works across all types of session clustering technologies. |
| Likewise, prior to Jetty 9.4 there were several different instances of the <code class="literal">SessionManager</code> class. |
| Instead of a single <code class="literal">SessionManager</code> though, it has been done away with entirely, with most of it’s functionality moved to the <code class="literal">SesssionHandler</code> class. |
| Additionally, Jetty 9.4 introduced the concepts of a <code class="literal">SessionCache</code> and an associated <code class="literal">SessionDataStore</code> (both explained below).</p><p>Finally, Session scavenging has been re-worked. |
| Where previously each <code class="literal">SessionManager</code> instance would periodically scan the in-memory (or clustered) sessions for expired sessions, there is now a single generic scavenger thread which instructs the <code class="literal">SessionHandler</code> to clean up expired sessions. |
| Session expiration has been changed to use a much more efficient timer-based mechanism that avoids constant iteration over all current sessions in memory by the scavenger.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_session_architecture_hierarchy"></a>Session Architecture Hierarchy</h3></div></div></div><p>Each Jetty instance has a singular <code class="literal">SessionIdManager</code> to handle all session requests, regardless of clustering technology. |
| For each context on the server there is one (1) <code class="literal">SessionCache</code> which contains all of the Session objects for the given context. |
| The benefit of the <code class="literal">SessionCache</code> is to ensure that simultaneous requests accessing the same Session Id in the same context always operate on the same Session object. |
| The SessionCache implementation supplied with the Jetty distribution does just that: keeps Session objects in memory so that they can be shared between simultaneous requests. |
| However, it is possible to provide your own implementation that never shares Session objects should you require it.</p><p>Where the <code class="literal">SessionCache</code> handles Session information, Session data is stored in a <code class="literal">SessionDataStore</code> that is specific to the clustering technology being implemented. |
| There is only one (1) <code class="literal">SessionDataStore</code> per <code class="literal">SessionCache</code>.</p><p>Visually the session architecture can be represented like this:</p><div class="informalfigure"><div class="mediaobject"><img src="images/SessionsHierarchy.png" alt="SessionsHierarchy"></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configuring_sessions_in_the_jetty_distribution"></a>Configuring Sessions in the Jetty Distribution</h3></div></div></div><p>Configuring session management involves selecting a <a class="link" href="startup-modules.html" title="Managing Startup Modules">module</a> for the desired type of <a class="link" href="session-configuration-sessioncache.html" title="The L1 Session Cache">session caching</a> behavior, and a module for the type of session persistence.</p><p>Jetty provides two different session caches: the <code class="literal">DefaultSessionCache</code> which holds sessions in memory, and the <code class="literal">NullSessionCache</code> which does not. |
| There is more information on both of these types of session caching and the circumstances which would lead you to select one or the other in the <a class="link" href="sessions-details.html" title="Session Components">Session Components</a> section, and more information on the configuration options of each in <a class="link" href="session-configuration-sessioncache.html" title="The L1 Session Cache">the L1 Session Cache</a> section.</p><p>For session persistence, Jetty provides a number of different implementations from which to choose including <a class="link" href="configuring-sessions-memory.html" title="Non-Persistent Sessions">non-persistence</a>, <a class="link" href="configuring-sessions-file-system.html" title="Persistent Sessions: File System">local file storage</a>, clustered technologies such as <a class="link" href="configuring-sessions-jdbc.html" title="Persistent Sessions: JDBC">JDBC</a>, <a class="link" href="configuring-sessions-mongo.html" title="Persistent Sessions: MongoDB">MongoDB</a>, <a class="link" href="configuring-sessions-infinispan.html" title="Persistent Sessions: Inifinspan">Inifinispan</a>, <a class="link" href="configuring-sessions-gcloud.html" title="Persistent Sessions: Google Cloud DataStore">Google Cloud Datastore</a>, and <a class="link" href="configuring-sessions-hazelcast.html" title="Persistent Sessions: Hazelcast">Hazelcast</a>.</p><p>Depending on your persistence technology, to enhance performance, you may want to use an L2 cache for session data, in which case Jetty provides the <a class="link" href="session-configuration-memcachedsessiondatastore.html" title="Persistent Sessions: The L2 Session Data Cache">memcached L2 session data cache</a>.</p></div></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="startup-jpms.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="jetty-admin-guide.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="sessions-details.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Startup using the Java Platform Module System (JPMS) </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top"> Session Components</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at |
| <span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-04-08)</i></span></div></p></body></html> |