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() {
  _group.add(_controller.stream);

  // Get or create the trigger executor and initialize with this task control executor
  _triggerExecutor = ExecutorFactory().getTriggerExecutor(
    studyDeploymentId,
    taskControl.triggerId,
  );
  if (_triggerExecutor == null) {
    _triggerExecutor = ExecutorFactory().createTriggerExecutor(
      studyDeploymentId,
      taskControl.triggerId,
      trigger,
    );

    _triggerExecutor?.initialize(trigger, deployment);
  }

  // now start listening on the trigger and trigger events
  _triggerExecutor?.triggerEvents.listen((_) => onTrigger());
  // get the task executor and add the measurements it collects to the stream group
  _taskExecutor = ExecutorFactory().getTaskExecutor(studyDeploymentId, task);
  if (_taskExecutor == null) {
    warning(
      "$runtimeType - Cannot find a TaskExecutor for task type '${task.runtimeType}'.",
    );
    return false;
  }
  _taskExecutor?.initialize(task, deployment);
  _group.add(_taskExecutor!.measurements);

  return true;
}