Where an estimator's inputs come from.
BB.Estimator.Server doesn't receive inputs itself; it asks a source for
them. The default, BB.Estimator.Source.PubSub, subscribes to a path and
treats every %BB.Message{} published there as an input. A sensor whose
readings don't travel over BB.PubSub names another source with
BB.Sensor.estimator_source/0, and the estimators nested inside it use
that instead.
The server owns the pace. It calls request/1 once it is ready for an
input - after it has started, and again each time it has finished with what
the source last gave it - so a source that delivers by demand never hands an
estimator more than it has asked for. A source that can't be paced, such as
PubSub, makes request/1 a no-op.
The server requests again only for an input, a :spent event or a
{:failed, reason} event, so a source must tell the message that answers a
request from one that merely accompanies it. Requesting on a message that
arrives alongside an input - ahead of it in the mailbox - would leave a
second request outstanding by the time the input is dispatched, and the
estimator would be handed an input it hadn't yet asked for.
Summary
Types
What a message received by the estimator's process means to a source.
Whatever a source needs to recognise its own messages. Opaque to the server.
Callbacks
What message, received by the subscribing process, means for this source.
Ask for the next input.
Start delivering to the calling process the inputs at path on robot.
Types
@type event() :: {:input, BB.Message.t()} | :no_input | :spent | {:failed, reason :: term()} | {:ended, reason :: term()} | nil
What a message received by the estimator's process means to a source.
{:input, message}- an input, handed toBB.Estimator.handle_input/2. The server measuresmax_input_ageand latency from the envelope'smonotonic_time, so a source whose messages are built some time after the reading was taken should stamp the time the reading was taken there. It refuses a message whose envelope names anothernode, because monotonic clocks are node-local.:no_input- the source's own message, carrying no input and leaving the outstanding request where it was. The server does nothing with it.:spent- the source's own message, which answered the outstanding request without an input - a stream pausing, say. The server requests again.{:failed, reason}- the source's own message, which answered the outstanding request with the news that whatever produces its inputs has failed - a camera whose capture broke, say. Unlike:spent, nothing is expected to follow soon. The server transitions the estimator to:lostwith reason:source_failed, firingon_lost, and requests again, so inputs resuming recover it the way they would afterlost_after.{:ended, reason}- the source will deliver nothing more; its subscription is dead. The server transitions the estimator to:lostwith reason:source_endedand stops requesting, but doesn't stop itself. A source ends because its sensor has gone, andBB.SensorEstimatorSupervisorrestarts a sensor's estimators after the sensor, so each subscribes afresh to whatever the new sensor provides.nil- not this source's message.
@type state() :: term()
Whatever a source needs to recognise its own messages. Opaque to the server.
Callbacks
What message, received by the subscribing process, means for this source.
@callback request(state()) :: :ok
Ask for the next input.
@callback subscribe(robot :: module(), path :: [atom()], args :: keyword()) :: {:ok, state()} | {:error, term()}
Start delivering to the calling process the inputs at path on robot.
args are whatever the sensor returned alongside the source module from
BB.Sensor.estimator_source/0.