- java.lang.Object
-
- java.lang.Thread
-
- org.tentackle.task.DefaultTaskDispatcher
-
- org.tentackle.session.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
-
-
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 booleanaddTask(org.tentackle.task.Task task)Adds a task to the queue.protected voidcleanup()protected SessionTaskDispatcherLockcreateLock(java.lang.Object key)SessiongetSession()Gets the session.booleanisSessionClosedOnTermination()Returns whether the session should be closed on termination.booleanisSessionKeptAlive()Gets the keepalive flag.voidrun()voidsetSession(Session session)Sets the session.voidsetSessionClosedOnTermination(boolean closeSessionOnTermination)Sets whether the session should be closed on termination.voidsetSessionKeptAlive(boolean sessionKeptAlive)Sets the keepalive flag.
If set, setAlive() will be invoked periodically to keep the session alive.protected voidunlockInternal(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.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
-
-
-
-
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 namesession- the open sessionuseMutexLocking- true use a mutex for locking, else just a counterkeepAliveMillis- keep alive in millisecondsdeadInterval- 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:SessionTaskDispatcherSets the keepalive flag.
If set, setAlive() will be invoked periodically to keep the session alive.- Specified by:
setSessionKeptAlivein interfaceSessionTaskDispatcher- Parameters:
sessionKeptAlive- true if ping enabled
-
isSessionKeptAlive
public boolean isSessionKeptAlive()
Description copied from interface:SessionTaskDispatcherGets the keepalive flag.- Specified by:
isSessionKeptAlivein interfaceSessionTaskDispatcher- Returns:
- true if ping enabled
-
getSession
public Session getSession()
Description copied from interface:SessionTaskDispatcherGets the session.- Specified by:
getSessionin interfaceSessionTaskDispatcher- Returns:
- the session
-
setSession
public void setSession(Session session)
Description copied from interface:SessionTaskDispatcherSets the session.- Specified by:
setSessionin interfaceSessionTaskDispatcher- Parameters:
session- the session
-
isSessionClosedOnTermination
public boolean isSessionClosedOnTermination()
Description copied from interface:SessionTaskDispatcherReturns whether the session should be closed on termination.- Specified by:
isSessionClosedOnTerminationin interfaceSessionTaskDispatcher- Returns:
- true if should be closed, false if remains open
-
setSessionClosedOnTermination
public void setSessionClosedOnTermination(boolean closeSessionOnTermination)
Description copied from interface:SessionTaskDispatcherSets whether the session should be closed on termination.- Specified by:
setSessionClosedOnTerminationin interfaceSessionTaskDispatcher- Parameters:
closeSessionOnTermination- true if should be closed, false if remains open
-
createLock
protected SessionTaskDispatcherLock createLock(java.lang.Object key)
- Overrides:
createLockin classorg.tentackle.task.DefaultTaskDispatcher
-
addTask
public boolean addTask(org.tentackle.task.Task task)
Adds a task to the queue.- Specified by:
addTaskin interfaceorg.tentackle.task.TaskDispatcher- Overrides:
addTaskin classorg.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:
unlockInternalin classorg.tentackle.task.DefaultTaskDispatcher
-
run
public void run()
Overridden to set the thread-local session.
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classorg.tentackle.task.DefaultTaskDispatcher
-
cleanup
protected void cleanup()
Overridden to close the session.
- Overrides:
cleanupin classorg.tentackle.task.DefaultTaskDispatcher
-
-