Distribunator.Distributed (distribunator v1.2.1)
Utilities supporting process distribution
Link to this section Summary
Functions
Get all nodes having the current module registered, see all_nodes_of/1
Get all node atoms sharing an instance of a distributed name
Get all pids registered to the current module, easy shorthand
Get all pids sharing a distributed name
Do a distributed call to the first registered pid of the calling module.
Do a distributed cast to the first registered pid of the calling module.
Perform an :rpc.call/4 on the target node. The callback is called with the target function's return value from the context of the intermediate rpc pid. This allows the return value to be used before the target node sees that the caling pid exited. Useful for when the target node wants to monitor calling pids.
Get the first pid of the current module
Perform an :rpc.call/4 on the first node having the current module registered on it.
Perform an :rpc.call/4 on the first node having name registered on it.
Get a single pid of a distributed name. If there are multiple pids registered with the same name, a random one is returned.
Register the current module and pid, easy shorthand
Register self() with a distributed name
Register a pid with a distributed name
Get the registry of names and pids
Link to this section Functions
Specs
Get all nodes having the current module registered, see all_nodes_of/1
all_nodes_of(name)
Specs
Get all node atoms sharing an instance of a distributed name
Parameters
- name The distributed name
Returns
{:ok, [node_atom]}
Success, even if atom list is emtpy{:error, reason}
Failure and reason
Specs
Get all pids registered to the current module, easy shorthand
Returns
{:ok, [pid()]}
Success, even if pid list is empty{:error, reason}
Failure and reason
all_pids_of(name)
Specs
Get all pids sharing a distributed name
Parameters
- name The distributed name
Returns
{:ok, [pid()]}
Success, even if pid list is empty{:error, reason}
Failure and reason
Do a distributed call to the first registered pid of the calling module.
Parameters
- msg The message to send
- timeout The timeout (ms)
Returns
- The result of GenServer.call()
Do a distributed cast to the first registered pid of the calling module.
Parameters
- msg The message to send
Returns
- The result of GenServer.cast()
do_node_rpc(target_node, mod, func, args, callback)
Specs
Perform an :rpc.call/4 on the target node. The callback is called with the target function's return value from the context of the intermediate rpc pid. This allows the return value to be used before the target node sees that the caling pid exited. Useful for when the target node wants to monitor calling pids.
Parameters
- target_node The node on which to execute the function
- mod The module atom to call the function on
- func The function atom to call
- args The argument list to function
- callback The callback to call during rpc invocation after the target function returns but before the rpc call returns. Can be nil.
Returns
{:badrpc, reason}
RPC failed, for reason{:error, "no node"}
There were no nodes with name registered- any The result of
apply(mod, func, args)
Specs
my_pid() :: pid()
Get the first pid of the current module
Returns
pid
The first registered pid of the calling module
Specs
Perform an :rpc.call/4 on the first node having the current module registered on it.
Parameters
- mod The module atom to call the function on
- func The function atom to call
- args The argument list to function
- callback The callback to call during rpc invocation after the target function returns but before the rpc call returns. Can be nil.
Returns
{:badrpc, reason}
RPC failed, for reason{:error, "no node"}
There were no nodes with name registered- any The result of
apply(mod, func, args)
node_rpc(name, mod, func, args, callback)
Specs
Perform an :rpc.call/4 on the first node having name registered on it.
Parameters
- name The distributed name
- mod The module atom to call the function on
- func The function atom to call
- args The argument list to function
- callback The callback to call during rpc invocation after the target function returns but before the rpc call returns. Can be nil.
Returns
{:badrpc, reason}
RPC failed, for reason{:error, "no node"}
There were no nodes with name registered- any The result of
apply(mod, func, args)
pid_of(name)
Specs
Get a single pid of a distributed name. If there are multiple pids registered with the same name, a random one is returned.
Parameters
- name The distributed name
Returns
{:ok, pid}
Success{:error, reason}
Failure and reason
Specs
register() :: :ok
Register the current module and pid, easy shorthand
register(name)
Specs
register(any()) :: :ok
Register self() with a distributed name
Parameters
- name The distributed name
Returns
:ok
register(name, pid)
Specs
Register a pid with a distributed name
Parameters
- name The distributed name
- pid The pid
Returns
:ok
registry()
Get the registry of names and pids
Returns
[{name, {:ok, [pid]}}, ...]