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 anObjectRunnable
including some lifecycle management like being active and termination.
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
logger
The logger for various purpose, e. g. logging exceptions which are not propagated to outside the runnable.protected Map<O2,Pair<ObjectRunnable<O1,O2>,R>>
objects
The data structures containing all objects and the corresponding work.protected AtomicInteger
terminate
The amount of termination requests.
-
Constructor Summary
Constructors Modifier Constructor Description 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.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
awaitTermination()
Awaits the termination of this runnable.O2
getIndexObject()
Gets the object with which this runnable is managed and executed within an object-specific executor service.O1
getRegisteredObject()
Gets the object with which this runnable has been registered at an object-specific executor service.void
run()
protected abstract boolean
runForObject()
Runs this runnable actually.
-
-
-
Field Detail
-
objects
protected final Map<O2,Pair<ObjectRunnable<O1,O2>,R>> objects
The data structures containing all objects and the corresponding work.
-
terminate
protected final AtomicInteger terminate
The amount of termination requests. If this is > 1, the runnable has to terminate.
Access has to be synchronised viaobjects
.
-
logger
protected final Logger logger
The logger for various purpose, e. g. logging exceptions which are not propagated to outside the runnable.
-
-
Constructor Detail
-
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 Detail
-
getRegisteredObject
public O1 getRegisteredObject()
Description copied from interface:ObjectRunnable
Gets the object with which this runnable has been registered at an object-specific executor service.- Specified by:
getRegisteredObject
in interfaceObjectRunnable<O1,O2>
- Returns:
- The object with which this runnable has been registered at an object-specific executor service.
-
getIndexObject
public O2 getIndexObject()
Description copied from interface:ObjectRunnable
Gets the object with which this runnable is managed and executed within an object-specific executor service.- Specified by:
getIndexObject
in interfaceObjectRunnable<O1,O2>
- Returns:
- The object with which this runnable is managed and executed within an object-specific executor service.
-
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 returnfalse
if you want to continue to work without interruption, e.g. to change the executing thread.
-
awaitTermination
public void awaitTermination() throws InterruptedException
Description copied from interface:ObjectRunnable
Awaits the termination of this runnable. Either the thread has been interrupted, its termination has been requested or the runnable has simply finished.- Specified by:
awaitTermination
in interfaceObjectRunnable<O1,O2>
- Throws:
InterruptedException
- If the waiting thread is interrupted while waiting for this runnable to terminate, anInterruptedException
will be thrown.
-
-