Classes | |
class | RunLoop |
class | TaskNode |
interface | TimerRunnable |
Public Member Functions | |
BACITimer (ThreadFactory threadFactory) | |
Object | executeAt (Date date, TimerRunnable command) |
Object | executeAfterDelay (long millisecondsToDelay, TimerRunnable command) |
Object | executePeriodically (long period, TimerRunnable command, long firstTime) |
synchronized Thread | getThread () |
synchronized void | shutDown () |
Static Public Member Functions | |
static void | cancel (Object taskID) |
Protected Member Functions | |
synchronized void | clearThread () |
synchronized void | restart () |
synchronized TaskNode | nextTask () |
Protected Attributes | |
final Heap | heap_ = new Heap(64) |
final ThreadFactory | threadFactory_ |
volatile boolean | shutdown_ = false |
Thread | thread_ |
final RunLoop | runLoop_ |
BACI timer. Based on EDU.oswego.cs.dl.util.concurrent
(it was not approriate for BACI usage). 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.
alma.ACS.jbaci.BACITimer.BACITimer | ( | ThreadFactory | threadFactory | ) |
Constructor.
threadFactory | thread factory to be used to create thread, if null no factory is being used |
References alma.ACS.jbaci.BACITimer.runLoop_, and alma.ACS.jbaci.BACITimer.threadFactory_.
static void alma.ACS.jbaci.BACITimer.cancel | ( | Object | taskID | ) | [static] |
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.
taskID | -- a task reference returned by one of the execute commands |
ClassCastException | if the taskID argument is not of the type returned by an execute command. |
synchronized void alma.ACS.jbaci.BACITimer.clearThread | ( | ) | [protected] |
set thread_ to null to indicate termination
References alma.ACS.jbaci.BACITimer.thread_.
Referenced by alma.ACS.jbaci.BACITimer.RunLoop.run().
Object alma.ACS.jbaci.BACITimer.executeAfterDelay | ( | long | millisecondsToDelay, | |
TimerRunnable | command | |||
) |
Excecute the given command after waiting for the given delay.
millisecondsToDelay | -- the number of milliseconds from now to run the command. | |
command | -- the command to run after the delay. |
References alma.ACS.jbaci.BACITimer.heap_, alma.ACS.jbaci.Heap.insert(), and alma.ACS.jbaci.BACITimer.restart().
Object alma.ACS.jbaci.BACITimer.executeAt | ( | Date | date, | |
TimerRunnable | command | |||
) |
Execute the given command at the given time.
date | -- the absolute time to run the command, expressed as a java.util.Date. | |
command | -- the command to run at the given time. |
References alma.ACS.jbaci.BACITimer.heap_, alma.ACS.jbaci.Heap.insert(), and alma.ACS.jbaci.BACITimer.restart().
Object alma.ACS.jbaci.BACITimer.executePeriodically | ( | long | period, | |
TimerRunnable | command, | |||
long | firstTime | |||
) |
Execute the given command every period
milliseconds AT FIXED RATE. If startNow
is true, execution begins immediately, otherwise, it begins after the first period
delay.
period | -- the period, in milliseconds. Periods are measured from start-of-task to the next start-of-task. It is generally a bad idea to use a period that is shorter than the expected task duration. | |
command | -- the command to run at each cycle | |
firstTime | -- time when task should start with execution, 0 means immediately. |
IllegalArgumentException | if period less than or equal to zero. |
References alma.ACS.jbaci.BACITimer.heap_, alma.ACS.jbaci.Heap.insert(), and alma.ACS.jbaci.BACITimer.restart().
synchronized Thread alma.ACS.jbaci.BACITimer.getThread | ( | ) |
Return the thread being used to process commands, or null if there is no such thread. You can use this to invoke any special methods on the thread, for example, to interrupt it.
References alma.ACS.jbaci.BACITimer.thread_.
synchronized TaskNode alma.ACS.jbaci.BACITimer.nextTask | ( | ) | [protected] |
Return the next task to execute, or null if thread is interrupted
References alma.ACS.jbaci.Heap.extract(), alma.ACS.jbaci.BACITimer.heap_, alma.ACS.jbaci.Heap.insert(), and alma.ACS.jbaci.Heap.peek().
Referenced by alma.ACS.jbaci.BACITimer.RunLoop.run().
synchronized void alma.ACS.jbaci.BACITimer.restart | ( | ) | [protected] |
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.
References alma.ACS.jbaci.BACITimer.runLoop_, alma.ACS.jbaci.BACITimer.shutdown_, alma.ACS.jbaci.BACITimer.thread_, and alma.ACS.jbaci.BACITimer.threadFactory_.
Referenced by alma.ACS.jbaci.BACITimer.executeAfterDelay(), alma.ACS.jbaci.BACITimer.executeAt(), and alma.ACS.jbaci.BACITimer.executePeriodically().
synchronized void alma.ACS.jbaci.BACITimer.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 repsond to interrupts, the current thread may persist, even if a new thread is started via restart().
References alma.ACS.jbaci.Heap.clear(), alma.ACS.jbaci.BACITimer.heap_, alma.ACS.jbaci.BACITimer.shutdown_, and alma.ACS.jbaci.BACITimer.thread_.
Referenced by alma.ACS.jbaci.BACIFramework.shutdown().
final Heap alma.ACS.jbaci.BACITimer.heap_ = new Heap(64) [protected] |
tasks are maintained in a standard priority queue
Referenced by alma.ACS.jbaci.BACITimer.executeAfterDelay(), alma.ACS.jbaci.BACITimer.executeAt(), alma.ACS.jbaci.BACITimer.executePeriodically(), alma.ACS.jbaci.BACITimer.nextTask(), and alma.ACS.jbaci.BACITimer.shutDown().
final RunLoop alma.ACS.jbaci.BACITimer.runLoop_ [protected] |
Referenced by alma.ACS.jbaci.BACITimer.BACITimer(), and alma.ACS.jbaci.BACITimer.restart().
volatile boolean alma.ACS.jbaci.BACITimer.shutdown_ = false [protected] |
shutdown status flag
Referenced by alma.ACS.jbaci.BACITimer.restart(), and alma.ACS.jbaci.BACITimer.shutDown().
Thread alma.ACS.jbaci.BACITimer.thread_ [protected] |
The thread used to process commands
Referenced by alma.ACS.jbaci.BACITimer.clearThread(), alma.ACS.jbaci.BACITimer.getThread(), alma.ACS.jbaci.BACITimer.restart(), and alma.ACS.jbaci.BACITimer.shutDown().
final ThreadFactory alma.ACS.jbaci.BACITimer.threadFactory_ [protected] |
thread factory, can be null
Referenced by alma.ACS.jbaci.BACITimer.BACITimer(), and alma.ACS.jbaci.BACITimer.restart().