Class DefaultSessionTaskDispatcher

  • All Implemented Interfaces:
    java.lang.Runnable, org.tentackle.daemon.Killable, org.tentackle.daemon.Supervisable, org.tentackle.daemon.Terminatable, SessionTaskDispatcher, org.tentackle.task.TaskDispatcher

    public class DefaultSessionTaskDispatcher
    extends org.tentackle.task.DefaultTaskDispatcher
    implements SessionTaskDispatcher
    A thread executing tasks in a serialized manner on an exclusive connection.
    Author:
    harald
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class org.tentackle.task.DefaultTaskDispatcher

        INSTANCE_COUNTER
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSessionTaskDispatcher​(java.lang.String name)
      Creates a dispatcher to be configured later.
      DefaultSessionTaskDispatcher​(java.lang.String name, Session session, boolean useMutexLocking, long keepAliveMillis, long deadInterval)
      Creates an execution thread for a given session.
      The session must not be used by any other thread!
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addTask​(org.tentackle.task.Task task)
      Adds a task to the queue.
      protected void cleanup()
      protected SessionTaskDispatcherLock createLock​(java.lang.Object key)  
      Session getSession()
      Gets the session.
      boolean isSessionClosedOnTermination()
      Returns whether the session should be closed on termination.
      boolean isSessionKeptAlive()
      Gets the keepalive flag.
      void run()
      void setSession​(Session session)
      Sets the session.
      void setSessionClosedOnTermination​(boolean closeSessionOnTermination)
      Sets whether the session should be closed on termination.
      void setSessionKeptAlive​(boolean sessionKeptAlive)
      Sets the keepalive flag.
      If set, setAlive() will be invoked periodically to keep the session alive.
      protected void unlockInternal​(long sleepMs)
      • Methods inherited from class org.tentackle.task.DefaultTaskDispatcher

        addTaskAndWait, addTaskListener, assertAlive, assertIntervalsInRange, assertNotAlive, assertNotKilled, executeTask, fireCompleted, fireStarted, getAllTasks, getDeadInterval, getQueueSize, getShutdownIdleTimeout, getSleepInterval, getTask, getTerminationCause, interrupt, isDead, isInstanceOfTaskPending, isKilled, isQueueEmpty, isTaskDispatcherThread, isTaskPending, isTerminationRequested, isUsingMutexLocking, kill, lock, lockInternal, nextTask, removeTask, removeTaskListener, requestTermination, setDead, setDeadInterval, setShutdownIdleTimeout, setSleepInterval, setUsingMutexLocking, sleepForInterval, startedAt, terminate, terminatedAt, toDiagnosticString, unlock, waitForTask
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.tentackle.daemon.Supervisable

        getName
      • Methods inherited from interface org.tentackle.task.TaskDispatcher

        addTaskAndWait, addTaskListener, getAllTasks, getDeadInterval, getQueueSize, getShutdownIdleTimeout, getSleepInterval, getTask, isAlive, isInstanceOfTaskPending, isQueueEmpty, isTaskPending, isUsingMutexLocking, lock, removeTask, removeTaskListener, setDeadInterval, setShutdownIdleTimeout, setSleepInterval, setUsingMutexLocking, start, toDiagnosticString, unlock, waitForTask
      • Methods inherited from interface org.tentackle.daemon.Terminatable

        isTerminationRequested, requestTermination, terminate
    • Constructor Detail

      • DefaultSessionTaskDispatcher

        public DefaultSessionTaskDispatcher​(java.lang.String name,
                                            Session session,
                                            boolean useMutexLocking,
                                            long keepAliveMillis,
                                            long deadInterval)
        Creates an execution thread for a given session.
        The session must not be used by any other thread!

        Parameters:
        name - the dispatcher's name
        session - the open session
        useMutexLocking - true use a mutex for locking, else just a counter
        keepAliveMillis - keep alive in milliseconds
        deadInterval - interval in milliseconds to detect a dead dispatcher, 0 to disable detection
      • DefaultSessionTaskDispatcher

        public DefaultSessionTaskDispatcher​(java.lang.String name)
        Creates a dispatcher to be configured later.
        Parameters:
        name - the dispatcher's name
    • Method Detail

      • setSessionKeptAlive

        public void setSessionKeptAlive​(boolean sessionKeptAlive)
        Description copied from interface: SessionTaskDispatcher
        Sets the keepalive flag.
        If set, setAlive() will be invoked periodically to keep the session alive.
        Specified by:
        setSessionKeptAlive in interface SessionTaskDispatcher
        Parameters:
        sessionKeptAlive - true if ping enabled
      • setSessionClosedOnTermination

        public void setSessionClosedOnTermination​(boolean closeSessionOnTermination)
        Description copied from interface: SessionTaskDispatcher
        Sets whether the session should be closed on termination.
        Specified by:
        setSessionClosedOnTermination in interface SessionTaskDispatcher
        Parameters:
        closeSessionOnTermination - true if should be closed, false if remains open
      • createLock

        protected SessionTaskDispatcherLock createLock​(java.lang.Object key)
        Overrides:
        createLock in class org.tentackle.task.DefaultTaskDispatcher
      • addTask

        public boolean addTask​(org.tentackle.task.Task task)
        Adds a task to the queue.
        Specified by:
        addTask in interface org.tentackle.task.TaskDispatcher
        Overrides:
        addTask in class org.tentackle.task.DefaultTaskDispatcher
        Parameters:
        task - the task to add
        Returns:
        true if added, false if already in queue
      • unlockInternal

        protected void unlockInternal​(long sleepMs)

        Overridden to run Session.setAlive(boolean) when sleeping for a while.

        Overrides:
        unlockInternal in class org.tentackle.task.DefaultTaskDispatcher
      • run

        public void run()

        Overridden to set the thread-local session.

        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class org.tentackle.task.DefaultTaskDispatcher
      • cleanup

        protected void cleanup()

        Overridden to close the session.

        Overrides:
        cleanup in class org.tentackle.task.DefaultTaskDispatcher