|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.hsqldb.lib.HsqlTimer
Provides facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. This class is a JDK 1.1 compatible implementation required by HSQLDB because the java.util.Timer class is available only in JDK 1.3+.
Nested Class Summary | |
protected class |
HsqlTimer.Task
A wrapper class used to schedule a Runnable object for execution by the enclosing HsqlTimer's TaskRunner in a background thread. |
protected class |
HsqlTimer.TaskQueue
Extends HsqlArrayHeap to allow all pending tasks to be cancelled when the queue is cleared. |
protected class |
HsqlTimer.TaskRunner
The Runnable that the background thread uses to execute scheduled tasks. |
Field Summary | |
protected HsqlTimer.TaskQueue |
taskQueue
The priority queue for the scheduled tasks. |
protected HsqlTimer.TaskRunner |
taskRunner
The inner runnable that executes tasks in the background thread. |
protected Thread |
taskRunnerThread
The background thread. |
protected ThreadFactory |
threadFactory
The factory that procduces the background threads. |
Constructor Summary | |
HsqlTimer()
Constructs a new HsqlTimer using the default thread factory implementation. |
|
HsqlTimer(ThreadFactory tf)
Constructs a new HsqlTimer using the specified thread factory implementation. |
Method Summary | |
protected HsqlTimer.Task |
addTask(long n,
Runnable r,
long p,
boolean b)
Adds to the task queue a new Task object encapsulating the supplied Runnable and scheduling arguments. |
static void |
cancel(Object task)
Causes the task referenced by the supplied argument to be cancelled. |
protected void |
clearThread()
Sets the background thread to null. |
int |
compare(Object a,
Object b)
ObjectComparator implemtation required to back priority queue for scheduled tasks. |
static Date |
getLastScheduled(Object task)
Retrieves the last time the referenced task was executed, as a Date object. |
static Date |
getNextScheduled(Object task)
Retrieves the next time the referenced task is due to be executed, as a Date object. |
Thread |
getThread()
Retrieves the background thread that is currently being used to execute submitted tasks. |
static boolean |
isCancelled(Object task)
Retreives whether the specified argument references a cancelled task. |
static boolean |
isFixedDelay(Object task)
Retreives whether the specified argument references a task scheduled periodically using fixed delay scheduling. |
static boolean |
isFixedRate(Object task)
Retreives whether the specified argument references a task scheduled periodically using fixed rate scheduling. |
static boolean |
isPeriodic(Object task)
Retreives whether the specified argument references a task scheduled for periodic execution. |
protected HsqlTimer.Task |
nextTask()
Retrieves the next task to execute, or null if the background thread is interrupted. |
void |
restart()
(Re)starts background processing of the task queue. |
Object |
scheduleAfter(long delay,
Runnable r)
Causes the specified Runnable to be executed once in the background after the specified delay. |
Object |
scheduleAt(Date date,
Runnable r)
Causes the specified Runnable to be executed once in the background at the specified time. |
Object |
schedulePeriodicallyAfter(long delay,
long p,
Runnable r,
boolean relative)
Causes the specified Runnable to be executed periodically in the background, starting after the specified delay. |
Object |
schedulePeriodicallyAt(Date date,
long p,
Runnable r,
boolean relative)
Causes the specified Runnable to be executed periodically in the background, starting at the specified time. |
void |
shutDown()
Causes all pending tasks to be cancelled and then stops background processing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final HsqlTimer.TaskQueue taskQueue
protected final HsqlTimer.TaskRunner taskRunner
protected Thread taskRunnerThread
protected ThreadFactory threadFactory
Constructor Detail |
public HsqlTimer()
public HsqlTimer(ThreadFactory tf)
tf
- the ThreadFactory used to produce the background threads.
If null, the implementation supplied by HsqlThreadFactory will
be used.Method Detail |
public int compare(Object a, Object b)
compare
in interface ObjectComparator
a
- the first Taskb
- the second Task
public Thread getThread()
public void restart()
public Object scheduleAfter(long delay, Runnable r)
delay
- in millisecondsr
- the Runnable to execute.
public Object scheduleAt(Date date, Runnable r)
date
- time at which to execute the specified Runnabler
- the Runnable to execute.
public Object schedulePeriodicallyAt(Date date, long p, Runnable r, boolean relative)
p
- the cycle periodrelative
- if true, fixed rate sheduling else fixed period schedulingdate
- time at which to execute the specified Runnabler
- the Runnable to execute
public Object schedulePeriodicallyAfter(long delay, long p, Runnable r, boolean relative)
p
- the cycle periodrelative
- if true, fixed rate sheduling else fixed period schedulingdelay
- in millisecondsr
- the Runnable to execute.
public void shutDown()
public static void cancel(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static boolean isCancelled(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static boolean isFixedRate(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static boolean isFixedDelay(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static boolean isPeriodic(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static Date getLastScheduled(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.public static Date getNextScheduled(Object task) throws ClassCastException
task
- a task reference
ClassCastException
- if the task argument cannot be cast
to the type of reference returned by a scheduleXXX method
invocation.protected HsqlTimer.Task addTask(long n, Runnable r, long p, boolean b)
n
- the time of the first executionr
- the Runnable to executep
- the periodicityb
- if true, use fixed rate else use fixed period
protected void clearThread()
protected HsqlTimer.Task nextTask()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |