| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Session Components</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="session-management.html" title="Chapter 10. Session Management"><link rel="prev" href="session-management.html" title="Chapter 10. Session Management"><link rel="next" href="session-configuration-housekeeper.html" title="The SessionIdManager and the Housekeeper"><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-SNAPSHOT</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">Session Components</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="session-management.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><th width="60%" align="center">Chapter 10. Session Management<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="session-configuration-housekeeper.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="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sessions-details"></a>Session Components</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="sessions-details.html#_sessionidmanager">SessionIdManager</a></span></dt><dt><span class="section"><a href="sessions-details.html#_housekeeper">HouseKeeper</a></span></dt><dt><span class="section"><a href="sessions-details.html#_sessioncache">SessionCache</a></span></dt><dt><span class="section"><a href="sessions-details.html#_sessiondatastore">SessionDataStore</a></span></dt><dt><span class="section"><a href="sessions-details.html#_cachingsessiondatastore">CachingSessionDataStore</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sessionidmanager"></a>SessionIdManager</h3></div></div></div><p>There is a maximum of one (1) <code class="literal">SessionIdManager</code> per Jetty Server instance. |
| Its purpose is to generate fresh, unique session ids and to coordinate the re-use of session ids amongst co-operating contexts.</p><p>Unlike in previous versions of Jetty, the <code class="literal">SessionIdManager</code> is agnostic with respect to the type of clustering technology chosen.</p><p>Jetty provides a default implementation - the <code class="literal">DefaultSessionIdManager</code> - which should meet the needs of most users. |
| If you do not explicitly enable one of the session modules or otherwise configure a <code class="literal">SessionIdManager</code>, the <code class="literal">DefaultSessionIdManager</code> will be used.</p><p>If the <code class="literal">DefaultSessionIdManager</code> does not meet your needs, you can extend the <code class="literal">org.eclipse.jetty.server.session.AbstractSessionIdManager</code> or do a fresh implementation of the <code class="literal">org.eclipse.jetty.server.session.SessionIdManager</code> interface.</p><p>See <a class="link" href="session-configuration-housekeeper.html" title="The SessionIdManager and the Housekeeper">Configuring the SessionIdManager and HouseKeeper</a> for details on configuration.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_housekeeper"></a>HouseKeeper</h3></div></div></div><p>There is a maximum of one (1) <code class="literal">HouseKeeper</code> per <code class="literal">SessionIdManager</code>. |
| Its purpose is to periodically poll the <code class="literal">SessionHandlers</code> to clean out expired sessions.</p><p>By default the <code class="literal">HouseKeeper</code> will poll the <code class="literal">SessionHandlers</code> every 10 mins to find and delete expired sessions, although this interval is configurable.</p><p>See <a class="link" href="session-configuration-housekeeper.html" title="The SessionIdManager and the Housekeeper">Configuring the SessionIdManager and HouseKeeper</a> for details on configuration.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sessioncache"></a>SessionCache</h3></div></div></div><p>There is one (1) <code class="literal">SessionCache</code> <span class="strong"><strong>per context.</strong></span> |
| Its purpose is to provide an L1 cache of Session objects. |
| Having a working set of Session objects in memory allows multiple simultaneous requests for the same session to share the same Session object.</p><p>Jetty provides two (2) <code class="literal">SessionCache</code> implementations: the <code class="literal">DefaultSessionCache</code> and the <code class="literal">NullSessionCache</code>. |
| The <code class="literal">DefaultSessionCache</code> retains Session objects in memory in a cache and has a number of <a class="link" href="session-configuration-sessioncache.html" title="The L1 Session Cache">configuration options</a> to control cache behavior. |
| It is the default that is used if no other <code class="literal">SessionCache</code> has been configured. |
| It is suitable for non-clustered and clustered deployments with a sticky load balancer, as well as clustered deployments with a non-sticky load balancer, with some caveats.</p><p>The <code class="literal">NullSessionCache</code> does not actually cache any objects: each request uses a fresh Session object. |
| It is suitable for clustered deployments without a sticky load balancer and non-clustered deployments when purely minimal support for sessions is needed.</p><p><code class="literal">SessionCaches</code> always write out a Session to the <code class="literal">SessionDataStore</code> whenever the last request for the Session exits.</p><p>They can also be configured to do an immediate, eager write of a freshly created session. |
| This can be useful if you are likely to experience multiple, near simultaneous requests referencing the same session, e.g. with HTTP/2 and you don’t have a sticky load balancer. |
| Alternatively, if the eager write is not done, application paths which create and then invalidate a session within a single request never incur the cost of writing to persistent storage.</p><p>Additionally, if the <code class="literal">EVICT_ON_INACTIVITY</code> eviction policy is in use, you can <a class="link" href="session-configuration-sessioncache.html" title="The L1 Session Cache">configure</a> the <code class="literal">DefaultSessionCache</code> to force a write of the Session to the <code class="literal">SessionDataStore</code> just before the Session is evicted.</p><p>See <a class="link" href="session-configuration-sessioncache.html" title="The L1 Session Cache">the L1 Session Cache</a> for more information.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sessiondatastore"></a>SessionDataStore</h3></div></div></div><p>There is one (1) <code class="literal">SessionDataStore</code> per context. |
| Its purpose is to handle all persistence related operations on sessions.</p><p>The common characteristics for all <code class="literal">SessionDataStores</code> are whether or not they support passivation, and the length of the grace period.</p><p>Supporting passivation means that session data is serialized. |
| Some persistence mechanisms serialize, such as JDBC, GCloud Datastore etc, whereas others may store an object in shared memory, e.g. Infinispan, when configured with a local cache.</p><p>Whether or not a clustering technology entails passivation controls whether or not the session passivation/activation listeners will be called.</p><p>The grace period is an interval, configured in seconds, that attempts to deal with the non-transactional nature of sessions with regard to finding sessions that have expired. |
| Due to the lack of transactionality, in a clustered configuration, even with a sticky load balancer, it is always possible that a Session is live on a node but has not yet been updated in the persistent store. |
| When <code class="literal">SessionDataStores</code> search their persistent store to find sessions that have expired, they typically perform a few sequential searches:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">The first verifies the expiration of a list of candidate session ids suggested by the SessionCache</li><li class="listitem">The second finds sessions in the store that have expired which were last live on the current node</li><li class="listitem">The third finds sessions that expired a "while" ago, irrespective of on which node they were last used: the definition of "a while" is based on the grace period.</li></ul></div><p>Jetty instantiates the trivial <code class="literal">NullSessionDataStore</code> - which does not persist sessions - as the default.</p><p>The distribution provides a number of alternative <code class="literal">SessionDataStore</code> implementations such as <a class="link" href="configuring-sessions-file-system.html" title="Persistent Sessions: File System">FileSessionDataStore</a>, <a class="link" href="configuring-sessions-gcloud.html" title="Persistent Sessions: Google Cloud DataStore">GCloudSessionDataStore</a>, <a class="link" href="configuring-sessions-jdbc.html" title="Persistent Sessions: JDBC">JDBCSessionDataStore</a>, MongoSessionDataStore, <a class="link" href="configuring-sessions-infinispan.html" title="Persistent Sessions: Inifinspan">InfinispanSessionDataStore</a>, <a class="link" href="configuring-sessions-hazelcast.html" title="Persistent Sessions: Hazelcast">HazelcastSessionDataStore</a>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_cachingsessiondatastore"></a>CachingSessionDataStore</h3></div></div></div><p>The <code class="literal">CachingSessionDataStore</code> is a special type of <code class="literal">SessionDataStore</code> that inserts an L2 cache of Session data - the <code class="literal">SessionDataMap</code> - in front of a delegate <code class="literal">SessionDataStore</code>. |
| The <code class="literal">SessionDataMap</code> is preferentially consulted before the actual SessionDataStore on reads. |
| This can improve the performance of slow stores.</p><p>Jetty provides one implementation of the this L2 cache based on <code class="literal">Memcached</code>, the <code class="literal">MemcachedSessionDataMap</code>.</p><p>See <a class="link" href="session-configuration-memcachedsessiondatastore.html" title="Persistent Sessions: The L2 Session Data Cache">the L2 SessionData Cache</a>for additional information.</p></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="session-management.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="session-management.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="session-configuration-housekeeper.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 10. Session Management </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"> The SessionIdManager and the Housekeeper</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-03-10)</i></span></div></p></body></html> |