Espex.Supervisor (espex v0.1.1)

Copy Markdown View Source

Top-level supervisor for an Espex server instance.

Starts children in :rest_for_one order:

  1. Registry (duplicate keys) — fan-out point for Espex.push_state/2.
  2. A cross-connection state server (internal) — holds the device config and adapter modules.
  3. ThousandIsland — TCP acceptor pool that spawns a per-client connection handler process (internal).
  4. An mDNS advertiser GenServer (internal) — optional, started only when :mdns is configured.

If the server child crashes, the listener and advertiser restart too, so live connections drop rather than hold stale references.

Configuration is passed as keyword options:

Espex.Supervisor.start_link(
  device_config: [name: "my-device"],   # or a %DeviceConfig{}
  port: 6053,                           # overrides device_config.port
  name: :my_espex,                      # supervisor registered name
  server_name: MyApp.EspexServer,       # Espex.Server registered name
  num_acceptors: 10,
  serial_proxy: MyApp.MySerialAdapter,
  zwave_proxy: MyApp.MyZWaveAdapter,
  infrared_proxy: MyApp.MyIRAdapter,
  entity_provider: MyApp.MyEntities,
  mdns: Espex.Mdns.MdnsLite
)

Any adapter key omitted disables that feature. Pass :mdns with an Espex.Mdns adapter module (e.g. Espex.Mdns.MdnsLite) to advertise the server over mDNS; omit to skip.

Summary

Functions

Return the port the listener is currently bound to. Useful when starting the server with port: 0 (ephemeral) — typically in tests.

Returns a specification to start this module under a supervisor.

Return the conventional Registry name for a given server name.

Functions

bound_port(supervisor)

@spec bound_port(Supervisor.supervisor()) ::
  {:ok, :inet.port_number()} | {:error, term()}

Return the port the listener is currently bound to. Useful when starting the server with port: 0 (ephemeral) — typically in tests.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

registry_name(server_name)

@spec registry_name(atom()) :: atom()

Return the conventional Registry name for a given server name.

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()