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 with 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 Details

    • 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 Details