ExMCP.HttpPlug.SessionRegistry (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Supervised owner of the SSE session table used by ExMCP.HttpPlug.

ExMCP.HttpPlug runs inside short-lived HTTP request processes, so the ETS table mapping session ids to SSE handler pids must be owned by a long-lived process — otherwise every registration would vanish as soon as the request process that happened to create the table exits. This GenServer creates the named public table in init/1 and simply holds it for the lifetime of the :ex_mcp application, which starts it as part of its supervision tree.

Summary

Functions

Returns a specification to start this module under a supervisor.

Looks up the SSE handler pid registered for a session id.

Registers the SSE handler pid for a session id.

Returns the name of the ETS table holding session registrations.

Removes the registration for a session id.

Removes the registration for a session id only if it still points at handler_pid.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(session_id)

@spec lookup(String.t()) ::
  {:ok, pid()} | {:error, :not_found | :registry_not_started}

Looks up the SSE handler pid registered for a session id.

register(session_id, handler_pid)

@spec register(String.t(), pid()) :: :ok | {:error, :registry_not_started}

Registers the SSE handler pid for a session id.

Returns {:error, :registry_not_started} when the owning process (and thus the table) is not running, which usually means the :ex_mcp application has not been started.

start_link(opts \\ [])

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

table()

@spec table() :: atom()

Returns the name of the ETS table holding session registrations.

unregister(session_id)

@spec unregister(String.t()) :: :ok

Removes the registration for a session id.

unregister(session_id, handler_pid)

@spec unregister(String.t(), pid()) :: :ok

Removes the registration for a session id only if it still points at handler_pid.

Used by handlers cleaning up after themselves in terminate/2 without clobbering a newer registration made for the same session id.