Amarula.Protocol.Socket.ConnectionSupervisor (amarula v0.1.0)
View SourcePer-connection supervision tree. One ConnectionSupervisor owns everything for
a single WhatsApp connection instance:
ConnectionSupervisor (:one_for_one)
├── Registry (per-instance; keys = {instance_id, role})
├── TableOwner (per-connection retry-cache ETS)
├── Connection (THE socket: ws + cipher + IQ + sends + consumer API)
└── SenderSupervisor (DynamicSupervisor) — ConversationSender…Connection.make_socket/2 starts this supervisor and returns the Connection
child pid — the consumer's handle, so the public API (connect/send_text/...
on that pid) lands on Connection directly (no relay).
Siblings find each other through the per-instance Registry by role, via
name/2 / whereis/2 — no global atom names, no leaked atoms.
Summary
Functions
Returns a specification to start this module under a supervisor.
The :via tuple addressing a sibling role in this instance's Registry.
The per-instance Registry's process name. Derived from the instance ref so it is unique per instance and dies with the supervisor.
Start a connection instance. opts may carry :parent_pid. Returns
{:ok, sup_pid, connection_pid} — connection_pid is the consumer handle.
Stop a whole connection tree by its instance_id (the supervisor + all children,
freeing the profile registration). Returns :ok, or {:error, :not_found} if no
such tree is running.
The supervisor's registered name, derived from the instance ref.
Resolve a sibling role to a pid, or :undefined.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
The :via tuple addressing a sibling role in this instance's Registry.
The per-instance Registry's process name. Derived from the instance ref so it is unique per instance and dies with the supervisor.
@spec start_instance( Amarula.Conn.t(), keyword() ) :: {:ok, pid(), pid()} | {:error, term()}
Start a connection instance. opts may carry :parent_pid. Returns
{:ok, sup_pid, connection_pid} — connection_pid is the consumer handle.
The tree is started under the library-owned Amarula.ConnectionsSupervisor
(a DynamicSupervisor), not linked to the calling consumer. A connection
crash is therefore observable by the consumer through parent_pid events but
never delivers an exit signal that would take the consumer down.
@spec stop_instance(reference()) :: :ok | {:error, :not_found}
Stop a whole connection tree by its instance_id (the supervisor + all children,
freeing the profile registration). Returns :ok, or {:error, :not_found} if no
such tree is running.
The supervisor's registered name, derived from the instance ref.
Resolve a sibling role to a pid, or :undefined.