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:
    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 Detail

      • 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 via AbstractObjectRunnable.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 this ObjectRunnable in 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: AbstractObjectRunnable
        Runs this runnable actually. Activation and termination signalling are already handled, implementations only need to react to termination requests.
        Specified by:
        runForObject in class AbstractObjectRunnable<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 return false if you want to continue to work without interruption, e.g. to change the executing thread.