Class LineExecutor<T>
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
com.opencsv.bean.concurrent.LineExecutor<T>
- Type Parameters:
T- The type of the bean being converted to
- All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService, Spliterator<T>
A specific derivative of
IntolerantThreadPoolExecutor intended for
submitting lines of input to be converted to beans.- 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<T> 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<T>> 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
ConstructorsConstructorDescriptionLineExecutor(boolean orderedResults, Locale errorLocale, CompleteFileReader<T> completeFileReader) 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.voidsubmitLine(long lineNumber, MappingStrategy<? extends T> mapper, CsvToBeanFilter filter, List<BeanVerifier<T>> verifiers, String[] line, CsvExceptionHandler exceptionHandler) Submit one record for conversion to a bean.booleantryAdvance(Consumer<? super T> 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
-
LineExecutor
public LineExecutor(boolean orderedResults, Locale errorLocale, CompleteFileReader<T> completeFileReader) The only constructor available for this class.- Parameters:
orderedResults- Whether order should be preserved in the resultserrorLocale- The locale to use for error messagescompleteFileReader- The thread that reads lines of input and feeds the results to this Executor
-
-
Method Details
-
prepare
public void prepare()Prepares this Executor to receive jobs. -
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. -
submitLine
public void submitLine(long lineNumber, MappingStrategy<? extends T> mapper, CsvToBeanFilter filter, List<BeanVerifier<T>> verifiers, String[] line, CsvExceptionHandler exceptionHandler) Submit one record for conversion to a bean.- Parameters:
lineNumber- Which record in the input file is being processedmapper- The mapping strategy to be usedfilter- A filter to remove beans from the running, if necessary. May be null.verifiers- The list of verifiers to run on beans after creationline- The line of input to be transformed into a beanexceptionHandler- The handler for exceptions thrown during record processing
-
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
-
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>
-