Class ConsumerPipe<T>

  • Type Parameters:
    T - The input items' data type
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class ConsumerPipe<T>
    extends TerminalPipe
    A terminal pipe that consumes all contents of the input pipe in a synchronous manner. That is, calling start() will loop in over all outputs of the input pipe, performing the given action on each item.
    Author:
    Eyal Schneider
    • Constructor Detail

      • ConsumerPipe

        public ConsumerPipe​(Pipe<T> input,
                            FailableConsumer<? super T,​PipeException> itemAction,
                            Runnable terminationAction)
        Constructor
        Parameters:
        input - The input pipe
        itemAction - The action to perform on all items. Legitimate errors should be wrapped by PipeException.
        terminationAction - An action to perform once all input items have been consumed. Runs once, upon a successful iteration termination only.
      • ConsumerPipe

        public ConsumerPipe​(Pipe<T> input,
                            FailableConsumer<? super T,​PipeException> itemAction)
        Constructor
        Parameters:
        input - The input pipe
        itemAction - The action to perform on all items. Legitimate errors should be wrapped by PipeException.
      • ConsumerPipe

        public ConsumerPipe​(Pipe<T> input,
                            Runnable terminationAction)
        Constructor
        Parameters:
        input - The input pipe
        terminationAction - An action to perform once all input items have been consumed. Runs once, upon a successful iteration termination only.
      • ConsumerPipe

        public ConsumerPipe​(Pipe<T> input)
        Constructor Builds a no-op consumer
        Parameters:
        input - The input pipe
    • Method Detail

      • start

        public void start()
                   throws PipeException,
                          InterruptedException
        Description copied from interface: BasePipe
        Performs pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.
        Throws:
        PipeException - In case of pipe errors in this pipe or somewhere up-stream.
        InterruptedException - In case that the operation has been interrupted by another thread.