Class AbstractObjectRunnable<O1,O2,R>
java.lang.Object
de.aristaflow.adept2.util.threading.executor.AbstractObjectRunnable<O1,O2,R>
- Type Parameters:
O1- The type of objects for which runnables are registered.O2- The type of objects with which runnables are managed and executed within an object-specific executor service.R- The runtime data for managed objects. This allows for arbitrary data for each managed object.
- All Implemented Interfaces:
ObjectRunnable<O1,,O2> Runnable
- Direct Known Subclasses:
ObjectOneWorkRunnable,PipelineRunnable,ScheduledObjectOneWorkRunnable
public abstract class AbstractObjectRunnable<O1,O2,R>
extends Object
implements ObjectRunnable<O1,O2>
An abstract implementation for an
ObjectRunnable including some lifecycle management
like being active and termination.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LoggerThe logger for various purpose, e.The data structures containing all objects and the corresponding work.protected final AtomicIntegerThe amount of termination requests. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractObjectRunnable(O1 registeredObject, O2 indexObject, Map<O2, Pair<ObjectRunnable<O1, O2>, R>> objects, AtomicInteger terminate, Logger logger) Creates a new runnable for the designated object. -
Method Summary
Modifier and TypeMethodDescriptionvoidAwaits the termination of this runnable.Gets the object with which this runnable is managed and executed within an object-specific executor service.Gets the object with which this runnable has been registered at an object-specific executor service.voidrun()protected abstract booleanRuns this runnable actually.
-
Field Details
-
objects
The data structures containing all objects and the corresponding work. -
terminate
The amount of termination requests. If this is > 1, the runnable has to terminate.
Access has to be synchronised viaobjects. -
logger
The logger for various purpose, e. g. logging exceptions which are not propagated to outside the runnable.
-
-
Constructor Details
-
AbstractObjectRunnable
protected AbstractObjectRunnable(O1 registeredObject, O2 indexObject, Map<O2, Pair<ObjectRunnable<O1, O2>, R>> objects, AtomicInteger terminate, Logger logger) Creates a new runnable for the designated object.- Parameters:
registeredObject- The object for which this runnable has been registered.indexObject- The object with which this runnable is managed and executed within the corresponding object-specific executor service.objects- The data structures containing all objects and the corresponding work.terminate- The amount of termination requests.logger- The logger for various purpose, e. g. logging exceptions which are not propagated to outside the runnable.
-
-
Method Details
-
getRegisteredObject
Description copied from interface:ObjectRunnableGets the object with which this runnable has been registered at an object-specific executor service.- Specified by:
getRegisteredObjectin interfaceObjectRunnable<O1,O2> - Returns:
- The object with which this runnable has been registered at an object-specific executor service.
-
getIndexObject
Description copied from interface:ObjectRunnableGets the object with which this runnable is managed and executed within an object-specific executor service.- Specified by:
getIndexObjectin interfaceObjectRunnable<O1,O2> - Returns:
- The object with which this runnable is managed and executed within an object-specific executor service.
-
run
public void run() -
runForObject
protected abstract boolean runForObject()Runs this runnable actually. Activation and termination signalling are already handled, implementations only need to react to termination requests.- 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.
-
awaitTermination
Description copied from interface:ObjectRunnableAwaits the termination of this runnable. Either the thread has been interrupted, its termination has been requested or the runnable has simply finished.- Specified by:
awaitTerminationin interfaceObjectRunnable<O1,O2> - Throws:
InterruptedException- If the waiting thread is interrupted while waiting for this runnable to terminate, anInterruptedExceptionwill be thrown.
-