Class 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
    • 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,
                          InterruptedException
        Description copied from interface: BasePipe
        Performs 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.
      • fromPipes

        public static <T> SyncToAsyncPipe<T> fromPipes​(Collection<Pipe<T>> inputs,
                                                       int threadCount)
        Parameters:
        inputs - A collection of pipes to be fed into the SyncToAsyncPipe
        threadCount - 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 SyncToAsyncPipe initialized with the given input pipes