AnyEvent-MP
view release on metacpan or search on metacpan
The "NODE" function returns, and the $NODE variable contains, the
node ID of the node running in the current process. This value is
initialised by a call to "configure".
$nodeid = node_of $port
Extracts and returns the node ID from a port ID or a node ID.
$is_local = port_is_local $port
Returns true iff the port is a local port.
configure $profile, key => value...
configure key => value...
Before a node can talk to other nodes on the network (i.e. enter
"distributed mode") it has to configure itself - the minimum a node
needs to know is its own name, and optionally it should know the
addresses of some other nodes in the network to discover other
nodes.
This function configures a node - it must be called exactly once (or
never) before calling other AnyEvent::MP functions.
The key/value pairs are basically the same ones as documented for
the aemp command line utility (sans the set/del prefix), with these
additions:
norc => $boolean (default false)
If true, then the rc file (e.g. ~/.perl-anyevent-mp) will *not*
be consulted - all configuration options must be specified in
the "configure" call.
force => $boolean (default false)
IF true, then the values specified in the "configure" will take
precedence over any values configured via the rc file. The
default is for the rc file to override any options specified in
the program.
step 1, gathering configuration from profiles
The function first looks up a profile in the aemp configuration
(see the aemp commandline utility). The profile name can be
specified via the named "profile" parameter or can simply be the
first parameter). If it is missing, then the nodename (uname -n)
will be used as profile name.
The profile data is then gathered as follows:
First, all remaining key => value pairs (all of which are
conveniently undocumented at the moment) will be interpreted as
configuration data. Then they will be overwritten by any values
specified in the global default configuration (see the aemp
utility), then the chain of profiles chosen by the profile name
(and any "parent" attributes).
That means that the values specified in the profile have highest
priority and the values specified directly via "configure" have
lowest priority, and can only be used to specify defaults.
If the profile specifies a node ID, then this will become the
node ID of this process. If not, then the profile name will be
used as node ID, with a unique randoms tring ("/%u") appended.
The node ID can contain some "%" sequences that are expanded: %n
is expanded to the local nodename, %u is replaced by a random
strign to make the node unique. For example, the aemp
commandline utility uses "aemp/%n/%u" as nodename, which might
expand to "aemp/cerebro/ZQDGSIkRhEZQDGSIkRhE".
step 2, bind listener sockets
The next step is to look up the binds in the profile, followed
by binding aemp protocol listeners on all binds specified (it is
possible and valid to have no binds, meaning that the node
cannot be contacted from the outside. This means the node cannot
talk to other nodes that also have no binds, but it can still
talk to all "normal" nodes).
If the profile does not specify a binds list, then a default of
"*" is used, meaning the node will bind on a
dynamically-assigned port on every local IP address it finds.
step 3, connect to seed nodes
As the last step, the seed ID list from the profile is passed to
the AnyEvent::MP::Global module, which will then use it to keep
connectivity with at least one node at any point in time.
Example: become a distributed node using the local node name as
profile. This should be the most common form of invocation for
"daemon"-type nodes.
configure
Example: become a semi-anonymous node. This form is often used for
commandline clients.
configure nodeid => "myscript/%n/%u";
Example: configure a node using a profile called seed, which is
suitable for a seed node as it binds on all local addresses on a
fixed port (4040, customary for aemp).
# use the aemp commandline utility
# aemp profile seed binds '*:4040'
# then use it
configure profile => "seed";
# or simply use aemp from the shell again:
# aemp run profile seed
# or provide a nicer-to-remember nodeid
# aemp run profile seed nodeid "$(hostname)"
$SELF
Contains the current port id while executing "rcv" callbacks or
"psub" blocks.
*SELF, SELF, %SELF, @SELF...
Due to some quirks in how perl exports variables, it is impossible
to just export $SELF, all the symbols named "SELF" are exported by
this module, but only $SELF is currently used.
snd $port, type => @data
snd $port, @msg
Send the given message to the given port, which can identify either
a local or a remote port, and must be a port ID.
While the message can be almost anything, it is highly recommended
( run in 0.703 second using v1.01-cache-2.11-cpan-5623c5533a1 )