Class ExecutionQueue
- java.lang.Object
-
- com.inductiveautomation.ignition.common.util.ExecutionQueue
-
public class ExecutionQueue extends java.lang.ObjectQueues up submittedRunnables and executes them in serial on anExecutorService.
-
-
Constructor Summary
Constructors Constructor Description ExecutionQueue(java.util.concurrent.Executor service)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisIdle()booleanisInQueue()voidpause()Pause execution of queuedRunnables.voidrequireInQueue()Call to check if the current code is being executed inside this queue.voidrequireInQueue(java.lang.String message)Call to check if the current code is being executed inside this queue.voidresume()Resume execution of queuedRunnables.<E extends java.lang.Throwable>
java.util.concurrent.CompletableFuture<java.lang.Void>runOrSubmit(FragileRunnable<E> fragileRunnable)Runs the givenFragileRunnableon the calling thread ifisInQueue()is true.<T,E extends java.lang.Throwable>
java.util.concurrent.CompletableFuture<T>runOrSubmit(FragileSupplier<T,E> fragileSupplier)Runs the givenFragileSupplieron the calling thread ifisInQueue()is true.voidsubmit(java.lang.Runnable runnable)Submit aRunnableto be executed.voidsubmit(java.lang.Runnable... runnables)Submit one or moreRunnables to be executed.voidsubmitOrRun(java.lang.Runnable runnable)voidsubmitToHead(java.lang.Runnable runnable)Submit aRunnableto be executed at the head of the queue.
-
-
-
Method Detail
-
submit
public void submit(java.lang.Runnable runnable)
Submit aRunnableto be executed.- Parameters:
runnable- theRunnableto be executed.
-
submit
public void submit(java.lang.Runnable... runnables)
Submit one or moreRunnables to be executed.- Parameters:
runnables- theRunnables to be executed.
-
submitToHead
public void submitToHead(java.lang.Runnable runnable)
Submit aRunnableto be executed at the head of the queue.- Parameters:
runnable- theRunnableto be executed.
-
submitOrRun
public void submitOrRun(@Nonnull java.lang.Runnable runnable)- Parameters:
runnable- theRunnableto run on-queue.
-
runOrSubmit
@Nonnull public <E extends java.lang.Throwable> java.util.concurrent.CompletableFuture<java.lang.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- theFragileRunnableto 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:
java.lang.NullPointerException- if the givenFragileRunnableis null
-
runOrSubmit
@Nonnull public <T,E extends java.lang.Throwable> java.util.concurrent.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- theFragileSupplierto 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:
java.lang.NullPointerException- if the givenFragileSupplieris null
-
pause
public void pause()
Pause execution of queuedRunnables.
-
resume
public void resume()
Resume execution of queuedRunnables.
-
isInQueue
public boolean isInQueue()
- Returns:
trueif this thread is executing inside this queue.
-
requireInQueue
public void requireInQueue()
Call to check if the current code is being executed inside this queue.- Throws:
java.lang.IllegalStateException- if flow reaches here without going through this queue
-
requireInQueue
public void requireInQueue(java.lang.String message)
Call 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:
java.lang.IllegalStateException- if flow reaches here without going through this queue
-
isIdle
public boolean isIdle()
-
-