Class 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 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 via objects.
      • 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 interface ObjectRunnable<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 interface ObjectRunnable<O1,​O2>
        Returns:
        The object with which this runnable is managed and executed within an object-specific executor service.
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • 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 return false 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 interface ObjectRunnable<O1,​O2>
        Throws:
        InterruptedException - If the waiting thread is interrupted while waiting for this runnable to terminate, an InterruptedException will be thrown.