Class FlowControlledProcessor<T>
- java.lang.Object
-
- org.threadly.concurrent.processing.FlowControlledProcessor<T>
-
- Type Parameters:
T
- The type of result produced / accepted
- Direct Known Subclasses:
FlowControlledNoFailureProcessor
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()
returnsfalse
it should be considered done forever. If more work needs to be processed then this object needs to be reconstructed with a new instance.- Since:
- 5.37
-
-
Constructor Summary
Constructors 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.
-
-
-
Constructor Detail
-
FlowControlledProcessor
public FlowControlledProcessor(int maxRunningTasks, boolean provideResultsInOrder)
Construct a new processor. You must invokestart()
once constructed to start processing.- Parameters:
maxRunningTasks
- Maximum number of concurrent running tasksprovideResultsInOrder
- Iftrue
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 unlesshandleFailure(Throwable)
returnsfalse
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)
.- Returns:
- Future to indicate state of completion. This future's result
-
-