Package spoon.processing
Class AbstractParallelProcessor<E extends CtElement>
- java.lang.Object
-
- spoon.processing.AbstractProcessor<E>
-
- spoon.processing.AbstractParallelProcessor<E>
-
- All Implemented Interfaces:
FactoryAccessor
,Processor<E>
public abstract class AbstractParallelProcessor<E extends CtElement> extends AbstractProcessor<E>
AbstractParallelProcessor allows using multiple threads for concurrent processing withAbstractProcessor
. 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 aExecutors#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 Summary
Constructors Constructor Description AbstractParallelProcessor(Iterable<Processor<E>> processors)
Creates a new AbstractParallelProcessor from given iterable.AbstractParallelProcessor(Iterable<Processor<E>> processors, int numberOfProcessors)
Creates a new AbstractParallelProcessor from given iterable.AbstractParallelProcessor(Consumer<E> processFunction, int numberOfProcessors)
Creates a new AbstractParallelProcessor from given consumer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
process(E element)
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element.void
processingDone()
Cleans the threadpool after processing.-
Methods inherited from class spoon.processing.AbstractProcessor
addProcessedElementType, clearProcessedElementType, getEnvironment, getFactory, getProcessedElementTypes, getTraversalStrategy, init, initProperties, interrupt, isToBeProcessed, loadProperties, process, removeProcessedElementType, setFactory
-
-
-
-
Constructor Detail
-
AbstractParallelProcessor
public AbstractParallelProcessor(Iterable<Processor<E>> processors)
Creates a new AbstractParallelProcessor from given iterable. The iterable is fully consumed. Giving an endless iterable of processors will result in errors. The processors must follow the guidelines given in the class description.- Parameters:
processors
- iterable of processors.- Throws:
IllegalArgumentException
- if size of iterable is less than 1.
-
AbstractParallelProcessor
public AbstractParallelProcessor(Iterable<Processor<E>> processors, int numberOfProcessors)
Creates a new AbstractParallelProcessor from given iterable. The processors must follow the guidelines given in the class description.- Parameters:
processors
- iterable of processors.numberOfProcessors
- number consumed from the iterable added to the active processors.- Throws:
SpoonException
- if iterable has less values then numberOfProcessors.IllegalArgumentException
- if numberOfProcessors is less than 1.
-
AbstractParallelProcessor
public AbstractParallelProcessor(Consumer<E> processFunction, int numberOfProcessors)
Creates a new AbstractParallelProcessor from given consumer. The processors must follow the guidelines given in the class description.- Parameters:
processFunction
- Represents an operation that accepts a single element E and returns no result.numberOfProcessors
- number of concurrent running processors.- Throws:
IllegalArgumentException
- if numberOfProcessors is less than 1.
-
-
Method Detail
-
process
public final void process(E element)
Description copied from interface:Processor
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element. The way Spoon calls this method depends on the processed element types (Processor.getProcessedElementTypes()
), the traversal strategy (Processor.getTraversalStrategy()
), and the used processing manager (Environment.getManager()
. Also, this method is called only if the methodProcessor.isToBeProcessed(CtElement)
returns true for a given scanned element. In order to manually scan the meta-model, one can define theProcessor.process()
method instead.- Parameters:
element
- the element that is currently being scanned
-
processingDone
public void processingDone()
Cleans the threadpool after processing.- Specified by:
processingDone
in interfaceProcessor<E extends CtElement>
- Overrides:
processingDone
in classAbstractProcessor<E extends CtElement>
-
-