| java.lang.Object com.sun.perseus.util.RunnableQueue
RunnableQueue | final public class RunnableQueue implements Runnable(Code) | | This class represents an object which queues Runnable objects for
invocation in a single thread.
This class is derived from work done in the Batik project but was
seriously modified and extended.
version: $Id: RunnableQueue.java,v 1.5 2006/04/21 06:35:50 st125089 Exp $ |
Inner Class :public interface RunnableHandler | |
Inner Class :public interface RunnableQueueHandler | |
Inner Class :public static class VoidQueueHandler implements RunnableQueueHandler | |
Inner Class :protected static class LockableLink extends Link | |
Field Summary | |
final public static String | RUNNING The queue is in the processes of running tasks. | final public static String | SUSPENDED The queue is no longer running any tasks and will not
run any tasks until resumeExecution is called. | final public static String | SUSPENDING The queue may still be running tasks but as soon as possible
will go to SUSPENDED state. | final public static String | TERMINATED | protected static RunnableQueue | defaultQueue The default RunnableQueue instance. | protected DoublyLinkedList | list The Runnable objects list, also used as synchoronization point
for pushing/poping runables. | protected RunnableQueueHandler | queueHandler The object which handles RunnableQueue events. | protected Thread | runnableQueueThread The current thread. | protected Scheduler | scheduler The Scheduler which can run Runnables at a fixed
rate. | protected String | state The Suspension state of this thread. | protected Object | stateLock Object to synchronize/wait/notify for suspension
issues. |
Method Summary | |
public static RunnableQueue | createRunnableQueue(RunnableQueueHandler queueHandler) Creates a new RunnableQueue started in a new thread.
Parameters: queueHandler - the RunnableQueueHandler which will be notifiedof the RunnableQueue's activity. | public void | empty() Removes all pending Runnable s. | public static RunnableQueue | getDefault() Returns the default RunnableQueue instance. | public Runnable | getNextPending() | public String | getQueueState() | public int | getSize() | public Thread | getThread() Returns the thread in which the RunnableQueue is currently running. | public void | invokeAndWait(Runnable r, RunnableHandler runHandler) Waits until the given Runnable's run() has returned. | public void | invokeLater(Runnable r, RunnableHandler runHandler) Schedules the given Runnable object for a later invocation, and
returns. | public void | preemptAndWait(Runnable r, RunnableHandler runHandler) Waits until the given Runnable's run() has returned. | public void | preemptLater(Runnable r, RunnableHandler runHandler) Schedules the given Runnable object for a later invocation, and
returns. | public void | resumeExecution() Resumes the execution of this queue. | public void | run() Runs this queue. | public void | safeInvokeAndWait(Runnable r, RunnableHandler runHandler) Waits until the given Runnable's run() has returned.
Note: safeInvokeAndWait() may be called from any thread.
This method checks if this thread is the update thread, in which case
the Runnable is invoked directly. | public void | scheduleAtFixedRate(Runnable r, RunnableHandler runHandler, long interval) Schedules the input Runnable at the requested
fixed rate. | public void | suspendExecution(boolean waitTillSuspended) Suspends the execution of this queue after the current runnable
completes.
Parameters: waitTillSuspended - if true this method will not returnuntil the queue has suspended (no runnable in progressor about to be in progress). | public void | unschedule(Runnable r) Removes the input Runnable from the list of
Runnables scheduled at a fixed rate. |
RUNNING | final public static String RUNNING(Code) | | The queue is in the processes of running tasks.
|
SUSPENDED | final public static String SUSPENDED(Code) | | The queue is no longer running any tasks and will not
run any tasks until resumeExecution is called.
|
SUSPENDING | final public static String SUSPENDING(Code) | | The queue may still be running tasks but as soon as possible
will go to SUSPENDED state.
|
TERMINATED | final public static String TERMINATED(Code) | | This queue has been interrupted
|
defaultQueue | protected static RunnableQueue defaultQueue(Code) | | The default RunnableQueue instance.
|
list | protected DoublyLinkedList list(Code) | | The Runnable objects list, also used as synchoronization point
for pushing/poping runables.
|
queueHandler | protected RunnableQueueHandler queueHandler(Code) | | The object which handles RunnableQueue events.
|
runnableQueueThread | protected Thread runnableQueueThread(Code) | | The current thread.
|
scheduler | protected Scheduler scheduler(Code) | | The Scheduler which can run Runnables at a fixed
rate.
|
state | protected String state(Code) | | The Suspension state of this thread.
|
stateLock | protected Object stateLock(Code) | | Object to synchronize/wait/notify for suspension
issues.
|
createRunnableQueue | public static RunnableQueue createRunnableQueue(RunnableQueueHandler queueHandler)(Code) | | Creates a new RunnableQueue started in a new thread.
Parameters: queueHandler - the RunnableQueueHandler which will be notifiedof the RunnableQueue's activity. May be null. a RunnableQueue which is garanteed to have entered itsrun() method. |
empty | public void empty()(Code) | | Removes all pending Runnable s.
|
getDefault | public static RunnableQueue getDefault()(Code) | | Returns the default RunnableQueue instance. This is what
should be used in most circumstances. In particular, all document
instances which need to process in a seperate thread should share this
default RunnableQueue.
the default RunnableQueue instance. |
getNextPending | public Runnable getNextPending()(Code) | | the next pending runnable |
getQueueState | public String getQueueState()(Code) | | this queue's state, one of RUNNING, SUSPENDING,SUSPENDED or TERMINATED |
getSize | public int getSize()(Code) | | the number of pending runnables |
getThread | public Thread getThread()(Code) | | Returns the thread in which the RunnableQueue is currently running.
null if the RunnableQueue has not entered hisrun() method. |
invokeAndWait | public void invokeAndWait(Runnable r, RunnableHandler runHandler) throws InterruptedException(Code) | | Waits until the given Runnable's run() has returned.
Note: invokeAndWait() must not be called from the
current thread (for example from the run() method of the
argument).
Parameters: r - the Runnable to put at the end of the execution list. Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. throws: IllegalStateException - if getThread() is null or if thethread returned by getThread() is the current one. throws: InterruptedException - if the thread is interrupted while waiting for the input Runnable to completeits execution. |
invokeLater | public void invokeLater(Runnable r, RunnableHandler runHandler)(Code) | | Schedules the given Runnable object for a later invocation, and
returns.
An exception is thrown if the RunnableQueue was not started.
Parameters: r - the Runnable to put at the end of theexecution list. Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. throws: IllegalStateException - if getThread() is null. |
preemptAndWait | public void preemptAndWait(Runnable r, RunnableHandler runHandler) throws InterruptedException(Code) | | Waits until the given Runnable's run() has returned.
The given runnable preempts any runnable that is not currently
executing (ie the next runnable started will be the one given).
Note: preemptAndWait() must not be called from the
current thread (for example from the run() method of the
argument).
Parameters: r - the Runnable to execute Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. throws: IllegalStateException - if getThread() is null or if thethread returned by getThread() is the current one. throws: InterruptedException - if the thread is interrupted whilewaiting for the completion of the input Runnable to complete execution. |
preemptLater | public void preemptLater(Runnable r, RunnableHandler runHandler)(Code) | | Schedules the given Runnable object for a later invocation, and
returns. The given runnable preempts any runnable that is not
currently executing (ie the next runnable started will be the
one given). An exception is thrown if the RunnableQueue was
not started.
Parameters: r - the Runnable to put at the front of the execution list. Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. throws: IllegalStateException - if getThread() is null. |
resumeExecution | public void resumeExecution()(Code) | | Resumes the execution of this queue.
throws: IllegalStateException - if getThread() is null. |
run | public void run()(Code) | | Runs this queue. Implements the Runnable interface.
|
safeInvokeAndWait | public void safeInvokeAndWait(Runnable r, RunnableHandler runHandler)(Code) | | Waits until the given Runnable's run() has returned.
Note: safeInvokeAndWait() may be called from any thread.
This method checks if this thread is the update thread, in which case
the Runnable is invoked directly. Otherwise, it delegates to the
invokeAndWait method.
Parameters: r - the Runnable to put at the end of the execution list. Should not be null. Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. throws: IllegalStateException - if getThread() is null or if thethread returned by getThread() is the current one. |
scheduleAtFixedRate | public void scheduleAtFixedRate(Runnable r, RunnableHandler runHandler, long interval)(Code) | | Schedules the input Runnable at the requested
fixed rate. The RunnableQueue offers a 'best'
effort service meaning that it will schedule the Runnable
as soon as possible so that the time between the begining of
two consecutive runs of the Runnable is as close
as possible to the requested rate. Note that a too high rate
may cause the rest of the Runnable in the
RunnableQueue to be starved and never get
executed.
Parameters: r - the Runnable to schedule at a regularinterval. If null, there won't be any Runnable scheduled and if there was a current one, it won't be executedany more. Parameters: runHandler - the RunnableHandler to notify once the Runnable has finished executing.Should not be null. Parameters: interval - the minimum interval between to consecutive executions of the input Runnable . The value is in milliseconds. throws: IllegalArgumentException - If this parameter is zero or less, and r is not null. |
suspendExecution | public void suspendExecution(boolean waitTillSuspended)(Code) | | Suspends the execution of this queue after the current runnable
completes.
Parameters: waitTillSuspended - if true this method will not returnuntil the queue has suspended (no runnable in progressor about to be in progress). If resumeExecution iscalled while waiting will simply return (this reallyindicates a race condition in your code). This mayreturn before an associated RunHandler is notified. throws: IllegalStateException - if getThread() is null. |
unschedule | public void unschedule(Runnable r)(Code) | | Removes the input Runnable from the list of
Runnables scheduled at a fixed rate. If the Runnable is not
currently scheduled at a fixed rate, then this method does
nothing. If this Runnable was scheduled multiple times
with this RunnableQueue, then all instances are removed.
Parameters: r - the Runnable that should no longer be scheduled at a fixed rate. See Also: RunnableQueue.scheduleAtFixedRate |
|
|