AnyEvent-MP
view release on metacpan or search on metacpan
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.
"$cert$key"
}
sub init {
configure profile => "aemp", nodeid => "aemp/%n/%u";
}
our $cfg = AnyEvent::MP::Config::config;
our $profile = $cfg;
sub trace {
my ($seed) = @_;
my $cv = AE::cv;
my %seen;
my $exit;
my %to;
init;
my $reply = port {
my ($node, undef, @neigh) = @_;
delete $to{$node};
@neigh = grep $_ ne $NODE, @neigh;
print $node, " -> ", (join " ", @neigh), "\n";
for my $neigh (@neigh) {
unless ($seen{$neigh}++) {
$cv->begin;
$to{$neigh} = AE::timer 15, 0, sub {
print "$neigh (timeout)\n";
$exit = 1;
$cv->end;
};
AnyEvent::MP::Kernel::eval_on $neigh, "AnyEvent::MP::Kernel::up_nodes" => $SELF => $neigh;
}
}
$cv->end;
};
$cv->begin;
snd $reply, seed => undef, $seed;
$cv->recv;
exit $exit;
}
sub shell {
init;
my $node = shift @ARGV || $NODE;
$| = 1;
print <<EOF;
Entering interactive shell - no commandline editing of course (use rlfe etc.).
\= display a list of nodes
\=name switch to another node
package P switch to package P when evaluating
\$ECHO contains the name of a port that echos everything sent to it
EOF
my $json = JSON::XS->new->pretty->ascii;
my $pkg = "AnyEvent::MP::Kernel";
my $cv = AE::cv;
my $echo = port {
print "\nECHO<$AnyEvent::MP::Kernel::SRCNODE> ", $json->encode (\@_), "\n$node $pkg> ";
};
print "$node $pkg> ";
my $t = AE::io *STDIN, 0, sub {
chomp (my $line = <STDIN>);
if ($line =~ s/^=//) {
if (length $line) {
$node = $line;
} else {
db_keys "'l" => sub {
print "\nnodes: ", (join " ", sort @{ $_[0] }), "\n$node $pkg> ";
};
}
} elsif ($line =~ /^\s*package\s+(\S+)\s*;?\s*$/) {
$pkg = $1;
} elsif ($line =~ /\S/) {
my $time = AE::time;
AnyEvent::MP::Kernel::eval_on
$node,
"package $pkg; my \$ECHO = '$echo'; $line",
port {
kil $SELF;
my ($err, @res) = @_;
$time = AE::time - $time;
print "\n$node: $line\n";
printf "%0.3fs\n", $time;
if (length $err) {
print "$err @res";
} else {
print $json->encode(\@res);
}
print "\n$node $pkg> ";
}
;
}
print "$node $pkg> ";
};
$cv->recv;
}
sub node_eval {
my ($node, $expr) = @_;
init;
( run in 0.548 second using v1.01-cache-2.11-cpan-39bf76dae61 )