Class BeanExecutor<T>

Type Parameters:
T - The type of the bean being converted
All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService, Spliterator<String[]>

public class BeanExecutor<T> extends ThreadPoolExecutor
A specific derivative of IntolerantThreadPoolExecutor intended for submitting beans to be converted to Strings for writing.
Since:
5.0
Author:
Andrew Rucker Jones
  • Field Details

    • resultQueue

      protected final BlockingQueue<com.opencsv.bean.util.OrderedObject<String[]>> resultQueue
      A queue of the beans created.
    • thrownExceptionsQueue

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

      protected com.opencsv.bean.concurrent.AccumulateCsvResults<String[]> accumulateThread
      A separate thread that accumulates and orders results.
    • expectedRecords

      protected final SortedSet<Long> expectedRecords
      A list of the ordinals of data records still to be expected by the accumulator.
    • errorLocale

      protected final Locale errorLocale
      The locale for error messages.
  • Constructor Details

    • BeanExecutor

      public BeanExecutor(boolean orderedResults, Locale errorLocale)
      The only constructor available for this class.
      Parameters:
      orderedResults - Whether order should be preserved in the results
      errorLocale - The locale to use for error messages
  • Method Details

    • submitBean

      public void submitBean(long lineNumber, MappingStrategy<T> mappingStrategy, T bean, CsvExceptionHandler exceptionHandler)
      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
      exceptionHandler - The handler for exceptions thrown during record processing
    • prepare

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

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

      public 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 List<Runnable> shutdownNow()
      Specified by:
      shutdownNow in interface ExecutorService
      Overrides:
      shutdownNow in class ThreadPoolExecutor
    • afterExecute

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

      public 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
    • checkExceptions

      protected void checkExceptions()
      Checks whether exceptions are available that should halt processing. This is the case with unrecoverable errors, such as parsing the input, or if exceptions in conversion should be thrown by request of the user.
    • tryAdvance

      public boolean tryAdvance(Consumer<? super String[]> action)
      Specified by:
      tryAdvance in interface Spliterator<T>
    • trySplit

      public Spliterator<String[]> trySplit()
      Specified by:
      trySplit in interface Spliterator<T>
    • estimateSize

      public long estimateSize()
      Specified by:
      estimateSize in interface Spliterator<T>
    • characteristics

      public int characteristics()
      Specified by:
      characteristics in interface Spliterator<T>