Snodo.Session.Registry behaviour (snodo v0.5.0)

Copy Markdown View Source

Behaviour for finding an initialize-era session process by its ID.

Snodo.Session.Manager uses a registry to map each Mcp-Session-Id to the process that holds the session. The default, Snodo.Session.Registry.Local, keeps that map on the local node. A session process always runs on the node that handled initialize; a registry decides only how a request finds it. The core performs no cross-node routing, so a deployment with several nodes needs sticky load balancing that sends every request for a session to the node that created it, whatever registry it uses.

Configure a registry with the manager's :registry option as a module or {module, options}. options is passed back unchanged to every callback.

child_spec/1 returns the process the registry needs, started under the manager before any session, or nil when it needs none. register/3 runs in the session process that is registering itself. unregister/2 runs in that process as it stops; a registry should also remove an entry when its process exits, since a killed session process cannot unregister.

Summary

Types

id()

@type id() :: String.t()

options()

@type options() :: term()

Callbacks

child_spec(options)

@callback child_spec(options()) ::
  Supervisor.child_spec() | Supervisor.module_spec() | nil

lookup(options, id)

@callback lookup(options(), id()) :: {:ok, pid()} | :error

register(options, id, pid)

@callback register(options(), id(), pid()) :: :ok | {:error, :taken}

unregister(options, id)

@callback unregister(options(), id()) :: :ok