Interface PrioritisedExecutor
- All Known Implementing Classes:
BalancedPrioritisedThreadPool.OrderedStreamGroup.Queue,PrioritisedQueueExecutorThread,PrioritisedTaskQueue
public interface PrioritisedExecutor
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic final record -
Method Summary
Modifier and TypeMethodDescriptioncreateTask(Runnable task) Creates, but does not queue or execute, a task atPriority.NORMALpriority.createTask(Runnable task, Priority priority) Creates, but does not queue or execute, a task atPriority.NORMALpriority.createTask(Runnable task, Priority priority, long subOrder, long stream) Creates, but does not queue or execute, a task atPriority.NORMALpriority.booleanExecutes the next available task.longGenerates the next suborder id.longReturns the number of tasks that have been executed.longReturns the number of tasks that have been scheduled are pending to be scheduled.booleanReturns whether this executor has shut down.Queues or executes a task atPriority.NORMALpriority.Queues or executes a task.Queues or executes a task.booleanshutdown()Prevent further additions to this executor.
-
Method Details
-
getTotalTasksScheduled
long getTotalTasksScheduled()Returns the number of tasks that have been scheduled are pending to be scheduled. -
getTotalTasksExecuted
long getTotalTasksExecuted()Returns the number of tasks that have been executed. -
generateNextSubOrder
long generateNextSubOrder()Generates the next suborder id.- Returns:
- The next suborder id.
-
executeTask
Executes the next available task.If there is a task with priority
Priority.BLOCKINGavailable, then that such task is executed.If there is a task with priority
Priority.IDLEavailable then that task is only executed when there are no other tasks available with a higher priority.If there are no tasks that have priority
Priority.BLOCKINGorPriority.IDLE, then this function will be biased to execute tasks that have higher priorities.- Returns:
trueif a task was executed,falseotherwise- Throws:
IllegalStateException- If the current thread is not allowed to execute a task
-
shutdown
boolean shutdown()Prevent further additions to this executor. Attempts to add after this call has completed (potentially during) will result inIllegalStateExceptionbeing thrown.This operation is atomic with respect to other shutdown calls
After this call has completed, regardless of return value, this executor will be shutdown.
- Returns:
trueif the executor was shutdown,falseif it has shut down already- See Also:
-
isShutdown
boolean isShutdown()Returns whether this executor has shut down. Effectively, returns whether new tasks will be rejected. This method does not indicate whether all the tasks scheduled have been executed.- Returns:
- Returns whether this executor has shut down.
-
queueTask
Queues or executes a task atPriority.NORMALpriority.- Parameters:
task- The task to run.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
IllegalStateException- If this executor has shutdown.NullPointerException- If the task is null
-
queueTask
Queues or executes a task.- Parameters:
task- The task to run.priority- The priority for the task.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
IllegalStateException- If this executor has shutdown.NullPointerException- If the task is nullIllegalArgumentException- If the priority is invalid.
-
queueTask
PrioritisedExecutor.PrioritisedTask queueTask(Runnable task, Priority priority, long subOrder, long stream) Queues or executes a task.- Parameters:
task- The task to run.priority- The priority for the task.subOrder- The task's suborder.stream- The task's stream id.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
IllegalStateException- If this executor has shutdown.NullPointerException- If the task is nullIllegalArgumentException- If the priority is invalid.
-
createTask
Creates, but does not queue or execute, a task atPriority.NORMALpriority.- Parameters:
task- The task to run.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
NullPointerException- If the task is null
-
createTask
Creates, but does not queue or execute, a task atPriority.NORMALpriority.- Parameters:
task- The task to run.priority- The priority for the task.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
NullPointerException- If the task is nullIllegalArgumentException- If the priority is invalid.
-
createTask
PrioritisedExecutor.PrioritisedTask createTask(Runnable task, Priority priority, long subOrder, long stream) Creates, but does not queue or execute, a task atPriority.NORMALpriority.- Parameters:
task- The task to run.priority- The priority for the task.subOrder- The task's suborder.stream- The task's stream.- Returns:
nullif the current thread immediately executed the task, else returns the prioritised task associated with the parameter- Throws:
NullPointerException- If the task is nullIllegalArgumentException- If the priority is invalid.
-