Class BeanExecutor<T>

  • Type Parameters:
    T - The type of the bean being converted
    All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    public class BeanExecutor<T>
    extends java.util.concurrent.ThreadPoolExecutor
    A specific derivative of IntolerantThreadPoolExecutor intended for submitting beans to be converted to Strings for writing.
    Since:
    5.0
    Author:
    Andrew Rucker Jones
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor

        java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.opencsv.bean.concurrent.AccumulateCsvResults<T> accumulateThread
      A separate thread that accumulates and orders results.
      protected java.util.concurrent.BlockingQueue<OrderedObject<T>> resultQueue
      A queue of the beans created.
      protected java.util.concurrent.BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue
      A queue of exceptions thrown by threads during processing.
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanExecutor​(boolean orderedResults)
      The only constructor available for this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterExecute​(java.lang.Runnable r, java.lang.Throwable t)
      Shuts the Executor down if the thread ended in an exception.
      void complete()
      Sends a signal to the Executor that it should shut down once all threads have completed.
      java.util.List<CsvException> getCapturedExceptions()
      Returns exceptions captured during the conversion process if the conversion process was set not to propagate these errors up the call stack.
      java.lang.Throwable getTerminalException()
      If an unrecoverable exception was thrown during processing, it can be retrieved here.
      void prepare()
      Prepares this Executor to receive jobs.
      java.util.stream.Stream<T> resultStream()
      Returns the results of conversion as a Stream.
      java.util.List<java.lang.Runnable> shutdownNow()  
      void submitBean​(long lineNumber, MappingStrategy<T> mappingStrategy, T bean, boolean throwExceptions)
      Submit one bean for conversion.
      • Methods inherited from class java.util.concurrent.ThreadPoolExecutor

        allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, terminated, toString
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
      • Methods inherited from class java.lang.Object

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

      • resultQueue

        protected final java.util.concurrent.BlockingQueue<OrderedObject<T>> resultQueue
        A queue of the beans created.
      • thrownExceptionsQueue

        protected final java.util.concurrent.BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue
        A queue of exceptions thrown by threads during processing.
      • accumulateThread

        protected com.opencsv.bean.concurrent.AccumulateCsvResults<T> accumulateThread
        A separate thread that accumulates and orders results.
    • Constructor Detail

      • BeanExecutor

        public BeanExecutor​(boolean orderedResults)
        The only constructor available for this class.
        Parameters:
        orderedResults - Whether order should be preserved in the results
    • Method Detail

      • submitBean

        public void submitBean​(long lineNumber,
                               MappingStrategy<T> mappingStrategy,
                               T bean,
                               boolean throwExceptions)
        Submit one bean for conversion.
        Parameters:
        lineNumber - Which record in the output file is being processed
        mappingStrategy - The mapping strategy to be used
        bean - The bean to be transformed into a line of output
        throwExceptions - Whether exceptions should be thrown or captured for later processing
      • prepare

        public void prepare()
        Prepares this Executor to receive jobs.
      • complete

        public void complete()
                      throws java.lang.InterruptedException
        Sends a signal to the Executor that it should shut down once all threads have completed.
        Throws:
        java.lang.InterruptedException - If the current thread is interrupted while waiting. Shouldn't be thrown, since the Executor waits indefinitely for all threads to end.
        java.util.concurrent.RejectedExecutionException - If an exception during processing forced this Executor to shut down.
      • resultStream

        public java.util.stream.Stream<T> resultStream()
        Returns the results of conversion as a Stream.
        Returns:
        A Stream of results
      • getCapturedExceptions

        public java.util.List<CsvException> getCapturedExceptions()
        Returns exceptions captured during the conversion process if the conversion process was set not to propagate these errors up the call stack. The call is nondestructive.
        Returns:
        All exceptions captured
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
        Overrides:
        shutdownNow in class java.util.concurrent.ThreadPoolExecutor
      • afterExecute

        protected void afterExecute​(java.lang.Runnable r,
                                    java.lang.Throwable t)
        Shuts the Executor down if the thread ended in an exception.
        Overrides:
        afterExecute in class java.util.concurrent.ThreadPoolExecutor
        Parameters:
        r -
        t -
      • getTerminalException

        public java.lang.Throwable getTerminalException()
        If an unrecoverable exception was thrown during processing, it can be retrieved here.
        Returns:
        The exception that halted one of the threads, which caused the executor to shut itself down