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.Runnable
A concurrent character loader for loading a pool ofCharBucket
instances using aReader
in a separate thread- See Also:
ConcurrentCharInputReader
,CharBucket
,Entry
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
active
private java.lang.Thread
activeExecution
private java.util.concurrent.ArrayBlockingQueue<java.lang.Object>
buckets
private boolean
closeOnStop
private Entry<CharBucket>
currentBucket
private CharBucket
end
private java.lang.Exception
error
private boolean
finished
private FixedInstancePool<CharBucket>
instances
(package private) java.io.Reader
reader
-
Constructor Summary
Constructors Constructor Description ConcurrentCharLoader(java.io.Reader reader, int bucketSize, int bucketQuantity, boolean closeOnStop)
Creates aFixedInstancePool
with a given amount ofCharBucket
instances and starts a thread to fill each one.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharBucket
nextBucket()
Returns the next available bucket.private int
readBucket()
(package private) void
reportError()
void
run()
TheCharBucket
loading process that executes in parallel until the input is completely read.private void
setError(java.lang.Exception e)
void
stopReading()
Stops theCharBucket
loading 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 aFixedInstancePool
with a given amount ofCharBucket
instances and starts a thread to fill each one.- Parameters:
reader
- The source of characters to extract and fillCharBucket
instancesbucketSize
- The size of each individualCharBucket
bucketQuantity
- The number ofCharBucket
instances 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.IOException
java.lang.InterruptedException
-
run
public void run()
TheCharBucket
loading process that executes in parallel until the input is completely read. Once the end of the input is reached, theReader
instance provided in the constructor is closed.- Specified by:
run
in 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 theCharBucket
loading process and closes the reader provided in the constructor of this class
-
reportError
void reportError()
-
-