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
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.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class de.aristaflow.adept2.util.threading.LoggingFuture
LoggingFuture.IgnoredResultLogger -
Field Summary
Fields inherited from class de.aristaflow.adept2.util.threading.LoggingFuture
cleanup, logger, resultRelevant -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFlushTask(ObjectSpecificFlushCallable<?, T> flusher, AtomicInteger inPoolFlushers, Logger logger) Creates a new flush task executing the designated flusher. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddrained()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.voidrejected()Signals that submitting an execution of this runnable has failed, that is, the pool has rejected it.voidrun()voidSignals that an execution of this runnable has been submitted, that is, handed to a pool for execution.Methods inherited from class de.aristaflow.adept2.util.threading.LoggingFuture
cancel, equals, get, get, getWrappedFutureRunnable, hashCode, isCancelled, isDone, toString
-
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, ornullfor 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:
runin interfaceRunnable- Specified by:
runin interfaceRunnableFuture<T>- Overrides:
runin classLoggingFuture<T>
-
submitted
public void submitted()Description copied from interface:ManagedRunnableSignals 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:
submittedin interfaceManagedRunnable
-
rejected
public void rejected()Signals that submitting an execution of this runnable has failed, that is, the pool has rejected it. This revertsManagedRunnable.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:
rejectedin interfaceManagedRunnable
-
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.
-