Class ObjectOneWorkRunnable<O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- java.lang.Object
-
- de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable<O,O,R>
-
- de.aristaflow.adept2.util.threading.executor.ObjectOneWorkRunnable<O,R>
-
- 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:
ObjectRunnable<O,O>,Runnable
public class ObjectOneWorkRunnable<O,R extends AbstractObjectOneWorkExecutor.RuntimeData> extends AbstractObjectRunnable<O,O,R>
A runnable for having exactly one runnable per object. It removes the object from all work before running and thus allows to add a new runnable for this object.
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractObjectOneWorkExecutor<O,R>executorThe executor to which to add thisObjectRunnablein case there is more work for the object.protected AtomicIntegerflushPendingThe amount of pending flushs.-
Fields inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable
logger, objects, terminate
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedObjectOneWorkRunnable(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanrunForObject()Runs this runnable actually.-
Methods inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable
awaitTermination, getIndexObject, getRegisteredObject, run
-
-
-
-
Field Detail
-
executor
protected final AbstractObjectOneWorkExecutor<O,R extends AbstractObjectOneWorkExecutor.RuntimeData> executor
The executor to which to add thisObjectRunnablein case there is more work for the object. Re-adding instead of executing the work prevents starvation of work for specific objects.
-
flushPending
protected final AtomicInteger 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-scheduling it.
Normally, re-schedlung 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 Detail
-
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-scheduling it.logger- The logger which to use for runtime exceptions stemming from a executing a runnable. Such an exception will only be logged.
-
-
Method Detail
-
runForObject
protected boolean runForObject()
Description copied from class:AbstractObjectRunnableRuns this runnable actually. Activation and termination signalling are already handled, implementations only need to react to termination requests.- Specified by:
runForObjectin classAbstractObjectRunnable<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>- Returns:
- Whether the work for the object has been terminated. Otherwise there is work left and
the termination is not signalled. With a termination request, return
true, only returnfalseif you want to continue to work without interruption, e.g. to change the executing thread.
-
-