Package com.opencsv.bean.concurrent
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:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public class BeanExecutor<T> extends java.util.concurrent.ThreadPoolExecutorA specific derivative ofIntolerantThreadPoolExecutorintended for submitting beans to be converted toStrings 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>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 BeanExecutor(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()voidsubmitBean(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
-
-
-
-
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
-
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 processedmappingStrategy- The mapping strategy to be usedbean- The bean to be transformed into a line of outputthrowExceptions- 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
-
-