Adding a Custom Evaluation Task Manager

Follow these steps to define your own implementation of the IEvaluationTaskManager interface:

1. Create the Spring Bean

Create a class that implements the IEvaluationTaskManager interface. You will need to implement the following methods:

public interface IEvaluationTaskManager {

  /**
   * Create appropriate {@link java.util.concurrent.Future} given a {@code limitStructure}
   *
   * @param limitStructure the {@link LimitStructure} to evaluate.
   * @param evaluationService the {@link IEvaluationService} to evaluate the limit structure
   */
  void addChronFutureJob(LimitStructure limitStructure, IEvaluationService evaluationService);

  /**
   * Cancel ScheduledFuture for given KpiTaskKey and remove from futureAlertTasks HashMap.
   *
   * @param futureKey KpiTaskKey.
   */
  boolean removeChronFutureJob(String futureKey);

  /**
   * Checks if {@link ScheduledFuture } has been created for given kpiKey
   *
   * @param futureKey key
   * @return true if it exists, false otherwise.
   */
  boolean containsChronFutureJob(String futureKey);

  /**
   * Wait for the futures for the running {@code limitEvaluationTasks} to complete
   *
   * @param limitEvaluationTasks - the limit tasks to wait for
   */
  void waitForLimitTasks(Collection<LimitEvaluationTask> limitEvaluationTasks);

  /**
   * Wait for the futures for the running {@code structureTasks} to complete
   *
   * @param structureTasks - the structure tasks to wait for
   */
  void waitForLimitStructureTasks(Collection<LimitStructureEvaluationTask> structureTasks);

  /**
   * Add the future for a limit task to the manager
   *
   * @param limitTaskKey - the key of the limit task
   * @param future - the submitted future of the limit task
   */
  void addLimitTask(String limitTaskKey, Future future);

  /**
   * Add the future for a structure task to the manager
   *
   * @param structureTaskKey - the key of the structure task
   * @param future - the submitted future of the structure task
   */
  void addLimitStructureTask(String structureTaskKey, Future future);
}

The waitFor*Tasks methods are responsible for blocking the current thread until all running tasks have completed. The other methods are used to add/remove futures being managed by the IEvaluationTaskManager.

2. Import the Spring Bean

Once the bean is created, import it into the project. See Importing Spring Beans into the Project on how to do this. Once done, Spring injects it in all classes that use IEvaluationService.