Implementing Java Worker Tasks

Java worker tasks encapsulate java processing libraries.

Two such libraries and workers are predefined:

  • The 'engine worker' (in workers/engine-worker) and its 'engine' library (in processing/engine).

  • The 'model checker' worker (in workers/checker) and its 'model checker' library (in processing/checker).

It is possible to generate additional workers, as described in Part Getting Started.

By default, Java processing libraries rely on the Data Object Model to handle their input and output. For more details, please refer to Chapter Understanding the Data Object Model (DOM).

Java Processing

Each generated worker contains a <workerName>Task class which is where the actual processing code is called in the worker context. The pattern is to call the processing library code with a collector as argument and retrieve the modified collector as a return value of the execution.

The extract below shows how this is happening:

public class EngineTask implements Task {
  ...
  private OptimizationEngine optimizationEngine;

  @Override
  public void execute(Parameter input, Parameter output, ExecutionContext executionContext) {
    // retrieve collector built from scenario data
    CapacityPlanning inputColl = extractInputCollector(input);

    // execute engine (from library code) and retrieve a modified collector as output
    CapacityPlanning outputColl = optimizationEngine.execute(inputColl, executionContext);

    // if this list is empty, the whole output collector will be saved in the scenario
    // If you add classes in this list, only those classes will be saved
    List<Class<? extends DbDomObject>> consideredClasses= new ArrayList();

    // synchronize collector results with the original scenario data
    emitOutputCollector(outputColl, output, consideredClasses);
  }