DistributedSupervisor (distributed_supervisor v0.5.4)
View SourceDistributedSupervisor
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, cache_children?: true)
{: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>, %{id: …}}}
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/3
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
.
Returns a list of pids of local children
Returns true
if called from a node assigned to this key, false
otherwise
Returns the node for the key given according to a HashRing
Returns the list of nodes operated by a registered ring
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.
Starts the DistributedSupervisor
.
Terminates the given child identified by pid.
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.
Returns a registered name by a t:pid()
given.
Types
@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.
@type name() :: atom()
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/3
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.
See Supervisor
.
@spec children(name()) :: %{optional(term()) => {pid(), Supervisor.child_spec()}} | [ {:undefined, pid() | :restarting, :worker | :supervisor, [module()] | :dynamic} ]
Returns a map with registered names as keys and pids as values for the instance of the
registry with a name name
.
Returns a list of pids of local children
Returns true
if called from a node assigned to this key, false
otherwise
Returns the node for the key given according to a HashRing
Returns the list of nodes operated by a registered ring
A syntactic sugar for Kernel.send/2
allowing to send a message to
a dynamically supervised GenServer
identified by registry name and key.
@spec start_child(name(), Supervisor.child_spec() | {module(), term()}, node() | nil) :: DynamicSupervisor.on_start_child()
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
.
This function accepts an optional third argument node
. If it’s passed, the process
will be started on that node; the node will be chosed according to a keyring otherwise.
Starts the DistributedSupervisor
.
Options to DistributedSupervisor.start_link/1
:name
(atom/0
) - Required. The uniqueID
of this DistributedSupervisor, that will be used to address it, similar toDynamicSupervisor.name()
:cache_children?
(boolean/0
) - Iftrue
,Registry
will cache children as a map of%{name => %{pid() => initial_params}}
, setting this tofalse
would block the functionañity of restarting a process on another node when any node goes down The default value istrue
.:nodes
(list ofatom/0
) - The hardcoded list of nodes to spread children across, if not passed, all connected nodes will be used The default value is[]
.:monitor_nodes
(atom/0
) - If not false, theHashRing
will be automatically updated when nodes are changed in the cluster The default value isfalse
.:listeners
- The implementation ofDistributedSupervisor.Listener
to receive notifications upon process restarts The default value is[]
.
Terminates the given child identified by pid.
If successful, this function returns :ok
.
If there is no process with the given PID, this function returns {:error, :not_found}
.
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.
Returns a registered name by a t:pid()
given.