onInitialize method

  1. @override
bool onInitialize()
override

Callback when this executor is initialized. Returns true if successfully initialized, false otherwise.

Note that this is a non-async method and should hence be 'light-weight' and not block execution for a long duration.

Implementation

@override
bool onInitialize() {
  if (configuration == null) {
    warning(
        'Trying to initialize StudyDeploymentExecutor but the deployment configuration is null. Cannot initialize study deployment.');
    return false;
  }

  group.add(_manualMeasurementController.stream);

  for (var taskControl in configuration!.taskControls) {
    // get the trigger and task based on the trigger id and task name
    final trigger = configuration!.triggers['${taskControl.triggerId}']!;
    final task = configuration!.getTaskByName(taskControl.taskName)!;

    final executor = ExecutorFactory().getTaskControlExecutor(
      taskControl,
      trigger,
      task,
    );

    executor.initialize(taskControl, deployment!);

    // let the device manger know about this executor
    if (taskControl.destinationDeviceRoleName != null) {
      DeviceConfiguration? targetDevice = configuration
          ?.getDeviceFromRoleName(taskControl.destinationDeviceRoleName!);
      if (targetDevice != null) {
        DeviceController()
            .getDevice(targetDevice.type)
            ?.executors
            .add(executor);
      }
    }

    group.add(executor.measurements);
    executors.add(executor);
  }
  return true;
}