Interface ProcessorManager<T,​R>

    • 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" 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.