Logos. Runtime. Registry
(Logos v0.2.0)
Copy Markdown
A named, VM-wide lookup table from an arbitrary String.t() name to a
%Logos.Runtime{}. Its main consumer is mix logos.remsh: a host app
that starts distributed (--sname/--name + cookie) registers its
Runtime(s) here under a name, and a logos.remsh session attached to
that node looks up "the Runtime the host app wants exposed" by name
rather than needing a direct reference passed around from process to
process.
Storage-shape decision
Backed by a bare :ets table (:named_table, :public, :set) --
deliberately not Elixir's Registry module, which is built for
registering processes (keys map to {pid, value}, entries vanish
automatically when the owning process dies) -- a %Logos.Runtime{} is
plain data (an ETS table reference wrapped in a struct, see
Logos.Runtime's own moduledoc), not a process, so there is no
"owning process" for Registry's automatic cleanup semantics to hook
into. A bare named ETS table is the simplest thing that actually fits:
register/lookup/list are three one-line ETS operations, and unlike
every Logos.Runtime table itself (deliberately not :named_table,
per that module's own moduledoc, to avoid a global-singleton trap),
this module's whole purpose is to be a single global, VM-wide
singleton directory -- "the host app's named Runtimes" is inherently
one thing per VM, not one per embedding instance. start!/0 is
idempotent (safe to call more than once, e.g. from multiple mix tasks
in the same VM, or from tests) so nothing but the first caller actually
creates the table.
Summary
Functions
Every currently registered {name, runtime} pair.
Looks up the Logos.Runtime registered under name.
Registers runtime under name, overwriting whatever was previously registered under that name.
Ensures the registry's backing ETS table exists. Idempotent -- safe to call from multiple places.
Removes name's registration, if any. Idempotent.
Functions
@spec list() :: [{String.t(), Logos.Runtime.t()}]
Every currently registered {name, runtime} pair.
@spec lookup(String.t()) :: {:ok, Logos.Runtime.t()} | :error
Looks up the Logos.Runtime registered under name.
@spec register(String.t(), Logos.Runtime.t()) :: :ok
Registers runtime under name, overwriting whatever was previously registered under that name.
@spec start!() :: :ok
Ensures the registry's backing ETS table exists. Idempotent -- safe to call from multiple places.
@spec unregister(String.t()) :: :ok
Removes name's registration, if any. Idempotent.