Skip to content

DataManager

Stores or uploads the Measurements collected in a study deployment.

A data manager listens to the measurement stream of one deployment and saves each measurement, e.g. to a file, a database, or a server. Which one is used is set by the protocol's DataEndPoint: the SmartphoneStudyController asks the DataManagerRegistry for a data manager of DataEndPoint.type and calls configure with the deployment's measurements.

Key points:

  • One instance per deployment. Several deployments can run at the same time, so implementations must not share resources like the same file or network socket.
  • onMeasurement is called for each measurement; onError and onDone for errors and the end of the stream.
  • Call close to flush buffered data. The data manager cannot be used after that.

See also AbstractDataManager to extend, the built-in SQLiteDataManager, FileDataManager, and ConsoleDataManager, and DataManagerFactory to register your own.

Implementers

Constructors

DataManager

DataManager()

Properties

deployment

PrimaryDeviceDeployment get deployment

The deployment using this data manager.

events

Stream<DataManagerEvent> get events

Stream of data manager events, see DataManagerEventTypes.

studyDeploymentId

String get studyDeploymentId

The ID of the study deployment that this manager is handling.

type

String get type

The type of this data manager as enumerated in DataEndPointTypes.

Methods

close

Future<void> close()

Flushes any buffered data and closes this data manager.

After calling close the data manager can no longer be used.

configure

Future<void> configure({
  1. required DataEndPoint dataEndPoint,
  2. required SmartphoneDeployment deployment,
  3. required Stream<Measurement> measurements,
})

Configures the data manager with the study deployment, the dataEndPoint, and the stream of measurements to handle.

Call this before any data is handled.

onDone

Future<void> onDone()

When the data stream closes, the onDone handler is called.

onError

Future<void> onError(
  1. Object error
)

When an error event is sent on the stream, the onError handler is called.

onMeasurement

Future<void> onMeasurement(
  1. Measurement measurement
)

On each measurement collected, the onMeasurement handler is called.

Implementations of this interface should handle how to save or upload the measurement.