Package org.epics.ca.impl.search
Class SearchTimer
- java.lang.Object
-
- java.lang.Thread
-
- org.epics.ca.impl.search.SearchTimer
-
- All Implemented Interfaces:
java.lang.Runnable
public class SearchTimer extends java.lang.ThreadTimer. Based onEDU.oswego.cs.dl.util.concurrent. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSearchTimer.HeapA heap-based priority queue.protected classSearchTimer.RunLoopThe run loop is isolated in its own Runnable class just so that the main class need not implement Runnable, which would allow others to directly invoke run, which is not supported.static classSearchTimer.TimerTask
-
Field Summary
Fields Modifier and Type Field Description protected SearchTimer.HeapheapTasks are maintained in a standard priority queue.protected SearchTimer.RunLooprunLoopprotected java.lang.ThreadthreadThe thread used to process commands
-
Constructor Summary
Constructors Constructor Description SearchTimer()Protected constructor (singleton pattern).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidcancel(java.lang.Object taskID)Cancel a scheduled task that has not yet been run.protected voidclearThread()set thread to null to indicate terminationvoidexecuteAfterDelay(long millisecondsToDelay, SearchTimer.TimerTask task)Execute the given command after waiting for the given delay.java.lang.ThreadgetThread()booleanhasNext(long dT)Check whether there is a task scheduled in next "dT" ms.protected SearchTimer.TimerTasknextTask(boolean blockAndExtract, long dt)Return the next task to execute, or null if thread is interrupted.voidrescheduleAllAfterDelay(long millisecondsToDelay)voidrestart()Start (or restart) a thread to process commands, or wake up an existing thread if one is already running.voidshutDown()Cancel all tasks and interrupt the background thread executing the current task, if any.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
heap
protected final SearchTimer.Heap heap
Tasks are maintained in a standard priority queue.
-
runLoop
protected final SearchTimer.RunLoop runLoop
-
thread
protected java.lang.Thread thread
The thread used to process commands
-
-
Method Detail
-
executeAfterDelay
public void executeAfterDelay(long millisecondsToDelay, SearchTimer.TimerTask task)Execute the given command after waiting for the given delay.- Parameters:
millisecondsToDelay- -- the number of milliseconds from now to run the command.task- -- timer task
-
rescheduleAllAfterDelay
public void rescheduleAllAfterDelay(long millisecondsToDelay)
-
cancel
public static void cancel(java.lang.Object taskID)
Cancel a scheduled task that has not yet been run. The task will be cancelled upon the next opportunity to run it. This has no effect if this is a one-shot task that has already executed. Also, if an execution is in progress, it will complete normally. (It may however be interrupted via getThread().interrupt()). But if it is a periodic task, future iterations are cancelled.- Parameters:
taskID- -- a task reference returned by one of the execute commands- Throws:
java.lang.ClassCastException- if the taskID argument is not of the type returned by an execute command.
-
getThread
public java.lang.Thread getThread()
-
clearThread
protected void clearThread()
set thread to null to indicate termination
-
restart
public void restart()
Start (or restart) a thread to process commands, or wake up an existing thread if one is already running. This method can be invoked if the background thread crashed due to an unrecoverable exception in an executed command.
-
shutDown
public void shutDown()
Cancel all tasks and interrupt the background thread executing the current task, if any. A new background thread will be started if new execution requests are encountered. If the currently executing task does not respond to interrupts, the current thread may persist, even if a new thread is started via restart().
-
nextTask
protected SearchTimer.TimerTask nextTask(boolean blockAndExtract, long dt)
Return the next task to execute, or null if thread is interrupted.- Parameters:
blockAndExtract- block and extractdt- dt- Returns:
- the timer task.
-
hasNext
public boolean hasNext(long dT)
Check whether there is a task scheduled in next "dT" ms.- Parameters:
dT- dT- Returns:
- boolean
-
-