Class AsyncHeadPipe<T>

  • Type Parameters:
    T - The item data type
    All Implemented Interfaces:
    Closeable, AutoCloseable, BasePipe

    public class AsyncHeadPipe<T>
    extends AsyncPipe<T>
    An async version of the head pipe (See HeadPipe. It guarantees that K items or less (in case there are less than K available by the input pipe) are produced. Since async pipes in general don't guarantee any order, the identity of the produced items may not be consistent.
    Author:
    Eyal Schneider
    • Constructor Detail

      • AsyncHeadPipe

        public AsyncHeadPipe​(AsyncPipe<T> input,
                             int count)
        constructor
        Parameters:
        input - The input pipe
        count - The number of items to pass on
    • 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:
        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.