onInitialize method

  1. @override
bool onInitialize()
override

Called by initialize. Returns true if successfully initialized.

If false, the executor stays in ExecutorState.Created. This is a synchronous method and must be light-weight.

Implementation

@override
bool onInitialize() {
  if (task.measures != null) {
    for (Measure measure in task.measures!) {
      // create a new probe for each measure - this ensures that we can have
      // multiple measures of the same type, each using its own probe instance
      Probe? probe = SamplingPackageRegistry().create(measure.type);
      if (probe != null) {
        addExecutor(probe);
        _statesGroup.add(probe.stateEvents);

        probe.initialize(measure, deployment!);
      } else {
        warning(
          "A probe for measure type '${measure.type}' could not be created. "
          'This may be because this probe is not available on the operating system '
          'of this phone (primary device) or on the connected device. '
          'Or it may be because the sampling package containing this probe has not '
          'been registered in the SamplingPackageRegistry.',
        );
      }
    }
  }
  return true;
}