Class ConcurrentCharLoader
- java.lang.Object
-
- com.univocity.parsers.common.input.concurrent.ConcurrentCharLoader
-
- All Implemented Interfaces:
java.lang.Runnable
class ConcurrentCharLoader extends java.lang.Object implements java.lang.RunnableA concurrent character loader for loading a pool ofCharBucketinstances using aReaderin a separate thread- See Also:
ConcurrentCharInputReader,CharBucket,Entry
-
-
Field Summary
Fields Modifier and Type Field Description private booleanactiveprivate java.lang.ThreadactiveExecutionprivate java.util.concurrent.ArrayBlockingQueue<java.lang.Object>bucketsprivate booleancloseOnStopprivate Entry<CharBucket>currentBucketprivate CharBucketendprivate java.lang.Exceptionerrorprivate booleanfinishedprivate FixedInstancePool<CharBucket>instances(package private) java.io.Readerreader
-
Constructor Summary
Constructors Constructor Description ConcurrentCharLoader(java.io.Reader reader, int bucketSize, int bucketQuantity, boolean closeOnStop)Creates aFixedInstancePoolwith a given amount ofCharBucketinstances and starts a thread to fill each one.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharBucketnextBucket()Returns the next available bucket.private intreadBucket()(package private) voidreportError()voidrun()TheCharBucketloading process that executes in parallel until the input is completely read.private voidsetError(java.lang.Exception e)voidstopReading()Stops theCharBucketloading process and closes the reader provided in the constructor of this class
-
-
-
Field Detail
-
buckets
private final java.util.concurrent.ArrayBlockingQueue<java.lang.Object> buckets
-
end
private final CharBucket end
-
instances
private final FixedInstancePool<CharBucket> instances
-
currentBucket
private Entry<CharBucket> currentBucket
-
finished
private boolean finished
-
active
private boolean active
-
reader
java.io.Reader reader
-
activeExecution
private java.lang.Thread activeExecution
-
error
private java.lang.Exception error
-
closeOnStop
private final boolean closeOnStop
-
-
Constructor Detail
-
ConcurrentCharLoader
public ConcurrentCharLoader(java.io.Reader reader, int bucketSize, int bucketQuantity, boolean closeOnStop)Creates aFixedInstancePoolwith a given amount ofCharBucketinstances and starts a thread to fill each one.- Parameters:
reader- The source of characters to extract and fillCharBucketinstancesbucketSize- The size of each individualCharBucketbucketQuantity- The number ofCharBucketinstances used to extract characters from the given reader.closeOnStop- Indicates whether to automatically close the input whenstopReading()is called
-
-
Method Detail
-
readBucket
private int readBucket() throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
run
public void run()
TheCharBucketloading process that executes in parallel until the input is completely read. Once the end of the input is reached, theReaderinstance provided in the constructor is closed.- Specified by:
runin interfacejava.lang.Runnable
-
setError
private void setError(java.lang.Exception e)
-
nextBucket
public CharBucket nextBucket()
Returns the next available bucket. Blocks until a bucket is made available or the reading process stops.- Returns:
- the next available bucket.
-
stopReading
public void stopReading()
Stops theCharBucketloading process and closes the reader provided in the constructor of this class
-
reportError
void reportError()
-
-