java.lang.Object
org.eclipse.milo.opcua.stack.core.util.TaskQueue

public final class TaskQueue extends Object
  • Constructor Details

    • TaskQueue

      public TaskQueue(Executor executor)
      Create a TaskQueue that executes TaskQueue.Tasks on the provided Executor.

      All other parameters are default values.

      Parameters:
      executor - the Executor that TaskQueue.Tasks will use to execute.
      See Also:
      • DEFAULT_MAX_CONCURRENT_TASKS
      • DEFAULT_MAX_QUEUE_SIZE
      • DEFAULT_PRIORITY_RATIO
    • TaskQueue

      public TaskQueue(Executor executor, int maxConcurrentTasks, int maxQueueSize, int priorityRatio)
      Create a TaskQueue that executes TaskQueue.Tasks on the provided Executor.
      Parameters:
      executor - the Executor that TaskQueue.Tasks will use to execute.
      maxConcurrentTasks - the number of concurrently executing tasks allowed. When 1, the default value, submitted Tasks are guaranteed to execute serially.
      maxQueueSize - the maximum number of Tasks that can be queued before backpressure is applied and execute(Task) starts returning false.
      priorityRatio - ratio of TaskQueue.TaskPriority.ELEVATED tasks to TaskQueue.TaskPriority.REGULAR tasks that will be executed when elevated tasks are continually being dequeued.
  • Method Details

    • execute

      public boolean execute(TaskQueue.Task task)
      Queue a TaskQueue.Task to be executed.
      Parameters:
      task - the TaskQueue.Task to be executed.
      Returns:
      true if task was queued for execution, or false if it was not queued, either because this TaskQueue is shut down, or because backpressure is being applied because the configured max queue size would be exceeded.
    • submit

      public @Nullable CompletionStage<Unit> submit(TaskQueue.Task task)
      Queue a TaskQueue.Task to be executed, returning a CompletionStage that will complete when the task has been executed.

      The callback completes asynchronously, using the TaskQueue's configured Executor, and does not block execution of any further queued tasks.

      Parameters:
      task - the TaskQueue.Task to be executed.
      Returns:
      a CompletionStage that will complete when task has been executed, or null if the task was not queued, either because this TaskQueue is shut down, or because backpressure is being applied because the configured max queue size would be exceeded.
    • pause

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

      public void resume()
      Resume execution of queued TaskQueue.Tasks.
    • shutdown

      public List<TaskQueue.Task> shutdown(boolean awaitQuiescence) throws InterruptedException
      Shut down this executor, optionally awaiting completion of any currently-executing tasks.
      Parameters:
      awaitQuiescence - true if this method should block awaiting completion of any currently-executing tasks.
      Returns:
      a List of TaskQueue.Tasks that were queued and will not be executed.
      Throws:
      InterruptedException - if the current Thread is interrupted while waiting.
    • isShutdown

      public boolean isShutdown()
    • getQueueSize

      public int getQueueSize()
      Get the current number of tasks waiting in the queue.

      This count does not include tasks that are currently executing.

      Returns:
      the current number of tasks waiting in the queue.
    • getPending

      public int getPending()
      Get the current number of tasks that are pending execution.

      Pending tasks have been dequeued and submitted to the executor but have not yet completed.

      Returns:
      the current number of tasks pending execution.
    • newBuilder

      public static TaskQueue.Builder newBuilder()
      Returns:
      a new TaskQueue.Builder instance.