Class TaskQueue
java.lang.Object
org.eclipse.milo.opcua.stack.core.util.TaskQueue
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic interfacestatic enum -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionbooleanexecute(TaskQueue.Task task) Queue aTaskQueue.Taskto be executed.intGet the current number of tasks that are pending execution.intGet the current number of tasks waiting in the queue.booleanstatic TaskQueue.Buildervoidpause()Pause execution of queuedTaskQueue.Tasks.voidresume()Resume execution of queuedTaskQueue.Tasks.shutdown(boolean awaitQuiescence) Shut down this executor, optionally awaiting completion of any currently-executing tasks.@Nullable CompletionStage<Unit>submit(TaskQueue.Task task) Queue aTaskQueue.Taskto be executed, returning aCompletionStagethat will complete when the task has been executed.
-
Constructor Details
-
TaskQueue
Create aTaskQueuethat executesTaskQueue.Tasks on the providedExecutor.All other parameters are default values.
- Parameters:
executor- theExecutorthatTaskQueue.Tasks will use to execute.- See Also:
-
DEFAULT_MAX_CONCURRENT_TASKSDEFAULT_MAX_QUEUE_SIZEDEFAULT_PRIORITY_RATIO
-
TaskQueue
- Parameters:
executor- theExecutorthatTaskQueue.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 andexecute(Task)starts returning false.priorityRatio- ratio ofTaskQueue.TaskPriority.ELEVATEDtasks toTaskQueue.TaskPriority.REGULARtasks that will be executed when elevated tasks are continually being dequeued.
-
-
Method Details
-
execute
Queue aTaskQueue.Taskto be executed.- Parameters:
task- theTaskQueue.Taskto be executed.- Returns:
trueiftaskwas queued for execution, orfalseif it was not queued, either because thisTaskQueueis shut down, or because backpressure is being applied because the configured max queue size would be exceeded.
-
submit
Queue aTaskQueue.Taskto be executed, returning aCompletionStagethat will complete when the task has been executed.The callback completes asynchronously, using the
TaskQueue's configuredExecutor, and does not block execution of any further queued tasks.- Parameters:
task- theTaskQueue.Taskto be executed.- Returns:
- a
CompletionStagethat will complete whentaskhas been executed, or null if the task was not queued, either because thisTaskQueueis shut down, or because backpressure is being applied because the configured max queue size would be exceeded.
-
pause
public void pause()Pause execution of queuedTaskQueue.Tasks. -
resume
public void resume()Resume execution of queuedTaskQueue.Tasks. -
shutdown
Shut down this executor, optionally awaiting completion of any currently-executing tasks.- Parameters:
awaitQuiescence-trueif 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
- Returns:
- a new
TaskQueue.Builderinstance.
-