Class AbstractPipeliningExecutor<O,​P>

  • Type Parameters:
    O - The type of object for which work is registered.
    P - The type identifying a pipeline. This can be the same as <O> or an appropriate hash value for the registered object.
    All Implemented Interfaces:
    Executor, ExecutorService
    Direct Known Subclasses:
    LimitedPipelineExecutor, UnlimitedPipelineExecutor

    @Deprecated
    public abstract class AbstractPipeliningExecutor<O,​P>
    extends AFThreadPoolExecutor
    Deprecated.
    A thread pool executor that accepts work for specific objects and executing the work for each object serial but work for different objects parallel (or at least concurrently).
    While this thread pool executor can be used just like any ThreadPoolExecutor, it behaves differently when submitting a runnable together with an object. In this case all runnables submitted for an object will be executed in the order they arrive. This is similar to having a pipeline for each object. The amount of pipelines is bound to the maximum amount of threads in the thread pool. This prevents starving of a pipeline due to the other pipelines being never empty.

    Note that pipelines are not assigned to one thread. As long as there is work in a pipeline, it will be executed by the same thread. As soon as a pipeline is empty, new work may be done by a different thread.

    Author:
    Ulrich Kreher, Kevin Goeser
    • Field Detail

      • flushPending

        protected final AtomicInteger flushPending
        Deprecated.
        A counter for pending flushs. With this the running pipelines will be terminated/suspended and concurrent flushs will be synchronised.
      • abortCount

        protected final AtomicInteger abortCount
        Deprecated.
        A counter for all flushs that aborted pending work.
      • shutdownPending

        protected final AtomicBoolean shutdownPending
        Deprecated.
        Whether a shutdown has been requested.
      • logger

        protected final Logger logger
        Deprecated.
        The logger for log messages, especially runtime exception occurring when executing work.
    • Constructor Detail

      • AbstractPipeliningExecutor

        protected AbstractPipeliningExecutor​(Adept2ThreadFactory threadFactory)
        Deprecated.
        Creates a new thread pool executor with an unlimited amount of pipelines for different objects using the designate thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate.
        Parameters:
        threadFactory - The factory to use when the executor creates a new thread.
      • AbstractPipeliningExecutor

        protected AbstractPipeliningExecutor​(int limit,
                                             Adept2ThreadFactory threadFactory)
        Deprecated.
        Creates a new thread pool executor with the designated number of pipelines and threads for different objects using the designate thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate.
        Parameters:
        limit - The maximum number of threads allowed in the pool and also the maximum number of pipelines.
        threadFactory - The factory to use when the executor creates a new thread.
    • Method Detail

      • execute

        public void execute​(O object,
                            Runnable task)
        Deprecated.
        Executes the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.
        Parameters:
        object - The object for which to execute the designated task.
        task - The task which to execute.
        Throws:
        RejectedExecutionException - if the executor has been shut down.
        See Also:
        AFThreadPoolExecutor.execute(Runnable)
      • flushAndExecute

        public Map<P,​Queue<Runnable>> flushAndExecute​(boolean abortPending,
                                                            Runnable task)
        Deprecated.
        Flushes all pipelines and executes the designated task. When aborting, all registered work will be removed and returned. Otherwise null will be returned and the pipelines will restart work after the designated task has been executed.
        This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the pipelines will restart. The tasks of concurrent flushs will be executed concurrently!
        Parameters:
        abortPending - Whether the present work should be cancelled. In this case the corresponding runnables will be returned.
        task - The task which to execute without any pipeline running.
        Returns:
        null in case no abortion is requested, otherwise the pipelines and the aborted work.
        Throws:
        RejectedExecutionException - if the executor has been shut down.
      • flushAndExecuteUnchecked

        protected Map<P,​Queue<Runnable>> flushAndExecuteUnchecked​(boolean abortPending,
                                                                        Runnable task)
        Deprecated.
        The same as flushAndExecute(boolean, Runnable) but without the check for a pending shutdown. This is required for the shutdown procedure.
        Parameters:
        abortPending - Whether the present work should be cancelled. In this case the corresponding runnables will be returned.
        task - The task which to execute without any pipeline running.
        Returns:
        null in case no abortion is requested, otherwise the pipelines and the aborted work.
        Throws:
        RejectedExecutionException - if the executor has been shut down.
      • submit

        public Future<?> submit​(O object,
                                Runnable task)
        Deprecated.
        Submits the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.
        Parameters:
        object - The object for which to execute the designated task.
        task - The task which to execute.
        Returns:
        A Future representing pending completion of the task
        Throws:
        RejectedExecutionException - if the executor has been shut down.
        See Also:
        AbstractExecutorService.submit(Runnable)
      • submit

        public <T> Future<T> submit​(O object,
                                    Callable<T> task)
        Deprecated.
        Submits the designated task for the designated object. If several tasks are to be executed for the same object, these tasks will be executed one after the other in the order they arrived.
        Parameters:
        object - The object for which to execute the designated task.
        task - The task which to execute.
        Returns:
        A Future representing pending completion of the task
        Throws:
        RejectedExecutionException - if the executor has been shut down.
        See Also:
        AbstractExecutorService.submit(Callable)
      • submitAndFlush

        public <T> Pair<Future<T>,​Map<P,​Queue<Runnable>>> submitAndFlush​(boolean abortPending,
                                                                                     Callable<T> task)
        Deprecated.
        Submits the designated task and flushes all pipelines. When aborting, all registered work will be removed and returned. Otherwise null will be returned and the pipelines will restart work after the designated task has been executed.
        This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the pipelines will restart. The tasks of concurrent flushs will be executed concurrently!
        Parameters:
        abortPending - Whether the present work should be cancelled. In this case the corresponding runnables will be returned.
        task - The task which to execute without any pipeline running.
        Returns:
        A pair containing the future representing the designated and as second element either null in case no abortion is requested or the pipelines and the aborted work.
        Throws:
        RejectedExecutionException - if the executor has been shut down.
        See Also:
        flushAndExecute(boolean, Runnable)
      • restartPipelines

        protected boolean restartPipelines​(boolean abortedPending)
        Deprecated.
        Restarts the pipelines after a flush. If there are several concurrent flushs the pipelines will be started after the last flush.
        Parameters:
        abortedPending - Whether the flush leading to this restart has aborted pending work.
        Returns:
        Whether the pipelines have been restarted. Otherwise there are concurrent flushs or the executor has been shut down.
      • shutdown

        public void shutdown()
        Deprecated.
        Shutting down will reject new work (normal or flushing). But the current work may terminate. If there is currently a flush pending, the actual shutdown will wait until the suppressed work has been executed.
        Specified by:
        shutdown in interface ExecutorService
        Overrides:
        shutdown in class ThreadPoolExecutor
      • getPipelineFor

        protected abstract P getPipelineFor​(O object)
        Deprecated.
        Gets the identifier determining the pipeline for the designated object accordingly to the limit of the number of pipelines.
        Parameters:
        object - The object for which to determine the pipeline.
        Returns:
        The identifier determining the pipeline for the designated object.