Class SessionKeepAliveDaemon
java.lang.Object
java.lang.Thread
org.tentackle.task.DefaultTaskDispatcher
org.tentackle.session.SessionKeepAliveDaemon
- All Implemented Interfaces:
Runnable, Killable, Supervisable, Terminatable, TaskDispatcher
A task dispatcher to keep sessions alive.
- Author:
- harald
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class DefaultTaskDispatcher
INSTANCE_COUNTERFields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanup()Does any necessary cleanup after the dispatcher thread has been terminated.protected TaskcreateAliveTask(Session session, long interval) Creates a keep-alive task.protected ExecutorServiceCreates the executor service.Gets the executor service.Gets the sessions currently kept alive.
Useful to hand the registrations over to another daemon, should this one have died.voidkeepAliveIntervalChanged(Session session) Handles the change of a keep alive-interval of a session.voidremoveAliveTask(Session session) Removes the task for the given session.booleanremoveAliveTask(Session session, Task task) Removes the given task for the given session.voidrun()Methods inherited from class DefaultTaskDispatcher
addTask, addTaskAndWait, addTaskListener, assertAlive, assertIntervalsInRange, assertNotAlive, assertNotKilled, createLock, 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, unlockInternal, waitForTaskMethods inherited from class Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yieldMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Supervisable
getNameMethods inherited from interface TaskDispatcher
isAlive, start
-
Constructor Details
-
SessionKeepAliveDaemon
public SessionKeepAliveDaemon(long minAliveInterval) Creates the daemon.- Parameters:
minAliveInterval- the minimum alive-interval in ms
-
-
Method Details
-
cleanup
protected void cleanup()Description copied from class:DefaultTaskDispatcherDoes any necessary cleanup after the dispatcher thread has been terminated.- Overrides:
cleanupin classDefaultTaskDispatcher
-
run
public void run()- Specified by:
runin interfaceRunnable- Overrides:
runin classDefaultTaskDispatcher
-
keepAliveIntervalChanged
Handles the change of a keep alive-interval of a session.- Parameters:
session- the session
-
removeAliveTask
Removes the task for the given session.- Parameters:
session- the session
-
removeAliveTask
Removes the given task for the given session.Unlike
removeAliveTask(Session)the task is removed only if it still is the session's current task. This is what a runningSessionKeepAliveTaskmust use to unregister itself: another thread may have replaced it viakeepAliveIntervalChanged(Session)in the meantime, and removing by session alone would drop that replacement and leave the session without a keep-alive.Deliberately not synchronized on the daemon's alive-lock: the invocation comes from the daemon thread while executing the task, and the compare-and-remove is atomic in itself.
- Parameters:
session- the sessiontask- the task requesting its own removal- Returns:
- true if removed, false if the task no longer is the session's current task
-
getKeepAliveSessions
Gets the sessions currently kept alive.
Useful to hand the registrations over to another daemon, should this one have died.- Returns:
- a snapshot of the sessions, never null
-
getExecutorService
Gets the executor service.- Returns:
- the executor service
-
createExecutorService
Creates the executor service.- Returns:
- the executor service
-
createAliveTask
-