jonnify·bcs /bcs/elixir-core/otp-application/the-supervisor

B2.1.5 · dive 5 of 6 · module B2.1

The supervisor names the systems.

EchoData.Bcs.Supervisor: a comprehension over {name, namespace} pairs builds one PropertyStore child each, id set to the name, run one_for_one. The topology is data.

A comprehension turns name-namespace pairs into named, isolated children. Select a part.
stores =[{name, ns}, ...] child_spec(PropertyStore,[name, namespace], id: name) Supervisor · one_for_onestore · name Astore · name Bstore · name C
readout · Select a part. The supervisor maps {name, namespace} pairs to PropertyStore child specs with id set to the name, run one_for_one so each restarts in isolation.
§1

The idea

echo_data · bcs/supervisor.ex

EchoData.Bcs.Supervisor turns a list of systems into a running tree. Its init takes a list of {name, namespace} pairs and, for each, builds a child spec for a PropertyStore — passing the name and namespace as start arguments, and using the name as the child id. The supervisor is where the system topology is declared, and it is declared as data.

The strategy is one_for_one, and setting the child id to the name is what makes restarts addressable: each store is known to the supervisor by its name, so a crash restarts exactly that store and no other. Because the tree is a comprehension over a list, adding a system means adding a pair — not editing the supervisor.

Codemojex’s rooms take the same shape. A supervisor over room pairs brings up one store per room, each named by the room’s branded id; a new room is a new pair, a crashed room is one restarted child, and the command workers that drain the lanes hang off the same tree. The supervisor is how a game of many rooms becomes one supervised topology.

§2

The source

echo_data · committed, verbatim

echo_data/lib/echo_data/bcs/supervisor.ex — complete, 19 lines

defmodule EchoData.Bcs.Supervisor do
  @moduledoc "one_for_one over named property stores. Rung bcs1.1."

  use Supervisor

  def start_link(stores), do: Supervisor.start_link(__MODULE__, stores, name: __MODULE__)

  @impl true
  def init(stores) do
    children =
      for {name, ns} <- stores do
        Supervisor.child_spec({EchoData.Bcs.PropertyStore, [name: name, namespace: ns]},
          id: name
        )
      end

    Supervisor.init(children, strategy: :one_for_one)
  end
end
§4

The doors

the sibling courses
§3

References

sources · related

Sources

Related