Interface ProcessorManager<T,R>
-
- Type Parameters:
T
- return type ofFrameProcessor
created by this managerR
- result type of this manager; seeresult()
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
AccumulatingProcessorManager
,SequenceProcessorManager
public interface ProcessorManager<T,R> extends Closeable
Used byFrameProcessorExecutor.runAllFully(org.apache.druid.frame.processor.manager.ProcessorManager<T, 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 asProcessorManagers.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 throughProcessorAndCallback.onComplete(Object)
.) Implementations do not need to be thread-safe.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
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.R
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 anAccumulatingProcessorManager
that wraps this manager and accumulates a result, to be returned by itsresult()
method.
-
-
-
Method Detail
-
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, 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
withAccumulation
default <R2> ProcessorManager<T,R2> withAccumulation(R2 initialResult, BiFunction<R2,T,R2> accumulateFn)
Returns anAccumulatingProcessorManager
that 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.
-
-