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 (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;
}