Class QueuedReader<T>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<T>, FromFileReader<T>

    final class QueuedReader<T>
    extends java.lang.Object
    implements FromFileReader<T>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.Future<?>[] myFutures  
      private java.util.concurrent.BlockingQueue<T> myQueue  
      private FromFileReader<T>[] myReaders  
    • Constructor Summary

      Constructors 
      Constructor Description
      QueuedReader​(java.util.concurrent.ExecutorService executor, java.util.concurrent.BlockingQueue<T> queue, FromFileReader<T>... readers)
      Multiple suppliers supply to a queue, then you get from that queue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      int drainTo​(java.util.Collection<? super T> container, int maxElements)
      Behaves similar to BlockingQueue.drainTo(Collection, int) except that returning 0 means there are no more items to read.
      private boolean isDone()  
      T read()
      Returning null indicates that there are no more items to read.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • myFutures

        private final java.util.concurrent.Future<?>[] myFutures
      • myQueue

        private final java.util.concurrent.BlockingQueue<T> myQueue
    • Constructor Detail

      • QueuedReader

        QueuedReader​(java.util.concurrent.ExecutorService executor,
                     java.util.concurrent.BlockingQueue<T> queue,
                     FromFileReader<T>... readers)
        Multiple suppliers supply to a queue, then you get from that queue. There will be 1 thread (executor task) per supplier.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface FromFileReader<T>
        Throws:
        java.io.IOException
      • drainTo

        public int drainTo​(java.util.Collection<? super T> container,
                           int maxElements)
        Description copied from interface: FromFileReader
        Behaves similar to BlockingQueue.drainTo(Collection, int) except that returning 0 means there are no more items to read.
        Specified by:
        drainTo in interface FromFileReader<T>
      • read

        public T read()
        Description copied from interface: FromFileReader
        Returning null indicates that there are no more items to read. That's the same behaviour as BufferedReader.readLine(). All implementations must return null precisely once.
        Specified by:
        read in interface FromFileReader<T>
      • isDone

        private boolean isDone()