Package org.pipecraft.pipes.terminal
Class ParallelConsumerPipe
- java.lang.Object
-
- org.pipecraft.pipes.terminal.TerminalPipe
-
- org.pipecraft.pipes.terminal.ParallelConsumerPipe
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe
public class ParallelConsumerPipe extends TerminalPipe
A terminal pipe that consumes multiple input pipes in a parallel manner, with a configurable number of threads. For thread safety reasons, it is guaranteed that each pipe is consumed by exactly one thread. Each of the input pipes may be of any type: sync, async or terminal.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description ParallelConsumerPipe(int parallelism, Collection<? extends BasePipe> inputs)ConstructorParallelConsumerPipe(int parallelism, Collection<? extends BasePipe> inputs, Runnable terminationAction)ConstructorParallelConsumerPipe(int parallelism, BasePipe... inputs)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
-
ParallelConsumerPipe
public ParallelConsumerPipe(int parallelism, Collection<? extends BasePipe> inputs, Runnable terminationAction)Constructor- Parameters:
parallelism- The number of threads to use for consuming all pipesinputs- The input pipesterminationAction- An action to perform once all input items from all pipes have been consumed. Runs once, upon a successful iteration termination only. Must be thread safe!
-
ParallelConsumerPipe
public ParallelConsumerPipe(int parallelism, Collection<? extends BasePipe> inputs)Constructor- Parameters:
parallelism- The number of threads to use for consuming all pipesinputs- The input pipes
-
ParallelConsumerPipe
public ParallelConsumerPipe(int parallelism, BasePipe... inputs)Constructor- Parameters:
parallelism- The number of threads to use for consuming all pipesinputs- The input pipes
-
-
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.
-
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.
-
-