Package org.apache.batik.util
Class RunnableQueue
java.lang.Object
org.apache.batik.util.RunnableQueue
- All Implemented Interfaces:
Runnable
This class represents an object which queues Runnable objects for
invocation in a single thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
ARunnable
that can also inform the caller how long it should be until it is run again.protected static class
To store a Runnable.protected static class
To store a Runnable with an object waiting for him to be executed.static interface
This interface must be implemented by an object which wants to be notified of run events.static class
This is an adapter class that implements the RunHandler interface.static final class
Type-safe enumeration of queue states. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Count of preempt entries in queue, so preempt entries can be kept properly ordered.protected RunnableQueue.RunHandler
The object which handle run events.protected HaltingThread
The current thread.static final RunnableQueue.RunnableQueueState
The queue is in the process of running tasks.protected RunnableQueue.RunnableQueueState
The Suspension state of this thread.protected final Object
Object to synchronize/wait/notify for suspension issues.static final RunnableQueue.RunnableQueueState
The queue is no longer running any tasks and will not run any tasks until resumeExecution is called.static final RunnableQueue.RunnableQueueState
The queue may still be running tasks but as soon as possible will go to SUSPENDED state.protected boolean
Used to indicate if the queue was resumed while still running, so a 'resumed' event can be sent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RunnableQueue
Creates a new RunnableQueue started in a new thread.protected void
Called when execution is being resumed.protected void
Called when execution is being suspended.Returns iterator lock to use to work with the iterator returned by iterator().Returns the RunHandler or null.Returns the thread in which the RunnableQueue is currently running.void
Waits until the given Runnable'srun()
has returned.void
Schedules the given Runnable object for a later invocation, and returns.iterator()
Returns an iterator over the runnables.void
Waits until the given Runnable'srun()
has returned.void
Schedules the given Runnable object for a later invocation, and returns.void
Resumes the execution of this queue.void
run()
Runs this queue.protected void
runnableInvoked
(Runnable rable) Called when a Runnable completes.protected void
runnableStart
(Runnable rable) Called just prior to executing a Runnable.void
Sets a Runnable to be run whenever the queue is empty.void
Sets the RunHandler for this queue.void
suspendExecution
(boolean waitTillSuspended) Suspends the execution of this queue after the current runnable completes.
-
Field Details
-
RUNNING
The queue is in the process of running tasks. -
SUSPENDING
The queue may still be running tasks but as soon as possible will go to SUSPENDED state. -
SUSPENDED
The queue is no longer running any tasks and will not run any tasks until resumeExecution is called. -
state
The Suspension state of this thread. -
stateLock
Object to synchronize/wait/notify for suspension issues. -
wasResumed
protected boolean wasResumedUsed to indicate if the queue was resumed while still running, so a 'resumed' event can be sent. -
preemptCount
protected int preemptCountCount of preempt entries in queue, so preempt entries can be kept properly ordered. -
runHandler
The object which handle run events. -
runnableQueueThread
The current thread.
-
-
Constructor Details
-
RunnableQueue
public RunnableQueue()
-
-
Method Details
-
createRunnableQueue
Creates a new RunnableQueue started in a new thread.- Returns:
- a RunnableQueue which is guaranteed to have entered its
run()
method.
-
run
public void run()Runs this queue. -
getThread
Returns the thread in which the RunnableQueue is currently running.- Returns:
- null if the RunnableQueue has not entered his
run()
method.
-
invokeLater
Schedules the given Runnable object for a later invocation, and returns. An exception is thrown if the RunnableQueue was not started.- Throws:
IllegalStateException
- if getThread() is null.
-
invokeAndWait
Waits until the given Runnable'srun()
has returned. Note:invokeAndWait()
must not be called from the current thread (for example from therun()
method of the argument).- Throws:
IllegalStateException
- if getThread() is null or if the thread returned by getThread() is the current one.InterruptedException
-
preemptLater
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.- Throws:
IllegalStateException
- if getThread() is null.
-
preemptAndWait
Waits until the given Runnable'srun()
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 therun()
method of the argument).- Throws:
IllegalStateException
- if getThread() is null or if the thread returned by getThread() is the current one.InterruptedException
-
getQueueState
-
suspendExecution
public void suspendExecution(boolean waitTillSuspended) Suspends the execution of this queue after the current runnable completes.- Parameters:
waitTillSuspended
- if true this method will not return until the queue has suspended (no runnable in progress or about to be in progress). If resumeExecution is called while waiting will simply return (this really indicates a race condition in your code). This may return before an associated RunHandler is notified.- Throws:
IllegalStateException
- if getThread() is null.
-
resumeExecution
public void resumeExecution()Resumes the execution of this queue.- Throws:
IllegalStateException
- if getThread() is null.
-
getIteratorLock
Returns iterator lock to use to work with the iterator returned by iterator(). -
iterator
Returns an iterator over the runnables. -
setRunHandler
Sets the RunHandler for this queue. -
getRunHandler
Returns the RunHandler or null. -
setIdleRunnable
Sets a Runnable to be run whenever the queue is empty. -
executionSuspended
protected void executionSuspended()Called when execution is being suspended. Currently just notifies runHandler -
executionResumed
protected void executionResumed()Called when execution is being resumed. Currently just notifies runHandler -
runnableStart
Called just prior to executing a Runnable. Currently just notifies runHandler- Parameters:
rable
- The runnable that is about to start
-
runnableInvoked
Called when a Runnable completes. Currently just notifies runHandler- Parameters:
rable
- The runnable that just completed.
-