de.caff.util.concurrent

## Interface PriorityExecutor

- All Known Implementing Classes:
    PriorityThreadPoolExecutor

      public interface PriorityExecutor

  Executor which executes a task with a given priority. On heavy load situations it is possible that low priority tasks starve depending on the implementation of the executor.
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CANT_REMOVE` Return value for `removeTasksWithMark(Object)` if removing is not supported.
    `static PriorityExecutor` | `DIRECT_EXECUTOR` Priority executor which just executes the task directly without caring for priority.
    `static long` | `NO_ID` Return value for `execute(Priority, Object, Runnable)` indicating no valid id.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `execute(Priority priority, java.lang.Object mark, java.lang.Runnable task)` Execute a task with the given priority.
    `long` | `executeWithLifeCycle(Priority priority, TaskLifeCycleListener mark, java.lang.Runnable task)` Execute a task with the given priority.
    `int` | `removeTasksWithMark(java.lang.Object mark)` Remove all tasks which where started with the given mark.
    `boolean` | `removeTaskWithId(long id)` Remove the task with the given id.

- - ### Field Detail

    - #### NO_ID

          static final long NO_ID

      Return value for `execute(Priority, Object, Runnable)` indicating no valid id.
      See Also:
        Constant Field Values

    - #### CANT_REMOVE

          static final int CANT_REMOVE

      Return value for `removeTasksWithMark(Object)` if removing is not supported.
      See Also:
        Constant Field Values

    - #### DIRECT_EXECUTOR

          static final PriorityExecutor DIRECT_EXECUTOR

      Priority executor which just executes the task directly without caring for priority. As there is no queue, it neither cares for priority nor for mark.

  - ### Method Detail

    - #### execute

          long execute(@NotNull
                       Priority priority,
                       @Nullable
                       java.lang.Object mark,
                       @NotNull
                       java.lang.Runnable task)

      Execute a task with the given priority.
      Parameters:
        `priority` - priority of task
        `mark` - mark which allows access to objects in queue. Not all implementation need to take care of this.
        `task` - task to run
      Returns:
        an id allowing later access to this task, or `NO_ID` if access is no longer possible

    - #### executeWithLifeCycle

          long executeWithLifeCycle(@NotNull
                                    Priority priority,
                                    @NotNull
                                    TaskLifeCycleListener mark,
                                    @NotNull
                                    java.lang.Runnable task)

      Execute a task with the given priority.
      Parameters:
        `priority` - priority of task
        `mark` - mark which allows access to objects in queue, and also gets informed when the task is enqueued, started and finished. Not all implementation need to take care of this.
        `task` - task to run
      Returns:
        an id allowing later access to this task, or `NO_ID` if access is no longer possible

    - #### removeTasksWithMark

          int removeTasksWithMark(@NotNull
                                  java.lang.Object mark)

      Remove all tasks which where started with the given mark.
      Parameters:
        `mark` - mark to check for
      Returns:
        number of removed tasks if removing was possibe, or `CANT_REMOVE` if the executor does not allow removing

    - #### removeTaskWithId

          boolean removeTaskWithId(long id)

      Remove the task with the given id.
      Parameters:
        `id` - id
      Returns:
        `true` if a rask with the given id was found and removed
        `false`: if none was found