Class BeanExecutor<T>
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
com.opencsv.bean.concurrent.BeanExecutor<T>
- Type Parameters:
T- The type of the bean being converted
- All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService, Spliterator<String[]>
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 ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicyNested classes/interfaces inherited from interface Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS, T_SPLITR> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.opencsv.bean.concurrent.AccumulateCsvResults<String[]> A separate thread that accumulates and orders results.protected final LocaleThe locale for error messages.A list of the ordinals of data records still to be expected by the accumulator.protected final BlockingQueue<com.opencsv.bean.util.OrderedObject<String[]>> A queue of the beans created.protected final BlockingQueue<com.opencsv.bean.util.OrderedObject<CsvException>> A queue of exceptions thrown by threads during processing.Fields inherited from interface Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsConstructorDescriptionBeanExecutor(boolean orderedResults, Locale errorLocale) The only constructor available for this class. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(Runnable r, Throwable t) Shuts the Executor down if the thread ended in an exception.intprotected voidChecks whether exceptions are available that should halt processing.voidcomplete()Sends a signal to the Executor that it should shut down once all threads have completed.longReturns exceptions captured during the conversion process if the conversion process was set not to propagate these errors up the call stack.If an unrecoverable exception was thrown during processing, it can be retrieved here.voidprepare()Prepares this Executor to receive jobs.voidsubmitBean(long lineNumber, MappingStrategy<T> mappingStrategy, T bean, CsvExceptionHandler exceptionHandler) Submit one bean for conversion.booleantryAdvance(Consumer<? super String[]> action) trySplit()Methods inherited from class 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, toStringMethods inherited from class AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ExecutorService
closeMethods inherited from interface Spliterator
forEachRemaining, getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
resultQueue
A queue of the beans created. -
thrownExceptionsQueue
protected final BlockingQueue<com.opencsv.bean.util.OrderedObject<CsvException>> thrownExceptionsQueueA queue of exceptions thrown by threads during processing. -
accumulateThread
A separate thread that accumulates and orders results. -
expectedRecords
-
errorLocale
The locale for error messages.
-
-
Constructor Details
-
BeanExecutor
The only constructor available for this class.- Parameters:
orderedResults- Whether order should be preserved in the resultserrorLocale- 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 processedmappingStrategy- The mapping strategy to be usedbean- The bean to be transformed into a line of outputexceptionHandler- The handler for exceptions thrown during record processing
-
prepare
public void prepare()Prepares this Executor to receive jobs. -
complete
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
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
- Specified by:
shutdownNowin interfaceExecutorService- Overrides:
shutdownNowin classThreadPoolExecutor
-
afterExecute
Shuts the Executor down if the thread ended in an exception.- Overrides:
afterExecutein classThreadPoolExecutor- Parameters:
r-t-
-
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
- Specified by:
tryAdvancein interfaceSpliterator<T>
-
trySplit
- Specified by:
trySplitin interfaceSpliterator<T>
-
estimateSize
public long estimateSize()- Specified by:
estimateSizein interfaceSpliterator<T>
-
characteristics
public int characteristics()- Specified by:
characteristicsin interfaceSpliterator<T>
-