public abstract class AbstractParallelProcessor<E extends CtElement> extends AbstractProcessor<E>
AbstractProcessor
.
This class should only be used if all processors do the same.
Otherwise the result may vary from the expected result. All processors
must synchronize shared fields like Collections by themselves. Multiple
constructors exist for different approaches creating this. You can create
this processor with either a Iterable of processors or a Consumer.
For creating and managing threads a Executors#newFixedThreadPool()
is
used. Creating more threads then cores can harm the performance. Using a
different thread pool could increase the performance, but this class should
be general usage. If you need better performance you may want to use an own
class with different parallel approach.Constructor and Description |
---|
AbstractParallelProcessor(java.util.function.Consumer<E> processFunction,
int numberOfProcessors)
Creates a new AbstractParallelProcessor from given consumer.
|
AbstractParallelProcessor(java.lang.Iterable<Processor<E>> processors)
Creates a new AbstractParallelProcessor from given iterable.
|
AbstractParallelProcessor(java.lang.Iterable<Processor<E>> processors,
int numberOfProcessors)
Creates a new AbstractParallelProcessor from given iterable.
|
Modifier and Type | Method and Description |
---|---|
void |
process(E element)
A callback method upcalled by the meta-model scanner to perform a
dedicated job on the currently scanned element.
|
void |
processingDone()
Cleans the threadpool after processing.
|
addProcessedElementType, clearProcessedElementType, getEnvironment, getFactory, getProcessedElementTypes, getTraversalStrategy, init, initProperties, interrupt, isToBeProcessed, loadProperties, process, removeProcessedElementType, setFactory
public AbstractParallelProcessor(java.lang.Iterable<Processor<E>> processors)
processors
- iterable of processors.java.lang.IllegalArgumentException
- if size of iterable is less than 1.public AbstractParallelProcessor(java.lang.Iterable<Processor<E>> processors, int numberOfProcessors)
processors
- iterable of processors.numberOfProcessors
- number consumed from the iterable added to the
active processors.SpoonException
- if iterable has less values then
numberOfProcessors.java.lang.IllegalArgumentException
- if numberOfProcessors is less than 1.public AbstractParallelProcessor(java.util.function.Consumer<E> processFunction, int numberOfProcessors)
processFunction
- Represents an operation that accepts a single
element E and returns no result.numberOfProcessors
- number of concurrent running processors.java.lang.IllegalArgumentException
- if numberOfProcessors is less than 1.public final void process(E element)
Processor
Processor.getProcessedElementTypes()
), the traversal strategy (
Processor.getTraversalStrategy()
), and the used processing manager (
Environment.getManager()
. Also, this method is upcalled only if
the method Processor.isToBeProcessed(CtElement)
returns true for a given
scanned element. In order to manually scan the meta-model, one can define
the Processor.process()
method instead.element
- the element that is currently being scannedpublic void processingDone()
processingDone
in interface Processor<E extends CtElement>
processingDone
in class AbstractProcessor<E extends CtElement>
Copyright © 2007–2021 Inria. All rights reserved.