Class ExecutionQueue
java.lang.Object
com.inductiveautomation.ignition.common.util.ExecutionQueue
Queues up submitted 
Runnables and executes them in serial on an
 ExecutorService.- 
Constructor SummaryConstructorsConstructorDescriptionExecutionQueue(Executor service) ExecutionQueue(Executor service, Function<Runnable, Runnable> taskWrapper) 
- 
Method SummaryModifier and TypeMethodDescriptionintgetSize()booleanisIdle()booleanvoidpause()Pause execution of queuedRunnables.voidCall to check if the current code is being executed inside this queue.voidrequireInQueue(String message) Call to check if the current code is being executed inside this queue.voidresume()Resume execution of queuedRunnables.<E extends Throwable>
 CompletableFuture<Void>runOrSubmit(FragileRunnable<E> fragileRunnable) Runs the givenFragileRunnableon the calling thread ifisInQueue()is true.<T,E extends Throwable> 
 CompletableFuture<T>runOrSubmit(FragileSupplier<T, E> fragileSupplier) Runs the givenFragileSupplieron the calling thread ifisInQueue()is true.voidSubmit aRunnableto be executed.voidSubmit one or moreRunnables to be executed.voidsubmitOrRun(Runnable runnable) voidsubmitToHead(Runnable runnable) Submit aRunnableto be executed at the head of the queue.booleantruncate()Call to forcibly remove queued Runnables
- 
Constructor Details- 
ExecutionQueue
- 
ExecutionQueue
 
- 
- 
Method Details- 
submitSubmit aRunnableto be executed.- Parameters:
- runnable- the- Runnableto be executed.
 
- 
submitSubmit one or moreRunnables to be executed.- Parameters:
- runnables- the- Runnables to be executed.
 
- 
submitToHeadSubmit aRunnableto be executed at the head of the queue.- Parameters:
- runnable- the- Runnableto be executed.
 
- 
submitOrRun- Parameters:
- runnable- the- Runnableto run on-queue.
 
- 
runOrSubmit@Nonnull public <E extends Throwable> CompletableFuture<Void> runOrSubmit(FragileRunnable<E> fragileRunnable) Runs the givenFragileRunnableon the calling thread ifisInQueue()is true. Queues the givenFragileRunnableto be run on-queue ifisInQueue()is false. Useful for cases where the caller wishes to block until the givenFragileRunnablecompletes execution but the caller may or may not already be running on-queue. If theFragileRunnablethrows aThrowableduring execution, it will be caught and used to complete the returnedCompletableFutureexceptionally.- Parameters:
- fragileRunnable- the- FragileRunnableto run on-queue. must not be null.
- Returns:
- a CompletableFuturewhich will be completed after the givenFragileRunnableis ran. it will already be completed when called on a thread whereisInQueue()is true, else it will be completed once the queue runs the givenFragileRunnable.
- Throws:
- NullPointerException- if the given- FragileRunnableis null
 
- 
runOrSubmit@Nonnull public <T,E extends Throwable> CompletableFuture<T> runOrSubmit(FragileSupplier<T, E> fragileSupplier) Runs the givenFragileSupplieron the calling thread ifisInQueue()is true. Queues the givenFragileSupplierto be run on-queue ifisInQueue()is false. Useful for cases where the caller wishes to block until the givenFragileSuppliercompletes execution but the caller may or may not already be running on-queue. If theFragileSupplierthrows aThrowableduring execution, it will be caught and used to complete the returnedCompletableFutureexceptionally.- Parameters:
- fragileSupplier- the- FragileSupplierto run on-queue. must not be null.
- Returns:
- a CompletableFuturewhich will be completed after the givenFragileSupplieris ran with the value returned by callingFragileSupplier.get(). it will already be completed when called on a thread whereisInQueue()is true, else it will be completed once the queue runs the givenFragileSupplier.
- Throws:
- NullPointerException- if the given- FragileSupplieris null
 
- 
pausepublic void pause()Pause execution of queuedRunnables.
- 
resumepublic void resume()Resume execution of queuedRunnables.
- 
getSizepublic int getSize()
- 
isInQueuepublic boolean isInQueue()- Returns:
- trueif this thread is executing inside this queue.
 
- 
requireInQueuepublic void requireInQueue()Call to check if the current code is being executed inside this queue.- Throws:
- IllegalStateException- if flow reaches here without going through this queue
 
- 
requireInQueueCall to check if the current code is being executed inside this queue.- Parameters:
- message- The message to use in the thrown exception if the check fails
- Throws:
- IllegalStateException- if flow reaches here without going through this queue
 
- 
isIdlepublic boolean isIdle()
- 
truncatepublic boolean truncate()Call to forcibly remove queued Runnables- Returns:
- true if elements were cleared, false if no action taken
 
 
-