Interface ProcessorManager<T,R>
- Type Parameters:
T- return type ofFrameProcessorcreated by this managerR- result type of this manager; seeresult()
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
AccumulatingProcessorManager,ConcurrencyLimitedProcessorManager,SequenceProcessorManager
Used by
FrameProcessorExecutor.runAllFully(org.apache.druid.frame.processor.manager.ProcessorManager<T, ? extends R>, int, org.apache.druid.frame.processor.Bouncer, java.lang.String) to manage the launching of processors. Processors returned by
this class may run concurrently with each other.
This interface allows for simple sequences of processors, such as ProcessorManagers.of(Sequence). It also
allows for situations where later processors depend on the results of earlier processors. (The result of earlier
processors are made available to the manager through ProcessorAndCallback.onComplete(Object).)
Implementations do not need to be thread-safe.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Called when all processors are done, or when one has failed.com.google.common.util.concurrent.ListenableFuture<Optional<ProcessorAndCallback<T>>>next()Returns the next processor that should be run, along with a callback.result()Called after all procesors are done, prior toclose(), to retrieve the result of this computation.default <R2> ProcessorManager<T,R2> withAccumulation(R2 initialResult, BiFunction<R2, T, R2> accumulateFn) Returns anAccumulatingProcessorManagerthat wraps this manager and accumulates a result, to be returned by itsresult()method.
-
Method Details
-
next
com.google.common.util.concurrent.ListenableFuture<Optional<ProcessorAndCallback<T>>> next()Returns the next processor that should be run, along with a callback. The callback is called when the processor completes successfully, along with the result of the processor. If the processor fails, the callback is not called. The callback is called in a thread-safe manner: it will never be called concurrently with another callback, or concurrently with a call to "next" orclose(). To ensure this,FrameProcessorExecutor.runAllFully(org.apache.druid.frame.processor.manager.ProcessorManager<T, ? extends R>, int, org.apache.druid.frame.processor.Bouncer, java.lang.String)synchronizes executions of callbacks for the same processor manager. Therefore, it is important that the callbacks executed quickly. This method returns a future, so it allows for logic where the construction of later processors depends on the results of earlier processors. Returns an empty Optional if there are no more processors to run. Behavior of this method is undefined if called afterclose().- Throws:
NoSuchElementException- if a prior call to this method had returned an empty Optional
-
result
R result() -
close
void close()Called when all processors are done, or when one has failed. This method releases all resources associated with this manager. After calling this method, callers must call no other methods.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
withAccumulation
default <R2> ProcessorManager<T,R2> withAccumulation(R2 initialResult, BiFunction<R2, T, R2> accumulateFn) Returns anAccumulatingProcessorManagerthat wraps this manager and accumulates a result, to be returned by itsresult()method.- Type Parameters:
R2- result type of the returned manager- Parameters:
initialResult- initial accumulated valueaccumulateFn- accumulation function, will be provided the current accumulated value and the incremental new value.
-