Package com.opencsv.bean.concurrent
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:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public class LineExecutor<T> extends java.util.concurrent.ThreadPoolExecutorA specific derivative ofIntolerantThreadPoolExecutorintended 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 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>accumulateThreadA separate thread that accumulates and orders results.protected java.util.concurrent.BlockingQueue<OrderedObject<T>>resultQueueA queue of the beans created.protected java.util.concurrent.BlockingQueue<OrderedObject<CsvException>>thrownExceptionsQueueA queue of exceptions thrown by threads during processing.
-
Constructor Summary
Constructors Constructor Description LineExecutor(boolean orderedResults)The only constructor available for this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecute(java.lang.Runnable r, java.lang.Throwable t)Shuts the Executor down if the thread ended in an exception.voidcomplete()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.ThrowablegetTerminalException()If an unrecoverable exception was thrown during processing, it can be retrieved here.voidprepare()Prepares this Executor to receive jobs.java.util.stream.Stream<T>resultStream()Returns the results of conversion as aStream.java.util.List<java.lang.Runnable>shutdownNow()voidsubmitLine(long lineNumber, MappingStrategy<? extends T> mapper, CsvToBeanFilter filter, java.util.List<BeanVerifier<T>> verifiers, java.lang.String[] line, boolean throwExceptions)Submit one record for conversion to a bean.-
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
-
-
-
-
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.
-
-
Method Detail
-
submitLine
public void submitLine(long lineNumber, MappingStrategy<? extends T> mapper, CsvToBeanFilter filter, java.util.List<BeanVerifier<T>> verifiers, java.lang.String[] line, boolean throwExceptions)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 beanthrowExceptions- 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.InterruptedExceptionSends 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 aStream.- Returns:
- A
Streamof 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:
shutdownNowin interfacejava.util.concurrent.ExecutorService- Overrides:
shutdownNowin classjava.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:
afterExecutein classjava.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
-
-