Package org.pipecraft.pipes.sync.inter
Class CallbackPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.DelegatePipe<T>
-
- org.pipecraft.pipes.sync.inter.CallbackPipe<T>
-
- Type Parameters:
T- The item data type
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class CallbackPipe<T> extends DelegatePipe<T>
A pipe invoking a callback method per item passed through it. The callback is never invoked on null values which indicate end of input pipe. Also supports a termination action, which is run exactly once when pipe termination is detected. Pipe output is same as pipe input.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description CallbackPipe(Pipe<T> input, FailableConsumer<? super T,? extends PipeException> itemCallback)ConstructorCallbackPipe(Pipe<T> input, FailableConsumer<? super T,? extends PipeException> itemCallback, FailableRunnable<? extends PipeException> terminationCallback)ConstructorCallbackPipe(Pipe<T> input, FailableRunnable<? extends PipeException> terminationCallback)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tnext()Tpeek()-
Methods inherited from class org.pipecraft.pipes.sync.inter.DelegatePipe
close, getOriginPipe, getProgress, start
-
-
-
-
Constructor Detail
-
CallbackPipe
public CallbackPipe(Pipe<T> input, FailableConsumer<? super T,? extends PipeException> itemCallback, FailableRunnable<? extends PipeException> terminationCallback)
Constructor- Parameters:
input- The input pipeitemCallback- The callback to invoke. Allows throwing aPipeExceptionto signal pipeline termination.terminationCallback- A termination callback, executed once, when pipe termination is detected. Note that this callback can still fail the processing withPipeExceptionif needed. If input pipe isn't fully consumed, this callback won't be triggered.
-
CallbackPipe
public CallbackPipe(Pipe<T> input, FailableConsumer<? super T,? extends PipeException> itemCallback)
Constructor- Parameters:
input- The input pipeitemCallback- The callback to invoke
-
CallbackPipe
public CallbackPipe(Pipe<T> input, FailableRunnable<? extends PipeException> terminationCallback)
Constructor- Parameters:
input- The input pipeterminationCallback- A termination callback, executed once, when pipe termination is detected. If input pipe isn't fully consumed, this callback won't be triggered.
-
-
Method Detail
-
next
public T next() throws PipeException, InterruptedException
- Specified by:
nextin interfacePipe<T>- Overrides:
nextin classDelegatePipe<T>- Returns:
- The next item in this pipe output, or null if the output end has been reached. May be a blocking operation.
- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream while trying to prepare next item to return.InterruptedException- In case that the operation has been interrupted by another thread.
-
peek
public T peek() throws PipeException
- Specified by:
peekin interfacePipe<T>- Overrides:
peekin classDelegatePipe<T>- Returns:
- The next item in the pipe's output. Does not remove it, so next call to next() will return it.
- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream while trying to prepare next item to return.
-
-