Class FlowControlledProcessor<T>

  • Type Parameters:
    T - The type of result produced / accepted
    Direct Known Subclasses:

    public abstract class FlowControlledProcessor<T>
    extends java.lang.Object
    Abstract implementation which will do async processing, but only submit a limited number of tasks processing concurrently. This is different from something like an ExecutorLimiter because it not only limits execution, but pulls for new tasks when ready. This makes it easier to limit how much is held in heap. Otherwise while pools may limit execution to prevent over utilizing resources, this will help prevent task submission to ensure that the running processor does not over-consume its heap.

    This object is one time use. Once hasNext() returns false it should be considered done forever. If more work needs to be processed then this object needs to be reconstructed with a new instance.

    • Constructor Summary

      Constructor Description
      FlowControlledProcessor​(int maxRunningTasks, boolean provideResultsInOrder)
      Construct a new processor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ListenableFuture<?> start()
      Start processing tasks.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FlowControlledProcessor

        public FlowControlledProcessor​(int maxRunningTasks,
                                       boolean provideResultsInOrder)
        Construct a new processor. You must invoke start() once constructed to start processing.
        maxRunningTasks - Maximum number of concurrent running tasks
        provideResultsInOrder - If true completed results will be provided in the order they are submitted
    • Method Detail

      • start

        public ListenableFuture<?> start()
        Start processing tasks. The returned future wont complete until task execution has completed or unless handleFailure(Throwable) returns false indicating an error is not able to be handled.

        In the case of an unhandled error the returned future will finish with the error condition. Because of that, it's important the returned futures state is checked to verify an unhandled error did not occur. This can be done easily with ListenableFuture.failureCallback(java.util.function.Consumer).

        Future to indicate state of completion. This future's result