Class BlockingTaskQueue
- java.lang.Object
-
- com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue
-
public class BlockingTaskQueue extends java.lang.Object
Helps to manage threading for a series of tasks. These tasks are blocking tasks that may produce a value (T) and ideally can gracefully handle being cancelled.This class will guarantee:
- Only one task executes at a time.
- All tasks execute on the executor given.
- Tasks will have their
BlockingCancelableTask.cancel()
called if they exceed the configured timeout, and their completion stage will be completed exceptionally with aTaskTimedOutException
- Tasks submitted while other tasks are executing are put into a queue. If the queue fills up, the oldest
tasks are rejected first. Rejected tasks will have their completion stages completed exceptionally with a
QueueOverflowException
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BlockingTaskQueue.Builder
static class
BlockingTaskQueue.ShutdownBehavior
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BlockingTaskQueue.Builder
newBuilder()
Create a new blocking task queue builder with a default of 30 second timeout and max queue length of 5void
shutdown()
Shuts down the queue.<T> java.util.concurrent.CompletionStage<T>
submit(BlockingCancelableTask<T> work)
Submit a task to the queue.
-
-
-
Method Detail
-
submit
public <T> java.util.concurrent.CompletionStage<T> submit(BlockingCancelableTask<T> work)
Submit a task to the queue.- Returns:
- CompletionStage that will be completed with the return value of type T produced by the task, or completed exceptionally if the task times out, the task is kicked out of the queue by more tasks, or the task throws an exception during execution.
- Throws:
QueueShutdownException
- if this queue has been shutdown.
-
shutdown
public void shutdown()
Shuts down the queue. Any excuting or pending tasks will be canceled, their completion stages completed exceptionally with aQueueShutdownException
.
-
newBuilder
public static BlockingTaskQueue.Builder newBuilder()
Create a new blocking task queue builder with a default of 30 second timeout and max queue length of 5
-
-