public abstract class DispatchQueue
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DispatchQueue.DispatchQueueState
possible states of the dispatch queue
|
Modifier and Type | Field and Description |
---|---|
protected DispatchQueue.DispatchQueueState |
_queueState
state of this queue
|
protected java.util.concurrent.ExecutorService |
DISPATCH_EXECUTOR
executor for processing dispatched operations
|
static int |
DISPATCH_QUEUE_PRIORITY_BACKGROUND
priority for the background priority queue
|
static int |
DISPATCH_QUEUE_PRIORITY_DEFAULT
priority for the default priority queue
|
static int |
DISPATCH_QUEUE_PRIORITY_HIGH
priority for a high priority queue
|
static int |
DISPATCH_QUEUE_PRIORITY_LOW
priority for the low priority queue
|
protected java.util.concurrent.ThreadFactory |
DISPATCH_THREAD_FACTORY
thread factory for dispatch this queue
|
protected java.util.concurrent.LinkedBlockingQueue<xal.tools.dispatch.DispatchOperation<?>> |
PENDING_OPERATION_QUEUE
queue of pending operations which have not yet been submitted for execution
|
protected java.util.concurrent.ExecutorService |
QUEUE_PROCESSOR
executor which processes the queue
|
protected java.util.concurrent.atomic.AtomicInteger |
RUNNING_OPERATION_COUNTER
number of operations currently running
|
Modifier | Constructor and Description |
---|---|
protected |
DispatchQueue(java.lang.String label)
Constructor
|
protected |
DispatchQueue(java.lang.String label,
int priority)
Primary Constructor
|
Modifier and Type | Method and Description |
---|---|
static DispatchQueue |
createConcurrentQueue(java.lang.String label)
Create a concurrent queue
|
protected abstract java.util.concurrent.ExecutorService |
createDispatchExecutor()
create the executor for dispatching operations
|
static DispatchQueue |
createSerialQueue(java.lang.String label)
Create a serial queue
|
protected int |
decrementRunningOperationCount()
decrement the running operations count
|
void |
dispatchAfter(java.util.Date dispatchTime,
java.lang.Runnable rawOperation)
dispatch the operation after the specified time without blocking
|
void |
dispatchApply(int iterations,
DispatchIterationKernel iterationKernel)
Performs all the specified iterations of the kernel asynchronously and waits for them to complete.
|
void |
dispatchAsync(DispatchGroup group,
java.lang.Runnable rawOperation)
submit the operation for execution on the queue and add it to the specified group without waiting for completion
|
protected void |
dispatchAsync(DispatchGroup group,
java.lang.Runnable rawOperation,
boolean isBarrier)
submit the operation for execution on the queue and add it to the specified group without waiting for completion
|
void |
dispatchAsync(java.lang.Runnable rawOperation)
submit the operation for execution on the queue without waiting for completion
|
void |
dispatchBarrierAsync(java.lang.Runnable operation)
Submit a barrier block for execution on the queue without waiting for completion.
|
void |
dispatchBarrierSync(java.lang.Runnable operation)
Submit a barrier block for execution on the queue and wait for completion.
|
<ReturnType> |
dispatchSync(java.util.concurrent.Callable<ReturnType> rawOperation)
submit the operation for execution on the queue and wait for it to complete
|
void |
dispatchSync(java.lang.Runnable rawOperation)
submit the operation for execution on the queue and wait for it to complete
|
protected void |
dispatchSync(java.lang.Runnable rawOperation,
boolean isBarrier)
submit the operation for execution on the queue and wait for it to complete
|
void |
dispose()
dispose of this queue - can only be called on a custom queue
|
protected <ReturnType> |
enqueueOperation(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
Enqueue the operation and process make sure the operation queue gets processed
|
protected void |
finalize()
dispose of the executors
|
static DispatchQueue |
getCurrentQueue()
get the current queue or null if the current thread does not belong to a queue
|
static DispatchQueue |
getGlobalBackgroundPriorityQueue()
Get the global background priority queue
|
static DispatchQueue |
getGlobalDefaultPriorityQueue()
Get the global default priority queue
|
static DispatchQueue |
getGlobalHighPriorityQueue()
Get the global high priority queue
|
static DispatchQueue |
getGlobalLowPriorityQueue()
Get the global low priority queue
|
static DispatchQueue |
getGlobalQueue(int priority)
Get the global queue corresponding to the specified priority.
|
java.lang.String |
getLabel()
get this queue's label
|
static DispatchQueue |
getMainQueue()
Get the main queue on which Swing events are dispatched.
|
protected int |
incrementRunningOperationCount()
increment the running operations count
|
boolean |
isCurrentQueue()
Determine whether this queue is the current queue
|
boolean |
isDisposed()
determine whether this queue has been disposed
|
boolean |
isSuspended()
Determines whether this queue is suspended (disposed implies suspended)
|
protected <ReturnType> |
makeDispatchOperation(java.util.concurrent.Callable<ReturnType> rawOperation)
Make a callable operation wrapper from a raw runnable operation
|
protected <ReturnType> |
makeDispatchOperation(java.util.concurrent.Callable<ReturnType> rawOperation,
boolean isBarrier)
Make a callable operation wrapper from a raw runnable operation
|
protected xal.tools.dispatch.DispatchOperation<java.lang.Void> |
makeDispatchOperation(java.lang.Runnable rawOperation)
Make a callable operation wrapper from a raw runnable operation
|
protected xal.tools.dispatch.DispatchOperation<java.lang.Void> |
makeDispatchOperation(java.lang.Runnable rawOperation,
boolean isBarrier)
Make a callable operation wrapper from a raw runnable operation
|
<ReturnType> |
operationCompleted(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
Event indicating that an operation in this group has completed
|
protected <ReturnType> |
postProcessOperation(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
call this method when an operation has completed execution
|
protected abstract void |
processOperationQueue()
Process the operation queue by processing the next pending operation using the serial queue processor to guarantee the operations are queue serially
|
protected void |
releaseResources()
release allocated resources - called internally for any queue
|
void |
resume()
resume execution of pending operations if suspended or throw an exception if attempting to resume a disposed queue
|
void |
suspend()
suspend execution of pending operations if processing (nothing if disposed or already suspended)
|
public static final int DISPATCH_QUEUE_PRIORITY_HIGH
public static final int DISPATCH_QUEUE_PRIORITY_DEFAULT
public static final int DISPATCH_QUEUE_PRIORITY_LOW
public static final int DISPATCH_QUEUE_PRIORITY_BACKGROUND
protected final java.util.concurrent.ExecutorService QUEUE_PROCESSOR
protected final java.util.concurrent.ThreadFactory DISPATCH_THREAD_FACTORY
protected final java.util.concurrent.ExecutorService DISPATCH_EXECUTOR
protected final java.util.concurrent.atomic.AtomicInteger RUNNING_OPERATION_COUNTER
protected volatile DispatchQueue.DispatchQueueState _queueState
protected final java.util.concurrent.LinkedBlockingQueue<xal.tools.dispatch.DispatchOperation<?>> PENDING_OPERATION_QUEUE
protected DispatchQueue(java.lang.String label, int priority)
protected DispatchQueue(java.lang.String label)
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public java.lang.String getLabel()
public boolean isSuspended()
public void suspend()
public void resume()
public void dispose()
public boolean isDisposed()
protected void releaseResources()
protected abstract java.util.concurrent.ExecutorService createDispatchExecutor()
public static DispatchQueue createConcurrentQueue(java.lang.String label)
label
- optional label for the queue to createpublic static DispatchQueue createSerialQueue(java.lang.String label)
label
- optional label for the queue to createpublic static DispatchQueue getMainQueue()
public static DispatchQueue getGlobalQueue(int priority)
priority
- one of DISPATCH_QUEUE_PRIORITY_HIGH, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_BACKGROUNDpublic static DispatchQueue getGlobalDefaultPriorityQueue()
public static DispatchQueue getGlobalHighPriorityQueue()
public static DispatchQueue getGlobalLowPriorityQueue()
public static DispatchQueue getGlobalBackgroundPriorityQueue()
public static DispatchQueue getCurrentQueue()
public boolean isCurrentQueue()
public <ReturnType> ReturnType dispatchSync(java.util.concurrent.Callable<ReturnType> rawOperation)
public void dispatchSync(java.lang.Runnable rawOperation)
protected void dispatchSync(java.lang.Runnable rawOperation, boolean isBarrier)
public void dispatchAsync(java.lang.Runnable rawOperation)
public void dispatchAsync(DispatchGroup group, java.lang.Runnable rawOperation)
protected void dispatchAsync(DispatchGroup group, java.lang.Runnable rawOperation, boolean isBarrier)
public void dispatchAfter(java.util.Date dispatchTime, java.lang.Runnable rawOperation)
public void dispatchBarrierAsync(java.lang.Runnable operation)
operation
- the operation to executepublic void dispatchBarrierSync(java.lang.Runnable operation)
operation
- the operation to executepublic void dispatchApply(int iterations, DispatchIterationKernel iterationKernel)
protected <ReturnType> void enqueueOperation(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
protected abstract void processOperationQueue()
protected <ReturnType> void postProcessOperation(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
protected <ReturnType> xal.tools.dispatch.DispatchOperation<ReturnType> makeDispatchOperation(java.util.concurrent.Callable<ReturnType> rawOperation)
protected xal.tools.dispatch.DispatchOperation<java.lang.Void> makeDispatchOperation(java.lang.Runnable rawOperation)
protected xal.tools.dispatch.DispatchOperation<java.lang.Void> makeDispatchOperation(java.lang.Runnable rawOperation, boolean isBarrier)
protected <ReturnType> xal.tools.dispatch.DispatchOperation<ReturnType> makeDispatchOperation(java.util.concurrent.Callable<ReturnType> rawOperation, boolean isBarrier)
public <ReturnType> void operationCompleted(xal.tools.dispatch.DispatchOperation<ReturnType> operation)
protected int incrementRunningOperationCount()
protected int decrementRunningOperationCount()