Lotus.Source.Registry (Lotus v1.2.0)

Copy Markdown View Source

Names the processes an adapter starts for a source, without minting atoms.

Sources created in a UI carry arbitrary string names, and a registered process normally needs an atom. This Registry has unique keys, so a per-source process is reached through a via tuple whose key is a term:

name = Lotus.Source.Registry.via(MyApp.Adapters.HTTP, "warehouse")
{MyApp.Pool, name: name}

Lotus.Source.Supervisor starts the registry. An adapter names the children it returns from Lotus.Source.Adapter.source_children/2 through via/2 and reaches them later with whereis/2. Adapters that run more than one process per source tag them with via/3.

Summary

Functions

Returns the via tuple for the process an adapter runs for name.

Returns the via tuple for one of several processes an adapter runs for name, told apart by tag.

Returns the pid registered through via/2, or nil when the process is not running.

Returns the pid registered through via/3, or nil when the process is not running.

Types

key()

@type key() :: {module(), String.t()} | {module(), String.t(), term()}

Functions

via(module, name)

@spec via(module(), String.t()) :: {:via, Registry, {module(), key()}}

Returns the via tuple for the process an adapter runs for name.

via(module, name, tag)

@spec via(module(), String.t(), term()) :: {:via, Registry, {module(), key()}}

Returns the via tuple for one of several processes an adapter runs for name, told apart by tag.

whereis(module, name)

@spec whereis(module(), String.t()) :: pid() | nil

Returns the pid registered through via/2, or nil when the process is not running.

Registry removes a key a moment after its owner exits, so a lookup right after a stop can still hold the dead pid. This function checks the pid is alive and returns nil otherwise.

whereis(module, name, tag)

@spec whereis(module(), String.t(), term()) :: pid() | nil

Returns the pid registered through via/3, or nil when the process is not running.