Jido.Sensor.Runtime (Jido v2.0.0-rc.1)

View Source

GenServer runtime for Jido sensors.

Runtime wraps sensor modules and manages their lifecycle, similar to how AgentServer wraps agent modules. It handles configuration validation, event scheduling, and signal delivery.

Architecture

  • Single GenServer per sensor instance
  • Configuration validated via sensor module's schema() (Zoi.parse)
  • Timer-based event scheduling via {:schedule, interval_ms} directives
  • Signal delivery to agent via pid or Jido.Signal.Dispatch

Public API

Options

  • :sensor - Sensor module (required)
  • :config - Configuration map or keyword list for the sensor
  • :context - Context map including :agent_ref
  • :id - Instance ID (auto-generated if not provided)

Signal Delivery

When the sensor emits a signal:

Examples

{:ok, pid} = Jido.Sensor.Runtime.start_link(
  sensor: MySensor,
  config: %{interval: 1000},
  context: %{agent_ref: self()}
)

# Inject an external event
Jido.Sensor.Runtime.event(pid, :custom_event)

Summary

Functions

Returns a child_spec for supervision.

Injects an external event into the sensor.

Starts a Sensor.Runtime linked to the calling process.

Types

server()

@type server() :: pid() | atom() | {:via, module(), term()}

Functions

child_spec(init_arg)

@spec child_spec(keyword() | map()) :: Supervisor.child_spec()

Returns a child_spec for supervision.

Uses the :id option if provided, otherwise defaults to the module name.

event(server, event)

@spec event(server(), term()) :: :ok

Injects an external event into the sensor.

The event will be passed to the sensor's handle_event/2 callback.

Examples

:ok = Jido.Sensor.Runtime.event(pid, :my_event)
:ok = Jido.Sensor.Runtime.event(pid, {:data_received, payload})

start_link(opts)

@spec start_link(keyword() | map()) :: GenServer.on_start()

Starts a Sensor.Runtime linked to the calling process.

Options

  • :sensor - Sensor module (required)
  • :config - Configuration map or keyword list for the sensor (default: %{})
  • :context - Context map including :agent_ref (default: %{})
  • :id - Instance ID (auto-generated if not provided)

Examples

{:ok, pid} = Jido.Sensor.Runtime.start_link(
  sensor: MySensor,
  config: %{interval: 5000},
  context: %{agent_ref: agent_pid}
)