Class ManagerBase

  • All Implemented Interfaces:
    Manager
    Direct Known Subclasses:
    PersistentManagerBase, StandardManager

    public abstract class ManagerBase
    extends Object
    implements Manager
    Minimal implementation of the Manager interface that supports no session persistence or distributable capabilities. This class may be subclassed to create more sophisticated Manager implementations.
    Version:
    $Revision: 1.23.2.3 $ $Date: 2008/04/17 18:37:20 $
    Author:
    Craig R. McClanahan
    • Field Detail

      • log

        protected static final Logger log
      • devRandomSource

        protected String devRandomSource
      • container

        protected Container container
        The Container with which this Manager is associated.
      • debug

        protected int debug
        The debugging detail level for this component.
      • distributable

        protected boolean distributable
        The distributable flag for Sessions created by this Manager. If this flag is set to true, any user attributes added to a session controlled by this Manager must be Serializable.
      • entropy

        protected String entropy
        A String initialization parameter used to increase the entropy of the initialization of our random number generator.
      • sessionLocker

        protected SessionLocker sessionLocker
        A SessionLocker used to lock sessions (curently only in the request dispatcher forward/include use case)
      • maxInactiveInterval

        protected int maxInactiveInterval
        The default maximum inactive interval for Sessions created by this Manager.
      • sessionIdLength

        protected int sessionIdLength
        The session id length of Sessions created by this Manager.
      • name

        protected static final String name
        The descriptive name of this Manager implementation (for logging).
        See Also:
        Constant Field Values
      • uuidGenerator

        protected UuidGenerator uuidGenerator
        The Uuid Generator to be used when generating universally unique session identifiers. HERCULES: add
      • randomClass

        protected String randomClass
        The Java class name of the random number generator class to be used when generating session identifiers.
      • sessionMaxAliveTime

        protected int sessionMaxAliveTime
        The longest time (in seconds) that an expired session had been alive.
      • sessionAverageAliveTime

        protected int sessionAverageAliveTime
        Average time (in seconds) that expired sessions had been alive.
      • expiredSessions

        protected int expiredSessions
        Number of sessions that have expired.
      • sessions

        protected final Map<String,​Session> sessions
        The set of currently active Sessions for this Manager, keyed by session identifier.
      • sessionCounter

        protected int sessionCounter
      • maxActive

        protected volatile int maxActive
      • maxActiveUpdateLock

        protected final Object maxActiveUpdateLock
      • duplicates

        protected int duplicates
      • initialized

        protected boolean initialized
      • rejectedSessions

        protected int rejectedSessions
        Number of times a session was not created because the maximum number of active sessions had been reached.
      • domain

        protected String domain
    • Constructor Detail

      • ManagerBase

        public ManagerBase()
    • Method Detail

      • getUuidGenerator

        public UuidGenerator getUuidGenerator()
        Return the UuidGenerator for this Manager. HERCULES:added
      • setUuidGenerator

        public void setUuidGenerator​(UuidGenerator aUuidGenerator)
        Set the UuidGenerator for this Manager. HERCULES:added
      • getContainer

        public Container getContainer()
        Return the Container with which this Manager is associated.
        Specified by:
        getContainer in interface Manager
      • setContainer

        public void setContainer​(Container container)
        Set the Container with which this Manager is associated.
        Specified by:
        setContainer in interface Manager
        Parameters:
        container - The newly associated Container
      • getDebug

        public int getDebug()
        Return the debugging detail level for this component.
      • setDebug

        public void setDebug​(int debug)
        Set the debugging detail level for this component.
        Parameters:
        debug - The new debugging detail level
      • getClassName

        public String getClassName()
        Returns the name of the implementation class.
      • getDistributable

        public boolean getDistributable()
        Return the distributable flag for the sessions supported by this Manager.
        Specified by:
        getDistributable in interface Manager
      • setDistributable

        public void setDistributable​(boolean distributable)
        Set the distributable flag for the sessions supported by this Manager. If this flag is set, all user data objects added to sessions associated with this manager must implement Serializable.
        Specified by:
        setDistributable in interface Manager
        Parameters:
        distributable - The new distributable flag
      • getEntropy

        public String getEntropy()
        Return the entropy increaser value, or compute a semi-useful value if this String has not yet been set.
      • setEntropy

        public void setEntropy​(String entropy)
        Set the entropy increaser value.
        Parameters:
        entropy - The new entropy increaser value
      • getInfo

        public String getInfo()
        Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
        Specified by:
        getInfo in interface Manager
      • getMaxInactiveInterval

        public int getMaxInactiveInterval()
        Same as getMaxInactiveIntervalSeconds
        Specified by:
        getMaxInactiveInterval in interface Manager
      • getMaxInactiveIntervalSeconds

        public int getMaxInactiveIntervalSeconds()
        Return the default maximum inactive interval (in seconds) for Sessions created by this Manager.
        Specified by:
        getMaxInactiveIntervalSeconds in interface Manager
      • setMaxInactiveInterval

        public void setMaxInactiveInterval​(int interval)
        Same as setMaxInactiveIntervalSeconds
        Specified by:
        setMaxInactiveInterval in interface Manager
      • setMaxInactiveIntervalSeconds

        public void setMaxInactiveIntervalSeconds​(int interval)
        Set the default maximum inactive interval (in seconds) for Sessions created by this Manager.
        Specified by:
        setMaxInactiveIntervalSeconds in interface Manager
        Parameters:
        interval - The new default value
      • getSessionIdLength

        public int getSessionIdLength()
        Gets the session id length (in bytes) of Sessions created by this Manager.
        Specified by:
        getSessionIdLength in interface Manager
        Returns:
        The session id length
      • setSessionIdLength

        public void setSessionIdLength​(int idLength)
        Sets the session id length (in bytes) for Sessions created by this Manager.
        Specified by:
        setSessionIdLength in interface Manager
        Parameters:
        idLength - The session id length
      • getRejectedSessions

        public int getRejectedSessions()
        Gets the number of session creations that failed due to maxActiveSessions
        Specified by:
        getRejectedSessions in interface Manager
        Returns:
        number of session creations that failed due to maxActiveSessions
      • setRejectedSessions

        public void setRejectedSessions​(int rejectedSessions)
        Sets the number of sessions that were not created because the maximum number of active sessions was reached.
        Specified by:
        setRejectedSessions in interface Manager
        Parameters:
        rejectedSessions - Number of rejected sessions
      • getName

        public String getName()
        Return the descriptive short name of this Manager implementation.
      • setRandomFile

        public void setRandomFile​(String s)
        Use /dev/random-type special device. This is new code, but may reduce the big delay in generating the random. You must specify a path to a random generator file. Use /dev/urandom for linux ( or similar ) systems. Use /dev/random for maximum security ( it may block if not enough "random" exist ). You can also use a pipe that generates random. The code will check if the file exists, and default to java Random if not found. There is a significant performance difference, very visible on the first call to getSession ( like in the first JSP ) - so use it if available.
      • getRandomFile

        public String getRandomFile()
      • getRandom

        public SecureRandom getRandom()
        Return the random number generator instance we should use for generating session identifiers. If there is no such generator currently defined, construct and seed a new one.
      • resetRandom

        protected void resetRandom()
        Reset the random number generator instance to null.
      • getRandomClass

        public String getRandomClass()
        Return the random number generator class name.
      • setRandomClass

        public void setRandomClass​(String randomClass)
        Set the random number generator class name.
        Parameters:
        randomClass - The new random number generator class name
      • getExpiredSessions

        public int getExpiredSessions()
        Gets the number of sessions that have expired.
        Specified by:
        getExpiredSessions in interface Manager
        Returns:
        Number of sessions that have expired
      • setExpiredSessions

        public void setExpiredSessions​(int expiredSessions)
        Sets the number of sessions that have expired.
        Specified by:
        setExpiredSessions in interface Manager
        Parameters:
        expiredSessions - Number of sessions that have expired
      • setSessionLocker

        public void setSessionLocker​(SessionLocker sessLocker)
        set the pluggable sessionLocker for this manager by default it is pre-set to no-op BaseSessionLocker
      • destroy

        public void destroy()
      • init

        public void init()
      • add

        public void add​(Session session)
        Add this Session to the set of active Sessions for this Manager.
        Specified by:
        add in interface Manager
        Parameters:
        session - Session to be added
      • createSession

        public Session createSession()
        Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id will be assigned by this method, and available via the getId() method of the returned session. If a new session cannot be created for any reason, return null. Hercules: modified
        Specified by:
        createSession in interface Manager
        Throws:
        IllegalStateException - if a new session cannot be instantiated for any reason
      • createSession

        public Session createSession​(String sessionId)
        Construct and return a new session object, based on the default settings specified by this Manager's properties, using the specified session id. IMPLEMENTATION NOTE: This method must be kept in sync with the createSession method that takes no arguments.
        Specified by:
        createSession in interface Manager
        Parameters:
        sessionId - the session id to assign to the new session
        Returns:
        the new session, or null if a session with the requested id already exists
        Throws:
        IllegalStateException - if a new session cannot be instantiated for any reason
      • createEmptySession

        public Session createEmptySession()
        Get a session from the recycled ones or create a new empty one. The PersistentManager manager does not need to create session data because it reads it from the Store.
        Specified by:
        createEmptySession in interface Manager
      • checkSessionAttribute

        public void checkSessionAttribute​(String name,
                                          Object value)
        Description copied from interface: Manager
        Checks the given session attribute name and value to make sure they comply with any restrictions set forth by this session manager. For example, in the case of cookie-based persistence, session attribute values must be of type String.
        Specified by:
        checkSessionAttribute in interface Manager
        Parameters:
        name - the session attribute name
        value - the session attribute value
      • findSession

        public Session findSession​(String id)
                            throws IOException
        Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return null.
        Specified by:
        findSession in interface Manager
        Parameters:
        id - The session id for the session to be returned
        Throws:
        IllegalStateException - if a new session cannot be instantiated for any reason
        IOException - if an input/output error occurs while processing this request
      • findSession

        public Session findSession​(String id,
                                   jakarta.servlet.http.HttpServletRequest request)
                            throws IOException
        Description copied from interface: Manager
        Gets the session with the given id from the given request.
        Specified by:
        findSession in interface Manager
        Parameters:
        id - the session id
        request - the request containing the requested session information
        Returns:
        the requested session, or null if not found
        Throws:
        IOException
      • findSession

        public Session findSession​(String id,
                                   String version)
                            throws IOException
        Finds and returns the session with the given id that also satisfies the given version requirement. This overloaded version of findSession() will be invoked only if isSessionVersioningSupported() returns true. By default, this method delegates to the version of findSession() that does not take any session version number.
        Specified by:
        findSession in interface Manager
        Parameters:
        id - The session id to match
        version - The session version requirement to satisfy
        Returns:
        The session that matches the given id and also satisfies the given version requirement, or null if no such session could be found by this session manager
        Throws:
        IOException - if an IO error occurred
      • isSessionVersioningSupported

        public boolean isSessionVersioningSupported()
        Returns true if this session manager supports session versioning, false otherwise.
        Specified by:
        isSessionVersioningSupported in interface Manager
        Returns:
        true if this session manager supports session versioning, false otherwise.
      • clearSessions

        public void clearSessions()
        clear out the sessions cache HERCULES:added
      • findSessions

        public List<Session> findSessions()
        Description copied from interface: Manager
        Return the set of active Sessions associated with this Manager. If this Manager has no active Sessions, a empty list is returned.
        Specified by:
        findSessions in interface Manager
        Returns:
        associated sessions
      • remove

        public void remove​(Session session)
        Remove this Session from the active Sessions for this Manager.
        Specified by:
        remove in interface Manager
        Parameters:
        session - Session to be removed
      • toCookie

        public jakarta.servlet.http.Cookie toCookie​(Session session)
                                             throws IOException
        Description copied from interface: Manager
        Converts the given session into a cookie as a way of persisting it.
        Specified by:
        toCookie in interface Manager
        Parameters:
        session - the session to convert
        Returns:
        the cookie representation of the given session
        Throws:
        IOException
      • changeSessionId

        public void changeSessionId​(Session session)
        Change the session ID of the current session to a new randomly generated session ID.
        Specified by:
        changeSessionId in interface Manager
        Parameters:
        session - The session to change the session ID for
      • getNewSession

        protected StandardSession getNewSession()
        Get new session class to be used in the doLoad() method.
      • getRandomBytes

        protected void getRandomBytes​(byte[] bytes)
      • generateSessionId

        protected String generateSessionId​(Object obj)
        Generate and return a new session identifier. Hercules:added
      • generateSessionId

        protected String generateSessionId()
        Generate and return a new session identifier. Hercules:modified
      • getEngine

        public Engine getEngine()
        Retrieve the enclosing Engine for this Manager.
        Returns:
        an Engine object (or null).
      • getJvmRoute

        public String getJvmRoute()
        Retrieve the JvmRoute for the enclosing Engine.
        Returns:
        the JvmRoute or null.
      • log

        protected void log​(String message)
        Deprecated.
        Log a message on the Logger associated with our Container (if any).
        Parameters:
        message - Message to be logged
      • log

        protected void log​(String message,
                           Throwable throwable)
        Deprecated.
        Log a message on the Logger associated with our Container (if any).
        Parameters:
        message - Message to be logged
        throwable - Associated exception
      • setSessionCounter

        public void setSessionCounter​(int sessionCounter)
        Same as setSessionCount
        Specified by:
        setSessionCounter in interface Manager
      • setSessionCount

        public void setSessionCount​(int sessionCounter)
        Description copied from interface: Manager
        Sets the total number of sessions created by this manager.
        Specified by:
        setSessionCount in interface Manager
        Parameters:
        sessionCounter - Total number of sessions created by this manager.
      • getSessionCounter

        public int getSessionCounter()
        Same as getSessionCount
        Specified by:
        getSessionCounter in interface Manager
      • getSessionCount

        public int getSessionCount()
        Total sessions created by this manager.
        Specified by:
        getSessionCount in interface Manager
        Returns:
        sessions created
      • getDuplicates

        public int getDuplicates()
        Number of duplicated session IDs generated by the random source. Anything bigger than 0 means problems.
        Returns:
      • setDuplicates

        public void setDuplicates​(int duplicates)
      • getActiveSessions

        public int getActiveSessions()
        Returns the number of active sessions
        Specified by:
        getActiveSessions in interface Manager
        Returns:
        number of sessions active
      • getMaxActive

        public int getMaxActive()
        Max number of concurent active sessions
        Specified by:
        getMaxActive in interface Manager
        Returns:
      • setMaxActive

        public void setMaxActive​(int maxActive)
        Description copied from interface: Manager
        (Re)sets the maximum number of sessions that have been active at the same time.
        Specified by:
        setMaxActive in interface Manager
        Parameters:
        maxActive - Maximum number of sessions that have been active at the same time.
      • getSessionMaxAliveTime

        public int getSessionMaxAliveTime()
        Same as getSessionMaxAliveTimeSeconds
        Specified by:
        getSessionMaxAliveTime in interface Manager
      • getSessionMaxAliveTimeSeconds

        public int getSessionMaxAliveTimeSeconds()
        Gets the longest time (in seconds) that an expired session had been alive.
        Specified by:
        getSessionMaxAliveTimeSeconds in interface Manager
        Returns:
        Longest time (in seconds) that an expired session had been alive.
      • setSessionMaxAliveTime

        public void setSessionMaxAliveTime​(int sessionMaxAliveTime)
        Same as setSessionMaxAliveTimeSeconds
        Specified by:
        setSessionMaxAliveTime in interface Manager
      • setSessionMaxAliveTimeSeconds

        public void setSessionMaxAliveTimeSeconds​(int sessionMaxAliveTime)
        Sets the longest time (in seconds) that an expired session had been alive.
        Specified by:
        setSessionMaxAliveTimeSeconds in interface Manager
        Parameters:
        sessionMaxAliveTime - Longest time (in seconds) that an expired session had been alive.
      • getSessionAverageAliveTime

        public int getSessionAverageAliveTime()
        Same as getSessionAverageAliveTimeSeconds
        Specified by:
        getSessionAverageAliveTime in interface Manager
      • getSessionAverageAliveTimeSeconds

        public int getSessionAverageAliveTimeSeconds()
        Gets the average time (in seconds) that expired sessions had been alive.
        Specified by:
        getSessionAverageAliveTimeSeconds in interface Manager
        Returns:
        Average time (in seconds) that expired sessions had been alive.
      • setSessionAverageAliveTime

        public void setSessionAverageAliveTime​(int sessionAverageAliveTime)
        Same as setSessionAverageAliveTimeSeconds
        Specified by:
        setSessionAverageAliveTime in interface Manager
      • setSessionAverageAliveTimeSeconds

        public void setSessionAverageAliveTimeSeconds​(int sessionAverageAliveTime)
        Sets the average time (in seconds) that expired sessions had been alive.
        Specified by:
        setSessionAverageAliveTimeSeconds in interface Manager
        Parameters:
        sessionAverageAliveTime - Average time (in seconds) that expired sessions had been alive.
      • listSessionIds

        public String listSessionIds()
        For debugging: return a list of all session ids currently active
      • getSessionAttribute

        public String getSessionAttribute​(String sessionId,
                                          String key)
        For debugging: get a session attribute
        Parameters:
        sessionId -
        key -
        Returns:
      • expireSession

        public void expireSession​(String sessionId)
      • getLastAccessedTimeMillis

        public String getLastAccessedTimeMillis​(String sessionId)
      • update

        public void update​(jakarta.servlet.http.HttpSession session)
                    throws Exception
        Perform any operations when the request is finished.
        Specified by:
        update in interface Manager
        Throws:
        Exception
      • getObjectName

        public ObjectName getObjectName()
      • getDomain

        public String getDomain()
      • postRequestDispatcherProcess

        public void postRequestDispatcherProcess​(jakarta.servlet.ServletRequest request,
                                                 jakarta.servlet.ServletResponse response)
        Specified by:
        postRequestDispatcherProcess in interface Manager
      • preRequestDispatcherProcess

        public void preRequestDispatcherProcess​(jakarta.servlet.ServletRequest request,
                                                jakarta.servlet.ServletResponse response)
        Specified by:
        preRequestDispatcherProcess in interface Manager
      • lockSession

        public boolean lockSession​(jakarta.servlet.ServletRequest request)
                            throws jakarta.servlet.ServletException
        Specified by:
        lockSession in interface Manager
        Throws:
        jakarta.servlet.ServletException
      • unlockSession

        public void unlockSession​(jakarta.servlet.ServletRequest request)
        Specified by:
        unlockSession in interface Manager
      • release

        public void release()