macula_peers_sup (macula v0.20.5)
View SourceMacula Peers Supervisor.
This supervisor manages dynamic peer connections using a simple_one_for_one strategy. Each peer connection gets its own macula_peer_system supervisor with dedicated handlers.
Architecture (v0.8.5): - One macula_peers_sup instance per Macula node - Dynamically adds/removes macula_peer_system children - Each child = one peer connection - simple_one_for_one strategy for efficient scaling
Usage:
%% Start new peer connection
{ok, PeerPid} = macula_peers_sup:start_peer(Url, Opts).
%% List all active peers
Peers = macula_peers_sup:list_peers().
%% Count active peers
Count = macula_peers_sup:count_peers().
%% Stop peer connection
ok = macula_peers_sup:stop_peer(PeerPid).
Summary
Functions
Count active peer connections.
Initialize the peers supervisor.
List all active peer connections.
Start the peers supervisor.
Start a new peer connection.
Stop a peer connection.
Functions
-spec count_peers() -> non_neg_integer().
Count active peer connections.
Returns the number of currently running macula_peer_system supervisors.
Initialize the peers supervisor.
Sets up a simple_one_for_one supervisor for macula_peer_system children. Each child will be started with dynamic arguments (Url, Opts).
Strategy: simple_one_for_one - Efficient for managing many similar children - Children started/stopped dynamically - All children use same child spec template
Restart Strategy: temporary - Peer connections don't auto-restart on crash - Application decides when to reconnect - Prevents reconnection storms
-spec list_peers() -> [pid()].
List all active peer connections.
Returns a list of PIDs for all currently running macula_peer_system supervisors.
Start the peers supervisor.
Called by macula_root during application startup. Registers the supervisor with the local name macula_peers_sup.
Start a new peer connection.
Creates a new macula_peer_system supervisor for the peer at the given URL. The peer system will manage the connection lifecycle and all peer-specific handlers (pubsub, rpc, advertisements).
Stop a peer connection.
Gracefully terminates the macula_peer_system supervisor for the given peer. This will clean up all peer handlers and close the connection.