Class AccumulateCsvResults<T>

  • Type Parameters:
    T - Type of output being created (bean or strings)
    All Implemented Interfaces:
    java.lang.Runnable

    class AccumulateCsvResults<T>
    extends java.lang.Thread
    The accumulator takes two queues of results of transforming text input into bean output or bean input into text output (output and exceptions) and orders them for later consumption. This task is delegated to a separate thread so threads can quickly queue their results in a (synchronized, thread-safe) queue and move on with other work, while the relatively expensive operation of ordering the results doesn't block other threads waiting for access to the ordered map.
    Since:
    4.0
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Constructor Summary

      Constructors 
      Constructor Description
      AccumulateCsvResults​(java.util.concurrent.BlockingQueue<OrderedObject<T>> resultantBeansQueue, java.util.concurrent.BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue, java.util.SortedSet<java.lang.Long> expectedRecords, java.util.concurrent.ConcurrentMap<java.lang.Long,​T> resultantBeanMap, org.apache.commons.collections4.ListValuedMap<java.lang.Long,​CsvException> thrownExceptionsMap)
      The only accepted constructor for the accumulator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean isMustStop()
      Checks whether the accumulator should shut itself down.
      void run()  
      (package private) void setMustStop​(boolean mustStop)
      Tells the accumulator whether it should stop.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • resultantBeansQueue

        private final java.util.concurrent.BlockingQueue<OrderedObject<T>> resultantBeansQueue
      • expectedRecords

        private final java.util.SortedSet<java.lang.Long> expectedRecords
      • resultantBeanMap

        private final java.util.concurrent.ConcurrentMap<java.lang.Long,​T> resultantBeanMap
      • mustStop

        private boolean mustStop
      • thrownExceptionsMap

        private final org.apache.commons.collections4.ListValuedMap<java.lang.Long,​CsvException> thrownExceptionsMap
        All access to this variable must be synchronized.
    • Constructor Detail

      • AccumulateCsvResults

        AccumulateCsvResults​(java.util.concurrent.BlockingQueue<OrderedObject<T>> resultantBeansQueue,
                             java.util.concurrent.BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue,
                             java.util.SortedSet<java.lang.Long> expectedRecords,
                             java.util.concurrent.ConcurrentMap<java.lang.Long,​T> resultantBeanMap,
                             org.apache.commons.collections4.ListValuedMap<java.lang.Long,​CsvException> thrownExceptionsMap)
        The only accepted constructor for the accumulator.
        Parameters:
        resultantBeansQueue - A queue of beans coming out of the pool of threads creating them. The accumulator pulls from this queue.
        thrownExceptionsQueue - A queue of CsvException and its derivatives coming out of the pool of threads creating beans. The accumulator pulls from this queue.
        expectedRecords - A list of outstanding record numbers so gaps in ordering due to filtered input or exceptions while converting can be detected.
        resultantBeanMap - The (ordered) map of beans that have been created. The accumulator inserts into this map.
        thrownExceptionsMap - The map of suppressed exceptions thrown during bean creation. The accumulator inserts into this map. All access to this variable must be synchronized.
    • Method Detail

      • isMustStop

        private boolean isMustStop()
        Checks whether the accumulator should shut itself down. This method must always be used to check the value of the signal boolean, because it's synchronized.
        Returns:
        Whether the accumulator should stop
      • setMustStop

        void setMustStop​(boolean mustStop)
        Tells the accumulator whether it should stop. This method must always be used to set the value of the signal boolean, because it's synchronized.
        Parameters:
        mustStop - Whether the accumulator should stop
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread