Bloccs.Discovery (bloccs v0.2.0)

Copy Markdown View Source

Boot-time registration of running networks, so introspection tools can enumerate them in O(1) without scanning the supervision tree.

Each compiled network supervisor calls register/2 from its init/1. The entry lives in Bloccs.NetworkRegistry keyed by the network id and is owned by the supervisor process, so it is removed automatically when that supervisor stops or crashes — list/0 never reports a dead network.

A network compiled with an older bloccs won't carry the registration call; re-run mix bloccs.compile after upgrading to make it discoverable.

Summary

Functions

List every running network.

Look up a single running network by id.

Register a running network. Called from the generated supervisor's init/1, so the registration is owned by (and cleaned up with) the supervisor process. Idempotent for the calling process.

Types

entry()

@type entry() :: %{
  network_id: atom(),
  supervisor: module(),
  pid: pid(),
  started_at: integer()
}

Functions

list()

@spec list() :: [entry()]

List every running network.

lookup(network_id)

@spec lookup(atom()) :: {:ok, entry()} | :error

Look up a single running network by id.

register(network_id, supervisor_module)

@spec register(atom(), module()) :: :ok

Register a running network. Called from the generated supervisor's init/1, so the registration is owned by (and cleaned up with) the supervisor process. Idempotent for the calling process.