Package org.pipecraft.pipes.async.inter
Class SyncToAsyncPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.async.AsyncPipe<T>
-
- org.pipecraft.pipes.async.inter.SyncToAsyncPipe<T>
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe
public class SyncToAsyncPipe<T> extends AsyncPipe<T>
A pipe converting multiple sync pipes into a single async one. The caller can configure the number of threads used for publishing the input pipes' items. The implementation makes sure to maintain thread safety of the synchronous input pipes by handling each pipe using a single thread.- Author:
- Eyal Schneider
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.pipecraft.pipes.async.AsyncPipe
AsyncPipe.Status
-
-
Constructor Summary
Constructors Constructor Description SyncToAsyncPipe(Collection<PipeSupplier<T>> inputPipeSuppliers, int threadCount)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static <T> SyncToAsyncPipe<T>fromPipe(Pipe<T> input)static <T> SyncToAsyncPipe<T>fromPipes(Collection<Pipe<T>> inputs, int threadCount)floatgetProgress()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.async.AsyncPipe
getStatus, notifyDone, notifyError, notifyNext, setListener
-
-
-
-
Constructor Detail
-
SyncToAsyncPipe
public SyncToAsyncPipe(Collection<PipeSupplier<T>> inputPipeSuppliers, int threadCount)
Constructor- Parameters:
inputPipeSuppliers- The input pipe suppliers (allowing lazy initialization). The produced pipes are not required to be thread safe.threadCount- The number of threads to actively fetch data from the input pipes. Thread compete on "acquiring" pipes and then draining them. There's no benefit in setting number of threads larger than the number of pipes.
-
-
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()
- Returns:
- Percent of pipes that were finished.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAsyncPipe<T>- Throws:
IOException
-
fromPipes
public static <T> SyncToAsyncPipe<T> fromPipes(Collection<Pipe<T>> inputs, int threadCount)
- Parameters:
inputs- A collection of pipes to be fed into theSyncToAsyncPipethreadCount- The number of threads to actively fetch data from the input pipes. Must not exceed the number of input pipes. Each thread is assigned an exclusive set of pipes to read from.- Returns:
- A new
SyncToAsyncPipeinitialized with the given input pipes
-
fromPipe
public static <T> SyncToAsyncPipe<T> fromPipe(Pipe<T> input)
- Parameters:
input- The pipe to be fed into theSyncToAsyncPipe- Returns:
- A new
SyncToAsyncPipeinitialized with the given input pipes
-
-