Top Description Fields Constructors Methods
com.opencsv.bean.concurrent

pack-priv Class AccumulateCsvResults<T>

extends Thread
Class Inheritance
Type Parameters
<T>
Type of output being created (bean or strings)
Imports
com.opencsv.bean.util.OrderedObject, com.opencsv.exceptions.CsvException, org.apache.commons.collections4.ListValuedMap, java.util.SortedSet, java.util.concurrent.BlockingQueue, .ConcurrentMap

The accumulator takes two queues of results of transforming text input into bean output or bean input into text output (output and exceptions) and orders them for later consumption. This task is delegated to a separate thread so threads can quickly queue their results in a (synchronized, thread-safe) queue and move on with other work, while the relatively expensive operation of ordering the results doesn't block other threads waiting for access to the ordered map.
Author
Andrew Rucker Jones
Since
4.0

Field Summary

Modifier and TypeField and Description
private final SortedSet<Long>
private boolean
private final ConcurrentMap<Long, T>
private final BlockingQueue<OrderedObject<T>>
private final ListValuedMap<Long, CsvException>
thrownExceptionsMap

All access to this variable must be synchronized.

private final BlockingQueue<OrderedObject<CsvException>>
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv
AccumulateCsvResults(BlockingQueue<OrderedObject<T>>
A queue of beans coming out of the pool of threads creating them. The accumulator pulls from this queue.
resultantBeansQueue
,
BlockingQueue<OrderedObject<CsvException>>
A queue of com.opencsv.exceptions.CsvException and its derivatives coming out of the pool of threads creating beans. The accumulator pulls from this queue.
thrownExceptionsQueue
,
SortedSet<Long>
A list of outstanding record numbers so gaps in ordering due to filtered input or exceptions while converting can be detected.
expectedRecords
,
ConcurrentMap<Long, T>
The (ordered) map of beans that have been created. The accumulator inserts into this map.
resultantBeanMap
,
ListValuedMap<Long, CsvException>
The map of suppressed exceptions thrown during bean creation. The accumulator inserts into this map. All access to this variable must be synchronized.
thrownExceptionsMap
)

The only accepted constructor for the accumulator.

Method Summary

Modifier and TypeMethod and Description
private synchronized boolean

Returns:

Whether the accumulator should stop
isMustStop
()

Checks whether the accumulator should shut itself down.

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.

pack-priv synchronized void
setMustStop(boolean
Whether the accumulator should stop
mustStop
)

Tells the accumulator whether it should stop.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopthreadIdtoStringyield

Field Detail

expectedRecordsback to summary
private final SortedSet<Long> expectedRecords
mustStopback to summary
private boolean mustStop
resultantBeanMapback to summary
private final ConcurrentMap<Long, T> resultantBeanMap
resultantBeansQueueback to summary
private final BlockingQueue<OrderedObject<T>> resultantBeansQueue
thrownExceptionsMapback to summary
private final ListValuedMap<Long, CsvException> thrownExceptionsMap

All access to this variable must be synchronized.

thrownExceptionsQueueback to summary
private final BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue

Constructor Detail

AccumulateCsvResultsback to summary
pack-priv AccumulateCsvResults(BlockingQueue<OrderedObject<T>> resultantBeansQueue, BlockingQueue<OrderedObject<CsvException>> thrownExceptionsQueue, SortedSet<Long> expectedRecords, ConcurrentMap<Long, T> resultantBeanMap, ListValuedMap<Long, CsvException> thrownExceptionsMap)

The only accepted constructor for the accumulator.

Parameters
resultantBeansQueue:BlockingQueue<OrderedObject<T>>

A queue of beans coming out of the pool of threads creating them. The accumulator pulls from this queue.

thrownExceptionsQueue:BlockingQueue<OrderedObject<CsvException>>

A queue of com.opencsv.exceptions.CsvException and its derivatives coming out of the pool of threads creating beans. The accumulator pulls from this queue.

expectedRecords:SortedSet<Long>

A list of outstanding record numbers so gaps in ordering due to filtered input or exceptions while converting can be detected.

resultantBeanMap:ConcurrentMap<Long, T>

The (ordered) map of beans that have been created. The accumulator inserts into this map.

thrownExceptionsMap:ListValuedMap<Long, CsvException>

The map of suppressed exceptions thrown during bean creation. The accumulator inserts into this map. All access to this variable must be synchronized.

Method Detail

isMustStopback to summary
private synchronized boolean isMustStop()

Checks whether the accumulator should shut itself down. This method must always be used to check the value of the signal boolean, because it's synchronized.

Returns:boolean

Whether the accumulator should stop

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override
setMustStopback to summary
pack-priv synchronized void setMustStop(boolean mustStop)

Tells the accumulator whether it should stop. This method must always be used to set the value of the signal boolean, because it's synchronized.

Parameters
mustStop:boolean

Whether the accumulator should stop