Class ExecutionQueue

java.lang.Object
com.inductiveautomation.ignition.common.util.ExecutionQueue

public class ExecutionQueue extends Object
Queues up submitted Runnables and executes them in serial on an ExecutorService.
  • Constructor Details

  • Method Details

    • submit

      public void submit(Runnable runnable)
      Submit a Runnable to be executed.
      Parameters:
      runnable - the Runnable to be executed.
    • submit

      public void submit(Runnable... runnables)
      Submit one or more Runnables to be executed.
      Parameters:
      runnables - the Runnables to be executed.
    • submitToHead

      public void submitToHead(Runnable runnable)
      Submit a Runnable to be executed at the head of the queue.
      Parameters:
      runnable - the Runnable to be executed.
    • submitOrRun

      public void submitOrRun(@Nonnull Runnable runnable)
      Run runnable if isInQueue(), otherwise submit(Runnable) it for later execution on the queue.
      Parameters:
      runnable - the Runnable to run on-queue.
    • runOrSubmit

      @Nonnull public <E extends Throwable> CompletableFuture<Void> runOrSubmit(FragileRunnable<E> fragileRunnable)
      Runs the given FragileRunnable on the calling thread if isInQueue() is true. Queues the given FragileRunnable to be run on-queue if isInQueue() is false. Useful for cases where the caller wishes to block until the given FragileRunnable completes execution but the caller may or may not already be running on-queue. If the FragileRunnable throws a Throwable during execution, it will be caught and used to complete the returned CompletableFuture exceptionally.
      Parameters:
      fragileRunnable - the FragileRunnable to run on-queue. must not be null.
      Returns:
      a CompletableFuture which will be completed after the given FragileRunnable is ran. it will already be completed when called on a thread where isInQueue() is true, else it will be completed once the queue runs the given FragileRunnable.
      Throws:
      NullPointerException - if the given FragileRunnable is null
    • runOrSubmit

      @Nonnull public <T, E extends Throwable> CompletableFuture<T> runOrSubmit(FragileSupplier<T,E> fragileSupplier)
      Runs the given FragileSupplier on the calling thread if isInQueue() is true. Queues the given FragileSupplier to be run on-queue if isInQueue() is false. Useful for cases where the caller wishes to block until the given FragileSupplier completes execution but the caller may or may not already be running on-queue. If the FragileSupplier throws a Throwable during execution, it will be caught and used to complete the returned CompletableFuture exceptionally.
      Parameters:
      fragileSupplier - the FragileSupplier to run on-queue. must not be null.
      Returns:
      a CompletableFuture which will be completed after the given FragileSupplier is ran with the value returned by calling FragileSupplier.get(). it will already be completed when called on a thread where isInQueue() is true, else it will be completed once the queue runs the given FragileSupplier.
      Throws:
      NullPointerException - if the given FragileSupplier is null
    • pause

      public void pause()
      Pause execution of queued Runnables.
    • resume

      public void resume()
      Resume execution of queued Runnables.
    • getSize

      public int getSize()
    • isInQueue

      public boolean isInQueue()
      Returns:
      true if 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:
      IllegalStateException - if flow reaches here without going through this queue
    • requireInQueue

      public void requireInQueue(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:
      IllegalStateException - if flow reaches here without going through this queue
    • isIdle

      public boolean isIdle()
    • truncate

      public boolean truncate()
      Call to forcibly remove queued Runnables
      Returns:
      true if elements were cleared, false if no action taken