Behaviours: supervisor.
Authors: Steve Roques.
em_pop_sup — Supervisor for Population Protocol nodes
One em_pop node (em_pop_node gen_server + Cowboy listener) is
started per agent that includes a pop_port key in its Config map.
An ETS table named em_pop_agent_nodes maps:
AgentName (atom) → PopNodePid (pid)
The table is public with read_concurrency so that
em_filter:pop_peers/1 and friends can do O(1) lookups without
going through a gen_server call.
The table is created inside start_link/0 with an existence check,
so supervisor restarts (which would call start_link/0 again) do
not crash on a duplicate table name.
simple_one_for_one — each dynamically added child is an
independent em_pop_node. Restart is transient: a node that exits
normally (e.g. via stop_node/1) is not restarted, but an
unexpected crash will trigger a restart.
| get_node/1 | Return the em_pop node pid for AgentName, or undefined. |
| start_link/0 | Start the supervisor and create the ETS registry if needed. |
| start_node/2 | Start an em_pop node for AgentName with the given Opts map. |
| stop_node/1 | Stop the em_pop node for AgentName. |
get_node(AgentName::atom()) -> pid() | undefined
Return the em_pop node pid for AgentName, or undefined.
start_link() -> {ok, pid()} | {error, term()}
Start the supervisor and create the ETS registry if needed.
The ETS table is created here rather than ininit/1 because
init/1 runs inside the new supervisor process, whereas we want the
table to be owned by the calling process (the application master)
so it survives supervisor crashes and restarts.
start_node(AgentName::atom(), Opts::map()) -> {ok, pid()} | {error, term()}
Start an em_pop node for AgentName with the given Opts map.
Delegates to supervisor:start_child/2 and registers the resulting
pid in the ETS registry so it can be found quickly by name.
Opts must contain at least:
port => pos_integer() — TCP port for the gossip HTTP listener
vector => binary() — f32 capability vector (unit norm)
stale_timeout => pos_integer() — default 30 000 ms
gossip_interval => non_neg_integer() — default 5 000 ms
max_peers => pos_integer() — default 200
stop_node(AgentName::atom()) -> ok
Stop the em_pop node for AgentName.
Removes the entry from the ETS registry and terminates the child process. No-op if AgentName has no registered node.
The child'srestart => transient strategy ensures the supervisor
does not try to restart it after a normal termination.
Generated by EDoc