NAME

AnyEvent::MP::Kernel - the actual message passing kernel

SYNOPSIS

use AnyEvent::MP::Kernel;

$AnyEvent::MP::Kernel::SRCNODE   # contains msg origin node id, for debugging

snd_to_func $node, $func, @args  # send msg to function
snd_on $node, @msg               # snd message again (relay)
eval_on $node, $string[, @reply] # execute perl code on another node

node_is_up $nodeid               # return true if a node is connected
@nodes = up_nodes                # return a list of all connected nodes
$guard = mon_nodes $callback->($node, $is_up, @reason) # connections up/downs

DESCRIPTION

This module implements most of the inner workings of AnyEvent::MP. It offers mostly lower-level functions that deal with network connectivity and special requests.

You normally interface with AnyEvent::MP through a higher level interface such as AnyEvent::MP and Coro::MP, although there is nothing wrong with using the functions from this module.

GLOBALS AND FUNCTIONS

$AnyEvent::MP::Kernel::SRCNODE

During execution of a message callback, this variable contains the node ID of the origin node.

The main use of this variable is for debugging output - there are probably very few other cases where you need to know the source node ID.

snd_to_func $node, $func, @args

Expects a node ID and a name of a function. Asynchronously tries to call this function with the given arguments on that node.

This function can be used to implement spawn-like interfaces.

snd_on $node, @msg

Executes snd with the given @msg (which must include the destination port) on the given node.

eval_on $node, $string[, @reply]

Evaluates the given string as Perl expression on the given node. When @reply is specified, then it is used to construct a reply message with "$@" and any results from the eval appended.

$bool = node_is_up $nodeid

Returns true if the given node is "up", that is, the kernel thinks it has a working connection to it.

More precisely, if the node is up, returns 1. If the node is currently connecting or otherwise known but not connected, returns 0. If nothing is known about the node, returns undef.

@nodes = up_nodes

Return the node IDs of all nodes that are currently connected (excluding the node itself).

$guard = mon_nodes $callback->($nodeid, $is_up, @reason)

Registers a callback that is called each time a node goes up (a connection is established) or down (the connection is lost).

Node up messages can only be followed by node down messages for the same node, and vice versa.

Note that monitoring a node is usually better done by monitoring its node port. This function is mainly of interest to modules that are concerned about the network topology and low-level connection handling.

Callbacks must not block and should not send any messages.

The function returns an optional guard which can be used to unregister the monitoring callback again.

Example: make sure you call function newnode for all nodes that are up or go up (and down).

newnode $_, 1 for up_nodes;
mon_nodes \&newnode;

LOGGING

AnyEvent::MP::Kernel logs high-level information about the current node, when nodes go up and down, and most runtime errors. It also logs some debugging and trace messages about network maintainance, such as seed connections and global node management.

SEE ALSO

AnyEvent::MP.

AUTHOR

Marc Lehmann <schmorp@schmorp.de>
http://home.schmorp.de/