Class AbstractObjectSpecificExecutor.FlushTask<T>

java.lang.Object
de.aristaflow.adept2.util.threading.LoggingFuture<T>
de.aristaflow.adept2.util.threading.executor.AbstractObjectSpecificExecutor.FlushTask<T>
Type Parameters:
T - The type of result of the flush task.
All Implemented Interfaces:
ManagedRunnable, Runnable, Future<T>, RunnableFuture<T>
Enclosing class:
AbstractObjectSpecificExecutor<O1,O2,R>

public static class AbstractObjectSpecificExecutor.FlushTask<T> extends LoggingFuture<T> implements ManagedRunnable
The task of a flush executing an ObjectSpecificFlushCallable. It blocks its thread until the work awaited by the flush has terminated, then it executes the flush task and restarts the object work.
Executors with a comparator-based queue can recognise flush tasks by this type. A comparator must not order a flush task before object runnables: the flush task blocks its thread until the awaited work has terminated, so overtaking the work it awaits can deadlock a saturated pool.
  • Constructor Details

    • FlushTask

      protected FlushTask(ObjectSpecificFlushCallable<?,T> flusher, AtomicInteger inPoolFlushers, Logger logger)
      Creates a new flush task executing the designated flusher.
      Parameters:
      flusher - The flusher which to execute.
      inPoolFlushers - The counter of flush tasks admitted to the pool which to decrement when this flush task has been executed or rejected, or null for a flush task executed by a dedicated thread.
      logger - The logger for an exception of the flusher which no one retrieves.
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
      Specified by:
      run in interface RunnableFuture<T>
      Overrides:
      run in class LoggingFuture<T>
    • submitted

      public void submitted()
      Description copied from interface: ManagedRunnable
      Signals that an execution of this runnable has been submitted, that is, handed to a pool for execution. The execution counts for the termination from now on, that is, for the time between being handed to the pool and being started (or rejected) by it. Awaiting the termination therefore awaits the execution although it has not started yet: work which has been submitted before a flush completes before the task of the flush and no work runs concurrently to this task.
      Specified by:
      submitted in interface ManagedRunnable
    • rejected

      public void rejected()
      Signals that submitting an execution of this runnable has failed, that is, the pool has rejected it. This reverts ManagedRunnable.submitted() since the execution will not take place.
      Nothing is reverted if the execution has started meanwhile, e. g. a handler for rejected executions which executes the task within the calling thread: Runnable.run() counts such an execution itself, so reverting would count it twice. The pool will never execute this flush task: the future of this task completes as cancelled and the object work is restarted, undoing the registration of the flush. Otherwise callers awaiting the future would block forever and the executor would never execute object work again. Nothing happens if this task has been executed meanwhile, e. g. by a handler for rejected executions which executes the task within the calling thread.

      This is the rejection by the pool itself, which the executor outlives. A flush task which an immediate shutdown has drained from the queue of the pool is settled by drained() instead, it must not restart the object work.

      Specified by:
      rejected in interface ManagedRunnable
    • drained

      protected void drained()
      Settles this flush task which an immediate shutdown has drained from the queue of the pool: the future of this task completes as cancelled, so that a caller awaiting it does not block, but the object work is not restarted, the termination request of the shutdown stays in force. Restarting would undo that request and the executor would execute the work which the shutdown has just reported as aborted. Nothing happens if this task has been executed meanwhile.