Package org.pipecraft.pipes.sync.inter
Class QueuePipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.CompoundPipe<T>
-
- org.pipecraft.pipes.sync.inter.QueuePipe<T>
-
- Type Parameters:
T- The item data type
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class QueuePipe<T> extends CompoundPipe<T>
An intermediate pipe that actively pulls items from the input pipe and stores in a queue for the downstream pipe to fetch. The threading model is a little different from other synchronous pipes: all upstream pipes are handled by an internal thread (the "produced thread" feeding the queue), while all actions on this pipe are handled by the caller's thread. Therefore, positioning a QueuePipe in a flow will break the flow into producer part and consumer part, each of them handled by a different thread.- Author:
- Eyal Schneider
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Pipe<T>createPipeline()-
Methods inherited from class org.pipecraft.pipes.sync.inter.CompoundPipe
close, getProgress, next, peek, start
-
-
-
-
Constructor Detail
-
QueuePipe
public QueuePipe(Pipe<T> inputPipe, BlockingQueue<QueueItem<T>> queue)
Constructor- Parameters:
inputPipe- The input pipe to pull items fromqueue- The queue to store data available for pulling from this pipe. Be careful with unbounded queues.
-
QueuePipe
public QueuePipe(Pipe<T> inputPipe, int queueCapacity)
Constructor- Parameters:
inputPipe- The input pipe to pull items fromqueueCapacity- The capacity to use for the internal queue. Uses aLinkedBlockingQueue.
-
-
Method Detail
-
createPipeline
protected Pipe<T> createPipeline() throws PipeException, InterruptedException
- Specified by:
createPipelinein classCompoundPipe<T>- Returns:
- A new pipeline to represent the logic of this pipe
- Throws:
PipeException- In case of a pipeline creation errorInterruptedException- In case that the thread is interrupted
-
-