Package org.pipecraft.pipes.terminal
Class AsyncConsumerPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.AsyncConsumerPipe<T>
-
- Type Parameters:
T- The input item type
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe
public class AsyncConsumerPipe<T> extends TerminalPipe
Consumes the contents of anAsyncPipe, blocking in the start() method until all data is read. This class is similar toConsumerPipe, but intended for async pipes. The close() method should be called by the same thread calling start().- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description AsyncConsumerPipe(AsyncPipe<T> inputPipe)ConstructorAsyncConsumerPipe(AsyncPipe<T> inputPipe, FailableConsumer<? super T,PipeException> itemAction)ConstructorAsyncConsumerPipe(AsyncPipe<T> inputPipe, FailableConsumer<? super T,PipeException> itemAction, Runnable terminationAction)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()floatgetProgress()voidstart()Performs pre-processing prior to item flow throw the pipe.
-
-
-
Constructor Detail
-
AsyncConsumerPipe
public AsyncConsumerPipe(AsyncPipe<T> inputPipe, FailableConsumer<? super T,PipeException> itemAction, Runnable terminationAction)
Constructor- Parameters:
inputPipe- The pipe to consumeitemAction- The action to perform on all items. Legitimate errors should be wrapped by PipeException. Errors cause pipeline termination. Must be thread safe!terminationAction- An action to perform once all input items have been consumed. Runs once, upon a successful iteration termination only.
-
AsyncConsumerPipe
public AsyncConsumerPipe(AsyncPipe<T> inputPipe, FailableConsumer<? super T,PipeException> itemAction)
Constructor- Parameters:
inputPipe- The pipe to consumeitemAction- The action to perform on all items. Legitimate errors should be wrapped by PipeException. Errors cause pipeline termination. Must be thread safe!
-
-
Method Detail
-
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.
-
getProgress
public float getProgress()
- Specified by:
getProgressin interfaceBasePipe- Overrides:
getProgressin classTerminalPipe- Returns:
- The pipe flow progress, as a floating number between 0.0 and 1.0. Important implementation rules: 1) Calling this method before start() call is complete isn't allowed and has an undefined behavior. 2) Implementation should do best effort to provide an estimate of the progress this pipe has made (0.0 - 1.0) 3) When the pipe is fully consumed, getProgress() should return 1.0. 4) Results must be monotonous, i.e. results of consecutive calls may never be decreasing. 5) Thread safety: progress may be maintained by some thread/s but monitoring by other threads. Implementations must be thread safe.
-
close
public void close() throws IOException- Throws:
IOException
-
-