AnyEvent-MP
view release on metacpan or search on metacpan
aemp delnodeid # reset node id to default (= inherit)
# node configuration: authentication
aemp gensecret # generate a random shared secret
aemp setsecret <secret> # set the shared secret
aemp delsecret # remove the secret (= inherit)
aemp gencert # generate a random certificate
aemp setcert <file> # set a certificate (key.pem + certificate.pem)
aemp delcert # remove certificate (= inherit)
# node configuration: seed addresses for bootstrapping
aemp setseeds <host:port>,... # set seeds
aemp delseeds # clear all seeds (= inherit)
aemp addseed <host:port> # add a seed
aemp delseed <host:port> # remove seed
# node configuration: bind addresses
aemp setbinds <host:port>,... # set binds
aemp delbinds # clear all binds (= inherit)
aemp addbind <host:port> # add a bind address
aemp delbind <host:port> # remove a bind address
# node configuration: services
aemp setservices initfunc,... # set service functions
aemp delservices # clear all services (= inherit)
aemp addservice <initfunc> # add an instance of a service
aemp delservice <initfunc> # delete one instance of a service
# profile management
aemp profile <name> <command>... # apply command to profile only
aemp setparent <name> # specify a parent profile
aemp delparent # clear parent again
aemp delprofile <name> # eradicate the named profile
aemp showprofile <name> # display given profile
aemp showconfig <name> ... # display effective config
# node configuration: low-level protocol
aemp [set|del]secure <boolean>
aemp [set|del]monitor_timeout <seconds>
aemp [set|del]connect_interval <seconds>
aemp [set|del]framing_format [array]
aemp [set|del]auth_offer [array]
aemp [set|del]auth_accept [array]
aemp [set|del]autocork <boolean>
aemp [set|del]nodelay <boolean>
=head1 DESCRIPTION
With aemp you can configure various aspects of AnyEvent::MP and its
protocol, send various messages and even run a node.
The F<aemp> utility works like F<cvs>, F<svn> or other commands: the first
argument defines which operation (subcommand) is requested, after which
arguments for this operation are expected. When a subcommand does not eat
all remaining arguments, the remaining arguments will again be interpreted
as subcommand and so on.
This means you can chain multiple commands, which is handy for profile
configuration, e.g.:
aemp gensecret profile xyzzy binds 4040,4041 nodeid anon/
Please note that all C<setxxx> subcommands have an alias without the
C<set> prefix.
All configuration data is stored in a human-readable (JSON) config file
stored in F<~/.perl-anyevent-mp> (or F<%appdata%/perl-anyevent-mp> on
loser systems, or wherever C<$ENV{PERL_ANYEVENT_MP_RC}> points to). Feel
free to look at it or edit it, the format is relatively simple.
=head2 SPECIFYING ARGUMENTS
Arguments can be specified just as with any other shell command, with a
few special cases:
If the I<first> argument starts with a literal C<[>-character, then it is
interpreted as a UTF-8 encoded JSON text. The resulting array replaces all
arguments.
Otherwise, if I<any> argument starts with one of C<[>, C<{> or C<">, then
it is interpreted as UTF-8 encoded JSON text (or a single value in case of
C<">), and the resulting reference or scalar replaces the argument.
This allows you, for example, to specify binds in F<aemp run> (using POSIX
shell syntax):
aemp run binds '["*:4040"]'
=head2 RUNNING A NODE
This can be used to run a node - together with some services, this makes
it unnecessary to write any wrapper programs.
=over 4
=item run <configure_args>...
Runs a node by calling C<AnyEvent::MP::Kernel::configure> with the given
arguments. The node runs under L<AnyEvent::Watchdog>, can be restarted
(and autorestarted, see the L<AnyEvent::Watchdog> manual). A very common
invocation is to just specify a profile using the profile name
aemp run database-backend
... but you can use most arguments that C<configure> understands:
aemp run nodeid mynode2 profile someprofile
Care has been taken to load (almost) no modules other than
L<AnyEvent::Watchdog> and the modules it loads, so everything (including
the L<AnyEvent::MP> modules themselves) will be freshly loaded on restart,
which makes upgrading everything except the perl binary easy.
=item restart <node>
Restarts the node using C<AnyEvent::Watchdog::Util::restart>. This works
for nodes started by C<aemp run>, but also for any other node that uses
L<AnyEvent::Watchdog>.
=back
=head2 PROTOCOL COMMANDS
These commands actually communicate with other nodes. They all use a node
profile name of C<aemp> (specifying a default node ID of C<anon/> and a
binds list containing C<*:*> only).
They all use a timeout of five seconds, after which they give up.
=over 4
=item snd <port> <arguments...>
Simply send a message to the given port - where you get the port ID from
is your problem.
Exits after ensuring that the message has been delivered to its node.
Most useful to take advantage of some undocumented functionality inside
nodes, such as node ports being able to call any method:
aemp snd doomed AnyEvent::Watchdog::restart 1
=item cal <port> <arg...>
Like F<aemp cal>: appends a local reply port to the message and waits for
a message to it.
basically C<host:port> pairs where you expect some long-running nodes. It
does no harm to have a node as its own seed (they will eventually be
ignored).
=over 4
=item setseeds <host:port>,...
Sets or replaces the list of seeds, which must be specified as a
comma-separated list of C<host:port> pairs. The C<host> can be a hostname,
an IP address, or C<*> to signify all local host addresses (which makes
little sense for seeds, outside some examples, but a lot of sense for
binds).
An empty list is allowed.
Example: use C<doomed> with default port as only seednode.
aemp setseeds doomed
=item delseeds
Removes the seed list again, which means it is inherited again from it's
parent profile, or stays unset.
=item addseed <host:port>
Adds a single seed address.
=item delseed <host:port>
Deletes the given seed address, if it exists.
=back
=head2 CONFIGURATION/BINDS
To be able to be reached from other nodes, a node must I<bind> itself
to some listening socket(s). The list of these can either bs specified
manually, or AnyEvent::MP can guess them. Nodes without any binds are
possible to some extent.
=over 4
=item setbinds <host:port>,...
Sets the list of bind addresses explicitly - see the F<aemp setseeds>
command for the exact syntax. In addition, a value of C<*> for the port,
or not specifying a port, means to use a dynamically-assigned port.
Note that the C<*>, C<*:*> or C<*:port> patterns are very useful here.
Example: bind on a ephemeral port on all local interfaces.
aemp setbinds "*"
Example: bind on a random port on all local interfaces.
aemp setbinds "*:*"
Example: resolve "doomed.mydomain" and try to bind on port C<4040> of all
IP addressess returned.
aep setbinds doomed.mydomain:4040
=item delbinds
Removes the bind list again, which means it is inherited again from it's
parent profile, or stays unset.
=item addbind <host:port>
Adds a single bind address.
=item delbind <host:port>
Deletes the given bind address, if it exists.
=back
=head2 CONFIGURATION/SERVICES
Services are modules (or functions) that are automatically loaded (or
executed) when a node starts. They are especially useful when used in
conjunction with F<aemp run>, to configure which services a node should
run.
Despite the daunting name, services really I<are> nothing more than a
module name or a function name with arguments. The "service" aspect comes
only from the behaviour of the module or function, which is supposed to
implement, well, some kind of service for the node, network etc.
Instead of writing a standalone program for each different node type in
your network, you can simply put your code into a module, and then let the
configuration decide which node runs which "services". This also makes it
easy to combine multiple different services within the same node.
=over 4
=item setservices <initfunc>...
Sets or replaces the list of services, which must be specified as a
comma-separated list or a JSON array.
Each string entry in the list is interpreted as either a module name to
load (when it ends with C<::>) or a function to call (all other cases).
Each entry which is an array itself (you need to use JSON format to
specify those) is interpreted as a function name and the arguments to
pass.
The algorithm to find the function is the same as used for C<<
L<AnyEvent::MP>::spawn >>.
Example: run the global service.
aemp setservices AnyEvent::MP::Global::
Example: call the mymod::myfun function with arguments 1, 2 and 3.
aemp setservices '[["mymod::myfun", 1,2,3]]'
=item delservices
( run in 0.558 second using v1.01-cache-2.11-cpan-39bf76dae61 )