Probe
Collects data for one Measure.
The data comes from a sensor, a connected device or a service. A probe is the leaf of the executor tree. Each measure in a task gets its own probe, created by the measure type's SamplingPackage through SamplingPackageRegistry.create. Write a probe when you add a new measure type to a sampling package; most extend one of the specialized probes below.
Key points:
- Lifecycle: see Executor. Subclasses implement onInitialize, onResume and onPause; the default ones do nothing.
- Emits Measurements with addMeasurement; errors with addError.
- Its samplingConfiguration is looked up in the measure, the deployment and the sampling packages, in that order.
- permissions come from the CamsDataTypeMetaData of the measure type. The SmartphoneStudyController asks for them up front; probes only check them with hasRequiredPermissions.
Specialized probes: MeasurementProbe (one measurement), IntervalProbe (polling), StreamProbe (continuous stream), PeriodicStreamProbe, BufferingPeriodicProbe, BufferingIntervalStreamProbe and BufferingPeriodicStreamProbe.
- Inheritance
-
- Object
- AbstractExecutor<
Measure> - Probe
- Implementers
Constructors
Probe
Properties
deviceManager
The device manager of the device this probe collects data from.
Set by SamplingPackageRegistry.create.
enabled
Whether this probe is enabled.
Not used by the CAMS runtime itself.
measure
The Measure that configures this probe.
permissions
The permissions this probe needs. Empty if none.
Taken from the CamsDataTypeMetaData of its data type.
samplingConfiguration
The sampling configuration for this probe.
Configuration is obtained in the following order:
- from the Measure.overrideSamplingConfiguration
- from the DeviceConfiguration.defaultSamplingConfiguration of the deployment
- from the DeviceConfiguration.dataTypeSamplingSchemes of the static device configuration
- from the SamplingPackage.samplingSchemes of the sampling packages
Returns null in case no configuration is found.
See also the section on Sampling schemes and configurations in the CARP Core Framework. In addition to CARP Core, CARP Mobile Sensing also supports sampling schemes in the sampling packages, which are used as the 4th possible configuration in the list above.
type
The data type this probe collects, e.g. dk.cachet.carp.steps.
Methods
addMeasurement
- Measurement measurement
Adds measurement to measurements.
If the samplingConfiguration is a PersistentSamplingConfiguration, also sets its lastTime to now and saves the deployment, at most once per second.
arePermissionsGranted
Whether all permissions are granted. Returns false if checking fails.
hasRequiredPermissions
Whether this probe is allowed to run.
The SmartphoneStudyController asks for all deployment permissions up front (SmartphoneStudyController.askForAllPermissions), so probes only check. Always true on iOS: permission_handler reports Android-only groups (e.g. activityRecognition, phone) as denied there, and iOS prompts on first use.
onInitialize
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.
onPause
Called by pause. Returns true if successfully paused.
If false, the state is not changed.
onResume
Called by resume. Returns true if successfully resumed.
If false, the executor moves to ExecutorState.PausedButShouldBeResumed.
requestPermissions
Asks the user for any permissions not yet granted.
Goes through SmartPhoneClientManager.requestPermissions. Returns true if all permissions are granted afterwards.