public class RunnableQueue
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Class and Description |
---|---|
static interface |
RunnableQueue.IdleRunnable
A
Runnable that can also inform the caller how long it should
be until it is run again. |
protected static class |
RunnableQueue.Link
To store a Runnable.
|
protected static class |
RunnableQueue.LockableLink
To store a Runnable with an object waiting for him to be executed.
|
static interface |
RunnableQueue.RunHandler
This interface must be implemented by an object which wants to
be notified of run events.
|
static class |
RunnableQueue.RunHandlerAdapter
This is an adapter class that implements the RunHandler interface.
|
static class |
RunnableQueue.RunnableQueueState
Type-safe enumeration of queue states.
|
Modifier and Type | Field and Description |
---|---|
protected int |
preemptCount
Count of preempt entries in queue, so preempt entries
can be kept properly ordered.
|
protected RunnableQueue.RunHandler |
runHandler
The object which handle run events.
|
protected HaltingThread |
runnableQueueThread
The current thread.
|
static RunnableQueue.RunnableQueueState |
RUNNING
The queue is in the process of running tasks.
|
protected RunnableQueue.RunnableQueueState |
state
The Suspension state of this thread.
|
protected java.lang.Object |
stateLock
Object to synchronize/wait/notify for suspension
issues.
|
static RunnableQueue.RunnableQueueState |
SUSPENDED
The queue is no longer running any tasks and will not
run any tasks until resumeExecution is called.
|
static RunnableQueue.RunnableQueueState |
SUSPENDING
The queue may still be running tasks but as soon as possible
will go to SUSPENDED state.
|
protected boolean |
wasResumed
Used to indicate if the queue was resumed while
still running, so a 'resumed' event can be sent.
|
Constructor and Description |
---|
RunnableQueue() |
Modifier and Type | Method and Description |
---|---|
static RunnableQueue |
createRunnableQueue()
Creates a new RunnableQueue started in a new thread.
|
protected void |
executionResumed()
Called when execution is being resumed.
|
protected void |
executionSuspended()
Called when execution is being suspended.
|
java.lang.Object |
getIteratorLock()
Returns iterator lock to use to work with the iterator
returned by iterator().
|
RunnableQueue.RunnableQueueState |
getQueueState() |
RunnableQueue.RunHandler |
getRunHandler()
Returns the RunHandler or null.
|
HaltingThread |
getThread()
Returns the thread in which the RunnableQueue is currently running.
|
void |
invokeAndWait(java.lang.Runnable r)
Waits until the given Runnable's
run() has returned. |
void |
invokeLater(java.lang.Runnable r)
Schedules the given Runnable object for a later invocation, and
returns.
|
java.util.Iterator |
iterator()
Returns an iterator over the runnables.
|
void |
preemptAndWait(java.lang.Runnable r)
Waits until the given Runnable's
run() has returned. |
void |
preemptLater(java.lang.Runnable r)
Schedules the given Runnable object for a later invocation, and
returns.
|
void |
resumeExecution()
Resumes the execution of this queue.
|
void |
run()
Runs this queue.
|
protected void |
runnableInvoked(java.lang.Runnable rable)
Called when a Runnable completes.
|
protected void |
runnableStart(java.lang.Runnable rable)
Called just prior to executing a Runnable.
|
void |
setIdleRunnable(RunnableQueue.IdleRunnable r)
Sets a Runnable to be run whenever the queue is empty.
|
void |
setRunHandler(RunnableQueue.RunHandler rh)
Sets the RunHandler for this queue.
|
void |
suspendExecution(boolean waitTillSuspended)
Suspends the execution of this queue after the current runnable
completes.
|
public static final RunnableQueue.RunnableQueueState RUNNING
public static final RunnableQueue.RunnableQueueState SUSPENDING
public static final RunnableQueue.RunnableQueueState SUSPENDED
protected volatile RunnableQueue.RunnableQueueState state
protected final java.lang.Object stateLock
protected boolean wasResumed
protected int preemptCount
protected RunnableQueue.RunHandler runHandler
protected volatile HaltingThread runnableQueueThread
public static RunnableQueue createRunnableQueue()
run()
method.public void run()
run
in interface java.lang.Runnable
public HaltingThread getThread()
run()
method.public void invokeLater(java.lang.Runnable r)
java.lang.IllegalStateException
- if getThread() is null.public void invokeAndWait(java.lang.Runnable r) throws java.lang.InterruptedException
run()
has returned.
Note: invokeAndWait()
must not be called from the
current thread (for example from the run()
method of the
argument).java.lang.IllegalStateException
- if getThread() is null or if the
thread returned by getThread() is the current one.java.lang.InterruptedException
public void preemptLater(java.lang.Runnable r)
java.lang.IllegalStateException
- if getThread() is null.public void preemptAndWait(java.lang.Runnable r) throws java.lang.InterruptedException
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).java.lang.IllegalStateException
- if getThread() is null or if the
thread returned by getThread() is the current one.java.lang.InterruptedException
public RunnableQueue.RunnableQueueState getQueueState()
public void suspendExecution(boolean waitTillSuspended)
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.java.lang.IllegalStateException
- if getThread() is null.public void resumeExecution()
java.lang.IllegalStateException
- if getThread() is null.public java.lang.Object getIteratorLock()
public java.util.Iterator iterator()
public void setRunHandler(RunnableQueue.RunHandler rh)
public RunnableQueue.RunHandler getRunHandler()
public void setIdleRunnable(RunnableQueue.IdleRunnable r)
protected void executionSuspended()
protected void executionResumed()
protected void runnableStart(java.lang.Runnable rable)
rable
- The runnable that is about to startprotected void runnableInvoked(java.lang.Runnable rable)
rable
- The runnable that just completed.Copyright © 2022 Apache Software Foundation. All Rights Reserved.