Distribunator.Distributed (distribunator v1.0.0)

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

Link to this macro

all_nodes_of()

(macro)

Specs

all_nodes_of() :: {:ok, [atom()]} | {:error, any()}

Get all nodes having the current module registered, see all_nodes_of/1

Link to this function

all_nodes_of(name)

Specs

all_nodes_of(atom()) :: {:ok, [atom()]} | {:error, any()}

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
Link to this macro

all_pids_of()

(macro)

Specs

all_pids_of() :: {:ok, [pid()]} | {:error, any()}

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
Link to this function

all_pids_of(name)

Specs

all_pids_of(any()) :: {:ok, [pid()]} | {:error, any()}

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
Link to this macro

call(msg, timeout \\ 5000)

(macro)

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()
Link to this macro

cast(msg)

(macro)

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()
Link to this function

do_node_rpc(target_node, mod, func, args, callback)

Specs

do_node_rpc(atom(), atom(), atom(), list(), function() | nil) ::
  {:error, any()} | any()

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)
Link to this macro

my_pid()

(macro)

Specs

my_pid() :: pid()

Get the first pid of the current module

Returns

  • pid The first registered pid of the calling module
Link to this macro

node_rpc(mod, func, args, callback)

(macro)

Specs

node_rpc(atom(), atom(), list(), function() | nil) :: {:error, any()} | any()

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)
Link to this function

node_rpc(name, mod, func, args, callback)

Specs

node_rpc(atom(), atom(), atom(), list(), function() | nil) ::
  {:error, any()} | any()

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)

Specs

pid_of(any()) :: {:ok, pid()} | {:error, any()}

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
Link to this macro

register()

(macro)

Specs

register() :: :ok

Register the current module and pid, easy shorthand

Specs

register(any()) :: :ok

Register self() with a distributed name

Parameters

  • name The distributed name

Returns

  • :ok
Link to this function

register(name, pid)

Specs

register(any(), pid()) :: :ok

Register a pid with a distributed name

Parameters

  • name The distributed name
  • pid The pid

Returns

  • :ok

Get the registry of names and pids

Returns

  • [{name, {:ok, [pid]}}, ...]