ACPex.Protocol.SessionSupervisor (ACPex v0.1.1)

Copy Markdown View Source

DynamicSupervisor that manages all active sessions for a single connection.

Each connection has its own SessionSupervisor instance, which dynamically spawns and monitors Session processes. This provides:

  • Isolated fault tolerance (a session crash doesn't affect other sessions)
  • Dynamic session creation as needed
  • Automatic cleanup of terminated sessions

Supervision Strategy

Uses a :one_for_one strategy, meaning if a session crashes, only that specific session is restarted, not all sessions.

Session Lifecycle

  1. Connection receives session/new request
  2. Connection calls start_session/4
  3. SessionSupervisor spawns a new Session process
  4. Session registers itself with the Connection
  5. Session handles messages until terminated

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a new SessionSupervisor.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Starts a new SessionSupervisor.

Typically started automatically by a Connection process.

start_session(sup, handler_module, initial_handler_state, transport_pid, session_id \\ nil)

@spec start_session(pid(), module(), term(), pid(), String.t() | nil) ::
  DynamicSupervisor.on_start_child()

Starts a new session under this supervisor.

Parameters

  • sup - PID of the SessionSupervisor
  • handler_module - Module implementing the protocol handler
  • initial_handler_state - Initial state for the handler
  • transport_pid - PID of the transport process
  • session_id - (optional) Use this session_id instead of generating a new one

Returns

{:ok, session_pid} on success, or {:error, reason} on failure.