Class ConcurrentCharLoader

  • All Implemented Interfaces:
    java.lang.Runnable

    class ConcurrentCharLoader
    extends java.lang.Object
    implements java.lang.Runnable
    A concurrent character loader for loading a pool of CharBucket instances using a Reader in a separate thread
    See Also:
    ConcurrentCharInputReader, CharBucket, Entry
    • Field Detail

      • buckets

        private final java.util.concurrent.ArrayBlockingQueue<java.lang.Object> buckets
      • finished

        private boolean finished
      • active

        private boolean active
      • reader

        java.io.Reader reader
      • activeExecution

        private java.lang.Thread activeExecution
      • error

        private java.lang.Exception error
      • closeOnStop

        private final boolean closeOnStop
    • Constructor Detail

      • ConcurrentCharLoader

        public ConcurrentCharLoader​(java.io.Reader reader,
                                    int bucketSize,
                                    int bucketQuantity,
                                    boolean closeOnStop)
        Creates a FixedInstancePool with a given amount of CharBucket instances and starts a thread to fill each one.
        Parameters:
        reader - The source of characters to extract and fill CharBucket instances
        bucketSize - The size of each individual CharBucket
        bucketQuantity - The number of CharBucket instances used to extract characters from the given reader.
        closeOnStop - Indicates whether to automatically close the input when stopReading() is called
    • Method Detail

      • readBucket

        private int readBucket()
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • run

        public void run()
        The CharBucket loading process that executes in parallel until the input is completely read. Once the end of the input is reached, the Reader instance provided in the constructor is closed.
        Specified by:
        run in interface java.lang.Runnable
      • setError

        private void setError​(java.lang.Exception e)
      • nextBucket

        public CharBucket nextBucket()
        Returns the next available bucket. Blocks until a bucket is made available or the reading process stops.
        Returns:
        the next available bucket.
      • stopReading

        public void stopReading()
        Stops the CharBucket loading process and closes the reader provided in the constructor of this class
      • reportError

        void reportError()