DistributedSupervisor (distributed_supervisor v0.1.0)

View Source

DistributedSupervisor is exactly what its name says. It’s a DynamicSupervisor working transparently in a distributed environment.

Example

iex|🌢|n1@am|1> DistributedSupervisor.start_link(name: DS)
{:ok, #PID<0.307.0>}
iex|🌢|n1@am|2> DistributedSupervisor.start_child(DS, {MyGenServer, name: MGS})
{:ok, #PID<0.311.0>, MGS}
iex|🌢|n1@am|3> DistributedSupervisor.children(DS)
%{MGS => #PID<0.311.0>}

Summary

Types

The id of the child process within the instance of the distributed supervisor. Might be whatever. If not passed explicitly to the DistributedSupervisor.start_child/2, the reference will be created automatically and returned as a third element of the {:ok, pid, child_name} success tuple.

The name of the instance of this distributed supervisor. Unlike GenServer.name/0, it must be an atom.

Functions

A syntactic sugar for GenServer.call/2 allowing to call a dynamically supervised GenServer by registry name and key.

A syntactic sugar for GenServer.cast/2 allowing to call a dynamically supervised GenServer by registry name and key.

Returns a specification to start this module under a supervisor.

Returns a map with registered names as keys and pids as values for the instance of the registry with a name name.

A syntactic sugar for Kernel.send/2 allowing to send a message to a dynamically supervised GenServer identified by registry name and key.

Dynamically adds a child specification to supervisor and starts that child.

Returns a fully qualified name to use with a standard library functions, accepting {:via, Registry, key} as a GenServer name.

Returns a t:pid() for the instance of the registry with a name name by key.

Types

id()

@type id() :: term()

The id of the child process within the instance of the distributed supervisor. Might be whatever. If not passed explicitly to the DistributedSupervisor.start_child/2, the reference will be created automatically and returned as a third element of the {:ok, pid, child_name} success tuple.

name()

@type name() :: atom()

The name of the instance of this distributed supervisor. Unlike GenServer.name/0, it must be an atom.

Functions

call(name, child, msg)

@spec call(name(), id(), msg) :: result when msg: term(), result: term()

A syntactic sugar for GenServer.call/2 allowing to call a dynamically supervised GenServer by registry name and key.

cast(name, child, msg)

@spec cast(name(), id(), msg) :: :ok when msg: term()

A syntactic sugar for GenServer.cast/2 allowing to call a dynamically supervised GenServer by registry name and key.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

children(name)

@spec children(name()) :: %{optional(term()) => pid()}

Returns a map with registered names as keys and pids as values for the instance of the registry with a name name.

send(name, child, msg)

@spec send(name(), id(), msg) :: msg | nil when msg: term()

A syntactic sugar for Kernel.send/2 allowing to send a message to a dynamically supervised GenServer identified by registry name and key.

start_child(name, spec)

Dynamically adds a child specification to supervisor and starts that child.

child_spec should be a valid child specification as detailed in the “Child specification” section of the documentation for Supervisor expressed as a Supervisor.child_spec/0 or as a tuple {module, start_link_arg}.

The child process will be started as defined in the child specification. The core difference from DynamicSupervisor is that the process must be named. The name might be any term, passed through name: option in a call to this function. If name option is not passed, it gets assigned randomly and returned in the third element of the tuple from start_child/2.

See: DynamicSupervisor.start_child/2

start_link(opts \\ [])

Starts the DistributedSupervisor.

  • required option
    • name :: DistributedSupervisor.name() the name of the supervisor to be used in lookups etc

via_name(name, id)

@spec via_name(name(), id()) :: {:via, module(), {name(), id()}}

Returns a fully qualified name to use with a standard library functions, accepting {:via, Registry, key} as a GenServer name.

whereis(name, child)

@spec whereis(name(), id()) :: pid() | nil

Returns a t:pid() for the instance of the registry with a name name by key.

See: DistributedSupervisor.children/1