java.lang.Object
java.lang.Thread
org.tentackle.task.DefaultTaskDispatcher
org.tentackle.session.DefaultSessionTaskDispatcher
- All Implemented Interfaces:
Runnable,Killable,Supervisable,Terminatable,SessionTaskDispatcher,TaskDispatcher
public class DefaultSessionTaskDispatcher
extends 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
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class org.tentackle.task.DefaultTaskDispatcher
INSTANCE_COUNTERFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionCreates a dispatcher to be configured later.DefaultSessionTaskDispatcher(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
Modifier and TypeMethodDescriptionbooleanAdds a task to the queue.protected voidcleanup()protected SessionTaskDispatcherLockcreateLock(Object key) Gets the session.booleanReturns whether the session should be closed on termination.booleanGets 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, getWaitInterval, interrupt, isDead, isInstanceOfTaskPending, isKilled, isQueueEmpty, isTaskDispatcherThread, isTaskPending, isTerminationRequested, isUsingMutexLocking, kill, lock, lockInternal, nextTask, removeTask, removeTaskListener, requestTermination, setDead, setDeadInterval, setShutdownIdleTimeout, setSleepInterval, setUsingMutexLocking, setWaitInterval, sleepForInterval, startedAt, terminate, terminatedAt, toDiagnosticString, unlock, waitForTaskMethods 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, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tentackle.daemon.Supervisable
getNameMethods inherited from interface org.tentackle.task.TaskDispatcher
addTaskAndWait, addTaskListener, getAllTasks, getDeadInterval, getQueueSize, getShutdownIdleTimeout, getSleepInterval, getTask, getWaitInterval, isAlive, isInstanceOfTaskPending, isQueueEmpty, isTaskPending, isUsingMutexLocking, lock, removeTask, removeTaskListener, setDeadInterval, setShutdownIdleTimeout, setSleepInterval, setUsingMutexLocking, setWaitInterval, start, toDiagnosticString, unlock, waitForTaskMethods inherited from interface org.tentackle.daemon.Terminatable
isTerminationRequested, requestTermination, terminate
-
Constructor Details
-
DefaultSessionTaskDispatcher
public DefaultSessionTaskDispatcher(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
Creates a dispatcher to be configured later.- Parameters:
name- the dispatcher's name
-
-
Method Details
-
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
Description copied from interface:SessionTaskDispatcherGets the session.- Specified by:
getSessionin interfaceSessionTaskDispatcher- Returns:
- the session
-
setSession
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 to close, false to leave it 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 to close, false to leave it open
-
createLock
- Overrides:
createLockin classDefaultTaskDispatcher
-
addTask
Adds a task to the queue.- Specified by:
addTaskin interfaceTaskDispatcher- Overrides:
addTaskin classDefaultTaskDispatcher- 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 classDefaultTaskDispatcher
-
run
public void run()Overridden to set the thread-local session.
- Specified by:
runin interfaceRunnable- Overrides:
runin classDefaultTaskDispatcher
-
cleanup
protected void cleanup()Overridden to close the session.
- Overrides:
cleanupin classDefaultTaskDispatcher
-