Interface ProcessorManager<T,R>

Type Parameters:
T - return type of FrameProcessor created by this manager
R - result type of this manager; see result()
All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
AccumulatingProcessorManager, ConcurrencyLimitedProcessorManager, SequenceProcessorManager

public interface ProcessorManager<T,R> extends Closeable
Used by FrameProcessorExecutor.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 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 Type
    Method
    Description
    void
    Called when all processors are done, or when one has failed.
    com.google.common.util.concurrent.ListenableFuture<Optional<ProcessorAndCallback<T>>>
    Returns the next processor that should be run, along with a callback.
    Called after all procesors are done, prior to close(), to retrieve the result of this computation.
    default <R2> ProcessorManager<T,R2>
    withAccumulation(R2 initialResult, BiFunction<R2,T,R2> accumulateFn)
    Returns an AccumulatingProcessorManager that wraps this manager and accumulates a result, to be returned by its result() 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" or close(). 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 after close().
      Throws:
      NoSuchElementException - if a prior call to this method had returned an empty Optional
    • result

      R result()
      Called after all procesors are done, prior to close(), to retrieve the result of this computation. Behavior of this method is undefined if called after close(), or if called prior to next() returning an empty Optional, or if called prior to all callbacks from next() having been called.
    • 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
    • withAccumulation

      default <R2> ProcessorManager<T,R2> withAccumulation(R2 initialResult, BiFunction<R2,T,R2> accumulateFn)
      Returns an AccumulatingProcessorManager that wraps this manager and accumulates a result, to be returned by its result() method.
      Type Parameters:
      R2 - result type of the returned manager
      Parameters:
      initialResult - initial accumulated value
      accumulateFn - accumulation function, will be provided the current accumulated value and the incremental new value.