Amarula.ProfileRegistry (amarula v0.1.0)

View Source

The app-level profile -> Connection pid registry: the seam that enforces one connection per profile and lets a consumer refer to a connection by its :profile (restart-safe) rather than a raw pid.

Reach = the registry module's reach

By default this is a local Elixir Registry (this module name doubles as the default registry's process name, started by Amarula.Application), so uniqueness is enforced per node. A clustered consumer can supply a different, :via-compatible registry via the :registry connection config — e.g. Horde.Registry for cluster-wide uniqueness:

Amarula.new(%{profile: :primary, registry: {Horde.Registry, MyApp.HordeReg}})

The :registry config is {module, name} (or just name, defaulting the module to Registry). The library only relies on the standard Registry/:via contract (register/3, lookup/2, {:via, mod, {name, key}}), so any module implementing it works without a code change here.

Uniqueness is keyed by profile and is the consumer's responsibility: the library trusts profile <-> credentials 1:1 and does not validate it.

Summary

Types

A registry spec: {module, name} or a bare name (module defaults to Registry).

Functions

Resolve the {module, name} for a Conn (or config map), with defaults.

The :via tuple for a connection's profile, used as the GenServer name.

The live Connection pid for profile, or nil.

Types

spec()

@type spec() :: {module(), atom()} | atom()

A registry spec: {module, name} or a bare name (module defaults to Registry).

Functions

resolve(arg1)

@spec resolve(Amarula.Conn.t() | map()) :: {module(), atom()}

Resolve the {module, name} for a Conn (or config map), with defaults.

via(conn_or_config, profile)

@spec via(Amarula.Conn.t() | map(), term()) :: {:via, module(), {atom(), term()}}

The :via tuple for a connection's profile, used as the GenServer name.

whereis(conn_or_config, profile)

@spec whereis(Amarula.Conn.t() | map(), term()) :: pid() | nil

The live Connection pid for profile, or nil.