Class DefaultSessionIdManager

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.session.DefaultSessionIdManager
All Implemented Interfaces:
SessionIdManager, 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 DefaultSessionIdManager extends org.eclipse.jetty.util.component.ContainerLifeCycle implements SessionIdManager
DefaultSessionIdManager Manages session ids to ensure each session id within a context is unique, and that session ids can be shared across contexts (but not session contents). There is only 1 session id manager per Server instance. Runs a HouseKeeper thread to periodically check for expired Sessions.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected HouseKeeper
     
    protected boolean
     
    protected Random
     
    protected long
     
    protected org.eclipse.jetty.server.Server
     
    protected boolean
     
    protected String
     
    protected String
     
    protected static final AtomicLong
     

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultSessionIdManager(org.eclipse.jetty.server.Server server)
     
    DefaultSessionIdManager(org.eclipse.jetty.server.Server server, Random random)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
     
    void
    Remove an id from use by telling all contexts to remove a session with this id.
    getExtendedId(String clusterId, org.eclipse.jetty.server.Request request)
    Get the session ID with any worker ID.
    getId(String extendedId)
    Get the session ID without any worker ID.
    Get the random number generator.
    long
    Get the reseed probability.
    org.eclipse.jetty.server.Server
    Get the server associated with this id manager.
     
    Get SessionManager for every context.
    Get the workname.
    void
    Set up a random number generator for the sessionids.
    void
    Invalidate all sessions on all contexts that share the same id.
    boolean
     
    newSessionId(long seedTerm)
     
    newSessionId(org.eclipse.jetty.server.Request request, String requestedId, long created)
    Create a new session id if necessary.
    renewSessionId(String oldClusterId, String oldNodeId, org.eclipse.jetty.server.Request request)
    Generate a new id for a session and update across all SessionManagers.
    void
     
    void
    setRandom(Random random)
    Set a random number generator for generating ids.
    void
    setReseed(long reseed)
    Set the reseed probability.
    void
    setServer(org.eclipse.jetty.server.Server server)
    Set the server associated with this id manager.
    void
    Set the housekeeper for doing scavenging.
    void
    setWorkerName(String workerName)
    Set the workername.
     

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable

    Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

    addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
  • Field Details

    • __NEW_SESSION_ID

      public static final String __NEW_SESSION_ID
      See Also:
    • COUNTER

      protected static final AtomicLong COUNTER
    • _random

      protected Random _random
    • _weakRandom

      protected boolean _weakRandom
    • _workerName

      protected String _workerName
    • _workerAttr

      protected String _workerAttr
    • _reseed

      protected long _reseed
    • _server

      protected org.eclipse.jetty.server.Server _server
    • _houseKeeper

      protected HouseKeeper _houseKeeper
    • _ownHouseKeeper

      protected boolean _ownHouseKeeper
  • Constructor Details

    • DefaultSessionIdManager

      public DefaultSessionIdManager(org.eclipse.jetty.server.Server server)
      Parameters:
      server - the server associated with the id manager
    • DefaultSessionIdManager

      public DefaultSessionIdManager(org.eclipse.jetty.server.Server server, Random random)
      Parameters:
      server - the server associated with the id manager
      random - a random number generator to use for ids
  • Method Details

    • setServer

      public void setServer(org.eclipse.jetty.server.Server server)
      Set the server associated with this id manager.
      Parameters:
      server - the server associated with this id manager
    • getServer

      public org.eclipse.jetty.server.Server getServer()
      Get the server associated with this id manager.
      Returns:
      the server associated with this id manager
    • setSessionHouseKeeper

      public void setSessionHouseKeeper(HouseKeeper houseKeeper)
      Description copied from interface: SessionIdManager
      Set the housekeeper for doing scavenging.
      Specified by:
      setSessionHouseKeeper in interface SessionIdManager
      Parameters:
      houseKeeper - the housekeeper
    • getSessionHouseKeeper

      public HouseKeeper getSessionHouseKeeper()
      Specified by:
      getSessionHouseKeeper in interface SessionIdManager
      Returns:
      the housekeeper
    • getWorkerName

      @ManagedAttribute(value="unique name for this node", readonly=true) public String getWorkerName()
      Get the workname. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.
      Specified by:
      getWorkerName in interface SessionIdManager
      Returns:
      name or null
    • setWorkerName

      public void setWorkerName(String workerName)
      Set the workername. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer. A worker name starting with $ is used as a request attribute name to lookup the worker name that can be dynamically set by a request Customizer.
      Parameters:
      workerName - the name of the worker, if null it is coerced to empty string
    • getRandom

      public Random getRandom()
      Get the random number generator.
      Returns:
      the random number generator
    • setRandom

      public void setRandom(Random random)
      Set a random number generator for generating ids.
      Parameters:
      random - a random number generator for generating ids
    • getReseed

      public long getReseed()
      Get the reseed probability.
      Returns:
      the reseed probability
    • setReseed

      public void setReseed(long reseed)
      Set the reseed probability.
      Parameters:
      reseed - If non zero then when a random long modulo the reseed value == 1, the SecureRandom will be reseeded.
    • newSessionId

      public String newSessionId(org.eclipse.jetty.server.Request request, String requestedId, long created)
      Create a new session id if necessary.
      Specified by:
      newSessionId in interface SessionIdManager
      Parameters:
      request - the request asking for a new session
      requestedId - the session id requested by the session
      created - the timestamp for when the session was created
      Returns:
      the new session id
    • newSessionId

      public String newSessionId(long seedTerm)
      Parameters:
      seedTerm - the seed for RNG
      Returns:
      a new unique session id
    • isIdInUse

      public boolean isIdInUse(String id)
      Specified by:
      isIdInUse in interface SessionIdManager
      Parameters:
      id - The plain session ID (ie no workername extension)
      Returns:
      True if the session ID is in use by at least one context.
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • initRandom

      public void initRandom()
      Set up a random number generator for the sessionids. By preference, use a SecureRandom but allow to be injected.
    • getExtendedId

      public String getExtendedId(String clusterId, org.eclipse.jetty.server.Request request)
      Get the session ID with any worker ID.
      Specified by:
      getExtendedId in interface SessionIdManager
      Parameters:
      clusterId - the cluster id
      request - the request
      Returns:
      sessionId plus any worker ID.
    • getId

      public String getId(String extendedId)
      Get the session ID without any worker ID.
      Specified by:
      getId in interface SessionIdManager
      Parameters:
      extendedId - the session id with the worker extension
      Returns:
      sessionId without any worker ID.
    • expireAll

      public void expireAll(String id)
      Remove an id from use by telling all contexts to remove a session with this id.
      Specified by:
      expireAll in interface SessionIdManager
      Parameters:
      id - The session ID without any cluster node extension
    • invalidateAll

      public void invalidateAll(String id)
      Description copied from interface: SessionIdManager
      Invalidate all sessions on all contexts that share the same id.
      Specified by:
      invalidateAll in interface SessionIdManager
      Parameters:
      id - the session id
    • scavenge

      public void scavenge()
      Specified by:
      scavenge in interface SessionIdManager
    • renewSessionId

      public String renewSessionId(String oldClusterId, String oldNodeId, org.eclipse.jetty.server.Request request)
      Generate a new id for a session and update across all SessionManagers.
      Specified by:
      renewSessionId in interface SessionIdManager
      Parameters:
      oldClusterId - the old plain session id
      oldNodeId - the old fully qualified id
      request - the request containing the session
      Returns:
      the new session id
    • getSessionManagers

      public Set<SessionManager> getSessionManagers()
      Get SessionManager for every context.
      Returns:
      all SessionManagers that are running
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.jetty.util.component.AbstractLifeCycle