Bundlex v0.2.2 Bundlex.CNode View Source
Utilities to ease interaction with Bundlex-based CNodes, so they can be treated
more like Elixir processes / GenServer
s.
Link to this section Summary
Functions
Makes a synchronous call to CNode and waits for its reply
Starts monitoring CNode from the calling process
Sends a message to cnode
Spawns and connects to CNode cnode_name
from application of calling module
Works the same way as start_link/2
, but does not link to CNode's associated
server
Spawns and connects to CNode cnode_name
from application of calling module
Spawns and connects to CNode cnode_name
from application app
Disconnects from CNode
Link to this section Types
on_start_t()
View Source
on_start_t() :: {:ok, t()} | {:error, :spawn_cnode | :connect_to_cnode}
on_start_t() :: {:ok, t()} | {:error, :spawn_cnode | :connect_to_cnode}
Reference to the CNode.
Consists of pid of CNode's associated server and CNode name.
Link to this section Functions
call(c_node, message, timeout \\ 5000)
View Source
call(t(), message :: term(), timeout :: non_neg_integer() | :infinity) ::
response :: term()
call(t(), message :: term(), timeout :: non_neg_integer() | :infinity) :: response :: term()
Makes a synchronous call to CNode and waits for its reply.
The CNode is supposed to send back a {cnode, response}
tuple where cnode
is the node name of CNode. If the response doesn't come in within timeout
,
error is raised.
Messages are exchanged directly (without interacting with CNode's associated server).
monitor(c_node) View Source
Starts monitoring CNode from the calling process.
send(c_node, message) View Source
Sends a message to cnode.
The message is exchanged directly (without interacting with CNode's associated server).
start(native_name) View Source (macro)
Spawns and connects to CNode cnode_name
from application of calling module.
See Bundlex.CNode.start/2
for more details.
start(app, native_name)
View Source
start(app :: atom(), native_name :: atom()) :: on_start_t()
start(app :: atom(), native_name :: atom()) :: on_start_t()
Works the same way as start_link/2
, but does not link to CNode's associated
server.
start_link(native_name) View Source (macro)
Spawns and connects to CNode cnode_name
from application of calling module.
See Bundlex.CNode.start_link/2
for more details.
start_link(app, native_name)
View Source
start_link(app :: atom(), native_name :: atom()) :: on_start_t()
start_link(app :: atom(), native_name :: atom()) :: on_start_t()
Spawns and connects to CNode cnode_name
from application app
.
The CNode is passed the following command line arguments:
- host name,
- alive name,
- node name,
- cookie,
- creation number.
After CNode startup, these parameters should be passed to
ei_connect_xinit
function, and CNode should be published and await connection. Once the CNode is
published, it should print a line starting with ready
to the standard output
and flush the standard output to avoid the line being buffered.
Under the hood, this function starts an associated server, which is responsible for monitoring the CNode and monitoring calling process to be able to do proper cleanup upon a crash. On startup, the server does the following:
- Makes current node distributed if it is not done yet (see
Node.start/3
). - Assigns CNode a unique name.
- Starts CNode OS process using
Port.open/2
. - Waits (at most 5 seconds) until a line
ready
is printed out (this line is captured and not forwarded to the stdout). - Connects to the CNode.
stop(c_node)
View Source
stop(t()) :: :ok | {:error, :disconnect_cnode}
stop(t()) :: :ok | {:error, :disconnect_cnode}
Disconnects from CNode.
It is the responsibility of the CNode to exit upon connection loss.