Class DefaultSessionCache

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.session.AbstractSessionCache
org.eclipse.jetty.server.session.DefaultSessionCache
All Implemented Interfaces:
SessionCache, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle

@ManagedObject public class DefaultSessionCache extends AbstractSessionCache
DefaultSessionCache A session store that keeps its sessions in memory within a concurrent map
  • Constructor Details

    • DefaultSessionCache

      public DefaultSessionCache(SessionHandler manager)
      Parameters:
      manager - The SessionHandler related to this SessionCache
    • DefaultSessionCache

      public DefaultSessionCache(SessionHandler manager, ConcurrentMap<String,Session> sessions)
      Parameters:
      manager - The SessionHandler related to this SessionCache
      sessions - The session map implementation to use
  • Method Details

    • getSessionsCurrent

      @ManagedAttribute(value="current sessions in cache", readonly=true) public long getSessionsCurrent()
      Returns:
      the number of sessions in the cache
    • getSessionsMax

      @ManagedAttribute(value="max sessions in cache", readonly=true) public long getSessionsMax()
      Returns:
      the max number of sessions in the cache
    • getSessionsTotal

      @ManagedAttribute(value="total sessions in cache", readonly=true) public long getSessionsTotal()
      Returns:
      a running total of sessions in the cache
    • resetStats

      @ManagedOperation(value="reset statistics", impact="ACTION") public void resetStats()
    • doGet

      public Session doGet(String id)
      Description copied from class: AbstractSessionCache
      Get the session matching the key from the cache. Does not load the session.
      Specified by:
      doGet in class AbstractSessionCache
      Parameters:
      id - session id
      Returns:
      the Session object matching the id
    • doPutIfAbsent

      public Session doPutIfAbsent(String id, Session session)
      Description copied from class: AbstractSessionCache
      Put the session into the map if it wasn't already there
      Specified by:
      doPutIfAbsent in class AbstractSessionCache
      Parameters:
      id - the identity of the session
      session - the session object
      Returns:
      null if the session wasn't already in the map, or the existing entry otherwise
    • doComputeIfAbsent

      protected Session doComputeIfAbsent(String id, Function<String,Session> mappingFunction)
      Description copied from class: AbstractSessionCache
      Compute the mappingFunction to create a Session object iff the session with the given id isn't already in the map, otherwise return the existing Session. This method is expected to have precisely the same behaviour as ConcurrentHashMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
      Specified by:
      doComputeIfAbsent in class AbstractSessionCache
      Parameters:
      id - the session id
      mappingFunction - the function to load the data for the session
      Returns:
      an existing Session from the cache
    • doDelete

      public Session doDelete(String id)
      Description copied from class: AbstractSessionCache
      Remove the session with this identity from the store
      Specified by:
      doDelete in class AbstractSessionCache
      Parameters:
      id - the id
      Returns:
      Session that was removed or null
    • shutdown

      public void shutdown()
    • newSession

      public Session newSession(jakarta.servlet.http.HttpServletRequest request, SessionData data)
      Description copied from class: AbstractSessionCache
      Create a new Session for a request.
      Specified by:
      newSession in class AbstractSessionCache
      Parameters:
      request - the request
      data - the session data
      Returns:
      the new session
    • newSession

      public Session newSession(SessionData data)
      Description copied from class: AbstractSessionCache
      Create a new Session object from pre-existing session data
      Specified by:
      newSession in interface SessionCache
      Specified by:
      newSession in class AbstractSessionCache
      Parameters:
      data - the session data
      Returns:
      a new Session object
    • doReplace

      public boolean doReplace(String id, Session oldValue, Session newValue)
      Description copied from class: AbstractSessionCache
      Replace the mapping from id to oldValue with newValue
      Specified by:
      doReplace in class AbstractSessionCache
      Parameters:
      id - the id
      oldValue - the old value
      newValue - the new value
      Returns:
      true if replacement was done