Interface PrioritisedExecutor

All Known Implementing Classes:
BalancedPrioritisedThreadPool.OrderedStreamGroup.Queue, PrioritisedQueueExecutorThread, PrioritisedTaskQueue

public interface PrioritisedExecutor
  • 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

      boolean executeTask() throws IllegalStateException
      Executes the next available task.

      If there is a task with priority Priority.BLOCKING available, then that such task is executed.

      If there is a task with priority Priority.IDLE available 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.BLOCKING or Priority.IDLE, then this function will be biased to execute tasks that have higher priorities.

      Returns:
      true if a task was executed, false otherwise
      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 in IllegalStateException being 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:
      true if the executor was shutdown, false if 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 at Priority.NORMAL priority.
      Parameters:
      task - The task to run.
      Returns:
      null if 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:
      null if 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
      IllegalArgumentException - 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:
      null if 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
      IllegalArgumentException - If the priority is invalid.
    • createTask

      Creates, but does not queue or execute, a task at Priority.NORMAL priority.
      Parameters:
      task - The task to run.
      Returns:
      null if 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 at Priority.NORMAL priority.
      Parameters:
      task - The task to run.
      priority - The priority for the task.
      Returns:
      null if the current thread immediately executed the task, else returns the prioritised task associated with the parameter
      Throws:
      NullPointerException - If the task is null
      IllegalArgumentException - 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 at Priority.NORMAL priority.
      Parameters:
      task - The task to run.
      priority - The priority for the task.
      subOrder - The task's suborder.
      stream - The task's stream.
      Returns:
      null if the current thread immediately executed the task, else returns the prioritised task associated with the parameter
      Throws:
      NullPointerException - If the task is null
      IllegalArgumentException - If the priority is invalid.