Top Description Inners Fields Constructors Methods
com.univocity.parsers.common.processor.core

public abstract Class AbstractConcurrentProcessor<T extends Context>

extends Object
implements Processor<T extends Context>
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.processor.core.Processor
Known Direct Subclasses
com.univocity.parsers.common.processor.ConcurrentRowProcessor
Imports
com.univocity.parsers.common.*, java.util.concurrent.*

A Processor implementation to perform row processing tasks in parallel. The ConcurrentRowProcessor wraps another Processor, and collects rows read from the input. The actual row processing is performed in by wrapped Processor in a separate thread

Note

by default the Context object passed on to the wrapped Processor will not reflect the state of the parser at the time the row as generated, but the current state of the parser instead. You can enable the contextCopyingEnabled flag to generate copies of the Context at the time each row was generated.

Author
Univocity Software Pty Ltd - [email protected]
See Also
AbstractParser, Processor

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private T
private boolean
private final ExecutorService
private volatile long
private AbstractConcurrentProcessor.Node<T>
private final int
private final Object
private volatile long
private volatile AbstractConcurrentProcessor.Node<T>
private Future<Void>
private final Processor<T extends Context>
private volatile long

Constructor Summary

AccessConstructor and Description
public
AbstractConcurrentProcessor(Processor<T>
a regular Processor implementation which will be executed in a separate thread.
processor
)

Creates a non-blocking AbstractConcurrentProcessor, to perform processing of rows parsed from the input in a separate thread.

public
AbstractConcurrentProcessor(Processor<T>
a regular Processor implementation which will be executed in a separate thread.
processor
,
int
the limit of rows to be kept in memory before blocking the input parsing process.
limit
)

Creates a blocking ConcurrentProcessor, to perform processing of rows parsed from the input in a separate thread.

Method Summary

Modifier and TypeMethod and Description
protected abstract T
copyContext(T context)

protected final long
private T
grabContext(T context)

public boolean

Returns:

a flag indicating whether the parsing context must be persisted along with the parsed row so its methods reflect the state of the parser at the time the record was produced.
isContextCopyingEnabled
()

Indicates whether this processor should persist the Context object that is sent to the wrapped Processor given in the constructor of this class, so all methods of Context reflect the parser state at the time each row was parsed.

public final void
processEnded(T
A contextual object with information and controls over the state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.processEnded.

This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
public final void
processStarted(T
A contextual object with information and controls over the current state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.processStarted.

This method will by invoked by the parser once, when it is ready to start processing the input.
public final void
rowProcessed(String[]
the data extracted by the parser for an individual record. Note that:
row
,
T
A contextual object with information and controls over the current state of the parsing process
context
)

Implements com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed.
public void
setContextCopyingEnabled(boolean
a flag indicating whether the parsing context must be persisted along with the parsed row so its methods reflect the state of the parser at the time the record was produced.
contextCopyingEnabled
)

Configures this processor to persist the Context object that is sent to the wrapped Processor given in the constructor of this class, so all methods of Context reflect the parser state at the time each row was parsed.

private void
protected abstract T
wrapContext(T context)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextCopyingEnabledback to summary
private boolean contextCopyingEnabled
currentContextback to summary
private T currentContext
endedback to summary
private boolean ended
executorback to summary
private final ExecutorService executor
inputback to summary
private volatile long input
inputQueueback to summary
private AbstractConcurrentProcessor.Node<T> inputQueue
limitback to summary
private final int limit
lockback to summary
private final Object lock
outputback to summary
private volatile long output
outputQueueback to summary
private volatile AbstractConcurrentProcessor.Node<T> outputQueue
processback to summary
private Future<Void> process
processorback to summary
private final Processor<T extends Context> processor
rowCountback to summary
private volatile long rowCount

Constructor Detail

AbstractConcurrentProcessorback to summary
public AbstractConcurrentProcessor(Processor<T> processor)

Creates a non-blocking AbstractConcurrentProcessor, to perform processing of rows parsed from the input in a separate thread.

Parameters
processor:Processor<T>

a regular Processor implementation which will be executed in a separate thread.

AbstractConcurrentProcessorback to summary
public AbstractConcurrentProcessor(Processor<T> processor, int limit)

Creates a blocking ConcurrentProcessor, to perform processing of rows parsed from the input in a separate thread.

Parameters
processor:Processor<T>

a regular Processor implementation which will be executed in a separate thread.

limit:int

the limit of rows to be kept in memory before blocking the input parsing process.

Method Detail

copyContextback to summary
protected abstract T copyContext(T context)
getRowCountback to summary
protected final long getRowCount()
grabContextback to summary
private T grabContext(T context)
isContextCopyingEnabledback to summary
public boolean isContextCopyingEnabled()

Indicates whether this processor should persist the Context object that is sent to the wrapped Processor given in the constructor of this class, so all methods of Context reflect the parser state at the time each row was parsed. Defaults to false

Returns:boolean

a flag indicating whether the parsing context must be persisted along with the parsed row so its methods reflect the state of the parser at the time the record was produced.

processEndedback to summary
public final void processEnded(T context)

Implements com.univocity.parsers.common.processor.core.Processor.processEnded.

Doc from com.univocity.parsers.common.processor.core.Processor.processEnded.

This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.

It will always be called by the parser: in case of errors, if the end of the input us reached, or if the user stopped the process manually using ParsingContext#stop().

Parameters
context:T

A contextual object with information and controls over the state of the parsing process

Annotations
@Override
processStartedback to summary
public final void processStarted(T context)

Implements com.univocity.parsers.common.processor.core.Processor.processStarted.

Doc from com.univocity.parsers.common.processor.core.Processor.processStarted.

This method will by invoked by the parser once, when it is ready to start processing the input.

Parameters
context:T

A contextual object with information and controls over the current state of the parsing process

Annotations
@Override
rowProcessedback to summary
public final void rowProcessed(String[] row, T context)

Implements com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Doc from com.univocity.parsers.common.processor.core.Processor.rowProcessed.

Invoked by the parser after all values of a valid record have been processed.

Parameters
row:String[]

the data extracted by the parser for an individual record. Note that:

context:T

A contextual object with information and controls over the current state of the parsing process

Annotations
@Override
setContextCopyingEnabledback to summary
public void setContextCopyingEnabled(boolean contextCopyingEnabled)

Configures this processor to persist the Context object that is sent to the wrapped Processor given in the constructor of this class, so all methods of Context reflect the parser state at the time each row was parsed. Defaults to false

Parameters
contextCopyingEnabled:boolean

a flag indicating whether the parsing context must be persisted along with the parsed row so its methods reflect the state of the parser at the time the record was produced.

startProcessback to summary
private void startProcess()
wrapContextback to summary
protected abstract T wrapContext(T context)
com.univocity.parsers.common.processor.core back to summary

private Class AbstractConcurrentProcessor.Node<T>

extends Object
Class Inheritance
  • java.lang.Object
  • com.univocity.parsers.common.processor.core.AbstractConcurrentProcessor.Node

Field Summary

Modifier and TypeField and Description
public final T
public AbstractConcurrentProcessor.Node<T>
public final String[]

Constructor Summary

AccessConstructor and Description
public
Node(String[] row, T context)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
public final T context
nextback to summary
public AbstractConcurrentProcessor.Node<T> next
rowback to summary
public final String[] row

Constructor Detail

Nodeback to summary
public Node(String[] row, T context)