Class AbstractADEPT2Service.ActiveSessions

  • Enclosing class:
    AbstractADEPT2Service

    protected static class AbstractADEPT2Service.ActiveSessions
    extends Object
    This class manages all sessions and threads currently active in this service. Each session has to register and deregister itself in every method of this service. The registration is reentrant, which means, multiple invocations with the same session as well as with the same thread are tracked. Additionally when registering a session the current thread is also stored. This allows to interrupt the threads currently executing a session in this service. For this to work a session has to be registered and deregistered by the same thread! This is usually the case when the corresponding session is registered right after calling the method and deregistered at the end of the method.
    If the service has been shut down, all registrations are refused. The calling method has to return immediately.
    This class relies on the fact that parent sessions and sub sessions have the same UUID.
    Author:
    Ulrich Kreher
    • Constructor Detail

      • ActiveSessions

        public ActiveSessions()
        Constructor creating and initialising the fields.
    • Method Detail

      • sessionActive

        protected void sessionActive​(SessionToken session)
        Registers the designated session as active and also tracks the current thread.

        This method synchronises on this object. So be sure not to hold any locks or at least acquire the locks in a well-defined order.

        Parameters:
        session - The session token with which a method is called and therefore active.
      • sessionFinished

        protected boolean sessionFinished​(SessionToken session)
        Deregisters the designated session and also removes the current thread.

        This method synchronises on this object. So be sure not to hold any locks or at least acquire the locks in a well-defined order.

        Parameters:
        session - The session token with which a method has been executed and which is not active any more in this service.
        Returns:
        Whether the top-level session of the designated session is not active any more, that is, it does not have any active subsessions left.
      • getCurrentParentSessionCount

        public int getCurrentParentSessionCount()
        Returns the number of currently active parent sessions; subsessions do not count separately.
        Returns:
        The number of currently active parent sessions.
      • isActive

        public boolean isActive​(SessionToken session)
        Returns whether the designated session token (or a session token having the same top-level session) is currently active or privileged.
        Parameters:
        session - The session to check its top-level session to be currently active.
        Returns:
        Whether the designated session token (or a session token having the same top-level session) is currently active or privileged.
      • getCurrentSessionCount

        public int getCurrentSessionCount()
        Returns the total number of currently active sessions; subsessions are counted separately.
        Returns:
        The total number of currently active sessions including subsessions.
      • privilegeSession

        protected void privilegeSession​(SessionToken session)
        Privileges the designated session, that is the session may access the service even when shutting down or initialising.
        Parameters:
        session - The session which should be privileged.
      • awaitTermination

        public boolean awaitTermination​(long timeout)
                                 throws InterruptedException
        Waits the designated time in milliseconds (0 means waiting until condition is true) until no sessions are active any more. Note that this does not necessarily mean, that no sessions will be accepted any more. It just means, there are currently no active sessions. For a real termination, other measures have to be taken to prevent new sessions from entering.
        Parameters:
        timeout - The time in milliseconds to wait until no more sessions are active.
        Returns:
        Whether no sessions are active any more.
        Throws:
        InterruptedException - If the current thread is interrupted while waiting for the termination, an InterruptedException will be thrown.
      • interruptActiveSessions

        public void interruptActiveSessions​(Set<Thread> nonInterrupted)
        Interrupts the threads that currently execute active sessions except the designated one.
        Parameters:
        nonInterrupted - The threads that are not to be interrupted.
      • privilegeActiveSessions

        public void privilegeActiveSessions()
        Privileges all currently active session to allow their normal termination