Class 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.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:
    HouseKeeper
    • Field Detail

      • 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 Server _server
      • _ownHouseKeeper

        protected boolean _ownHouseKeeper
    • Constructor Detail

      • DefaultSessionIdManager

        public DefaultSessionIdManager​(Server server)
        Parameters:
        server - the server associated with the id manager
      • DefaultSessionIdManager

        public DefaultSessionIdManager​(Server server,
                                       Random random)
        Parameters:
        server - the server associated with the id manager
        random - a random number generator to use for ids
    • Method Detail

      • setServer

        public void setServer​(Server server)
        Parameters:
        server - the server associated with this id manager
      • getServer

        public Server getServer()
        Returns:
        the server associated with this id manager
      • 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()
        Returns:
        the random number generator
      • setRandom

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

        public long getReseed()
        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​(long seedTerm)
        Parameters:
        seedTerm - the seed for RNG
        Returns:
        a new unique session id
      • doStart

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

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        Exception
        See Also:
        AbstractLifeCycle.doStop()
      • 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,
                                    HttpServletRequest 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.
      • 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
      • toString

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