Package org.pipecraft.pipes.terminal
Class ConsumerPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.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 Summary
Constructors Constructor Description ConsumerPipe(Pipe<T> input)Constructor Builds a no-op consumerConsumerPipe(Pipe<T> input, Runnable terminationAction)ConstructorConsumerPipe(Pipe<T> input, FailableConsumer<? super T,PipeException> itemAction)ConstructorConsumerPipe(Pipe<T> input, FailableConsumer<? super T,PipeException> itemAction, Runnable terminationAction)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.terminal.TerminalPipe
getProgress
-
-
-
-
Constructor Detail
-
ConsumerPipe
public ConsumerPipe(Pipe<T> input, FailableConsumer<? super T,PipeException> itemAction, Runnable terminationAction)
Constructor- Parameters:
input- The input pipeitemAction- 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 pipeitemAction- 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 pipeterminationAction- An action to perform once all input items have been consumed. Runs once, upon a successful iteration termination only.
-
-
Method Detail
-
close
public void close() throws IOException- Throws:
IOException
-
start
public void start() throws PipeException, InterruptedExceptionDescription copied from interface:BasePipePerforms 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.
-
-