Class ObjectOneWorkRunnable<O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- Type Parameters:
O- The type of object for which to run.R- The runtime data for managed objects. This is a tuple of pending work before and after a flush.
- All Implemented Interfaces:
ManagedRunnable,ObjectRunnable<O,,O> Runnable
A RuntimeException of the work will only be logged, the work for the object
continues. Any other throwable will be propagated to the thread of the pool and therefore to its
uncaught exception handling. Before propagating, the bookkeeping for the object takes place, that
is, this runnable is either re-submitted (there is more work) or removed from the work map.
Otherwise the object would keep this runnable without the runnable being submitted and no work
would ever be executed for this object again. Work pending for the object is re-submitted then,
it must not be removed from the work map for being executed within this thread since this thread
is about to die. Only a VirtualMachineError will be propagated without any
bookkeeping since the bookkeeping may fail as well and would then hide the error.
-
Field Summary
FieldsFields inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable
executor, logger, objects, terminate -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedObjectOneWorkRunnable(O object, AbstractObjectOneWorkExecutor<O, R> executor, AtomicInteger terminate, AtomicInteger flushPending, Logger logger) Creates a new runnable that executes one runnable for a specific object. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidProcesses the rejection of the last execution of this runnable, that is, the bookkeeping which would have taken place after this execution.protected booleanRuns this runnable actually.Methods inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable
awaitTermination, getExecutionsStartedByCurrentThread, getIndexObject, getRegisteredObject, rejected, run, submitted
-
Field Details
-
flushPending
The amount of pending flushs. If a flush is pending, work for the same object has to be executed by the same runnable (and thread) instead of re-submitting it.
Normally, re-scheduling prevents starvation of work. When a flush is pending, the current work will be executed before the flush so no starvation will take place since the amount of work (before the flush) is restricted.
Access has to be synchronised viaAbstractObjectRunnable.objects.
-
-
Constructor Details
-
ObjectOneWorkRunnable
protected ObjectOneWorkRunnable(O object, AbstractObjectOneWorkExecutor<O, R> executor, AtomicInteger terminate, AtomicInteger flushPending, Logger logger) Creates a new runnable that executes one runnable for a specific object.- Parameters:
object- The object of this runnable.executor- The executor to which to add thisObjectRunnablein case there is more work for the object.terminate- The amount of termination requests. This allows for synchronising across different objects.flushPending- The amount of pending flushs. If a flush is pending, work for the same object has to be executed by the same runnable (and thread) instead of re-submitting it.logger- The logger which to use for runtime exceptions stemming from a executing a runnable. Such an exception will only be logged.
-
-
Method Details
-
executionRejected
protected void executionRejected()Processes the rejection of the last execution of this runnable, that is, the bookkeeping which would have taken place after this execution. The runnable will not be executed, so its object or pipeline would keep it without it being submitted and no work would ever be executed for this object or pipeline again.This is only called when no execution of this runnable is submitted or in progress any more, so no other execution takes care of the work. An execution which is rejected while another one is in progress does not get here, the execution in progress does the bookkeeping itself.
Implementations have to acquire the lock onAbstractObjectRunnable.objectsthemselves; the lock on the termination is not held. The default implementation does nothing. The work of the object stays registered so that an immediate shutdown still reports it, only this runnable is removed from the object. The work is cancelled though: a shutdown without abortion neither executes nor cancels it, so its future would never complete.- Overrides:
executionRejectedin classAbstractObjectRunnable<O,O, R extends AbstractObjectOneWorkExecutor.RuntimeData, AbstractObjectOneWorkExecutor<O, R extends AbstractObjectOneWorkExecutor.RuntimeData>>
-
runForObject
protected boolean runForObject()Description copied from class:AbstractObjectRunnableRuns this runnable actually. Counting the executions and signalling the termination are already handled, implementations only need to react to termination requests.An execution which has been submitted but has not started yet is awaited by a flush as well: it executes the work of its object as soon as it starts, so work which has been submitted before the flush completes before the task of the flush and no work runs concurrently to this task.
- Specified by:
runForObjectin classAbstractObjectRunnable<O,O, R extends AbstractObjectOneWorkExecutor.RuntimeData, AbstractObjectOneWorkExecutor<O, R extends AbstractObjectOneWorkExecutor.RuntimeData>> - Returns:
- Whether the work for the object has been terminated. Otherwise there is work left and
another execution of this runnable continues it. With a termination request, return
true, only returnfalseif you want to continue to work without interruption, e. g. to change the executing thread. The return value is informational, the termination is signalled based on the submitted and running executions.
-