ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/bin/aemp
(Generate patch)

Comparing AnyEvent-MP/bin/aemp (file contents):
Revision 1.24 by root, Sun Aug 30 18:51:49 2009 UTC vs.
Revision 1.25 by root, Sun Aug 30 19:49:47 2009 UTC

51 aemp delservice <initfunc> # delete one instance of a service 51 aemp delservice <initfunc> # delete one instance of a service
52 52
53 # profile-specific configuration 53 # profile-specific configuration
54 aemp profile <name> <command>... # apply command to profile only 54 aemp profile <name> <command>... # apply command to profile only
55 aemp parent <name> # specify a parent profile 55 aemp parent <name> # specify a parent profile
56 aemp delparent # clear parent again
56 aemp delprofile <name> # eradicate the named profile 57 aemp delprofile <name> # eradicate the named profile
57 aemp showprofile <name> # display given profile 58 aemp showprofile <name> # display given profile
58 aemp showconfig <name> # display effective config 59 aemp showconfig <name> ... # display effective config
59 60
60=head1 DESCRIPTION 61=head1 DESCRIPTION
61 62
62With aemp you can configure various aspects of AnyEvent::MP and its 63With aemp you can configure various aspects of AnyEvent::MP and its
63protocol, send various messages and even run a node. 64protocol, send various messages and even run a node.
94=back 95=back
95 96
96=head2 PROTOCOL COMMANDS 97=head2 PROTOCOL COMMANDS
97 98
98These commands actually communicate with other nodes. They all use a node 99These commands actually communicate with other nodes. They all use a node
99profile name of L<anon/> currently. 100profile name of C<aemp> (specifying a dfeault node ID of C<anon/> and a
101binds list containing C<*:*> only).
100 102
101They all use a timeout of five seconds, after which they give up. 103They all use a timeout of five seconds, after which they give up.
102 104
103=over 4 105=over 4
104 106
252 254
253Sets the list of bind addresses explicitly - see the F<aemp setseeds> 255Sets the list of bind addresses explicitly - see the F<aemp setseeds>
254command for the exact syntax. In addition, a value of C<0> for the port 256command for the exact syntax. In addition, a value of C<0> for the port
255means to use a dynamically-assigned port. 257means to use a dynamically-assigned port.
256 258
257Note that the C<*>, C<*:0> or C<*:port> values are very useful here. 259Note that the C<*>, C<*:*> or C<*:port> values are very useful here.
258 260
259Example: bind on the default port (4040) on all local interfaces. 261Example: bind on the default port (4040) on all local interfaces.
260 262
261 aemp setbinds "*" 263 aemp setbinds "*"
262 264
263Example: bind on a random port on all local interfaces. 265Example: bind on a random port on all local interfaces.
264 266
265 aemp setbinds "*:0" 267 aemp setbinds "*:*"
266 268
267Example: resolve "doomed.mydomain" and try to bind on port C<4040> of all 269Example: resolve "doomed.mydomain" and try to bind on port C<4040> of all
268IP addressess returned. 270IP addressess returned.
269 271
270 aep setbinds doomed.mydomain 272 aep setbinds doomed.mydomain
334 336
335Example: create a C<server> profile, give it a random node name, some seed 337Example: create a C<server> profile, give it a random node name, some seed
336nodes and bind it on an unspecified port on all local interfaces. You 338nodes and bind it on an unspecified port on all local interfaces. You
337should add some services then and run the node... 339should add some services then and run the node...
338 340
339 aemp server setnodeid anon/ setseeds doomed,10.0.0.2:5000 setbinds "*:0" 341 aemp server setnodeid anon/ setseeds doomed,10.0.0.2:5000 setbinds "*:*"
340 342
341=item delprofile <name> 343=item delprofile <name>
342 344
343Deletes the profile of the given name. 345Deletes the profile of the given name.
344 346
365=item showprofile <name> 367=item showprofile <name>
366 368
367Shows the values of the given profile, and only those, no inherited 369Shows the values of the given profile, and only those, no inherited
368values. 370values.
369 371
370=item showconfig <name> 372=item showconfig <name> <key value...>
371 373
372Shows the I<effective> config, i.e. the values as used by a node started 374Shows the I<effective> config, i.e. the values as used by a node started
373with the given profile name. 375with the given profile name. Any additional key-value pairs specified
376augment the configuration, just as with C<initialise_node>.
374 377
375If the name is omitted, show the global default config. 378If all arguments are omitted, show the global default config.
376 379
377=back 380=back
378 381
379=cut 382=cut
380 383
392 395
393 AnyEvent::Watchdog::autorestart (1); 396 AnyEvent::Watchdog::autorestart (1);
394 AnyEvent::Watchdog::heartbeat (300); 397 AnyEvent::Watchdog::heartbeat (300);
395 398
396 require AnyEvent; 399 require AnyEvent;
397 require AnyEvent::MP; 400 require AnyEvent::MP::Kernel;
398 AnyEvent::MP::initialise_node (@ARGV); 401 AnyEvent::MP::Kernel::initialise_node (@ARGV);
399 402
400 AnyEvent::detect () eq "AnyEvent::Impl::EV" 403 AnyEvent::detect () eq "AnyEvent::Impl::EV"
401 ? EV::loop () 404 ? EV::loop ()
402 : AE::cv ()->recv; 405 : AE::cv ()->recv;
403 } 406 }
435 "2>", "/dev/null"; 438 "2>", "/dev/null";
436 439
437 "$cert$key" 440 "$cert$key"
438} 441}
439 442
443sub init {
444 initialise_node aemp => nodeid => "anon/", binds => ["*:*"];
445}
446
440our $cfg = AnyEvent::MP::Config::config; 447our $cfg = AnyEvent::MP::Config::config;
441our $profile = $cfg; 448our $profile = $cfg;
442 449
443sub trace { 450sub trace {
444 my ($node) = @_; 451 my ($node) = @_;
448 my $to = AE::timer 15, 0, sub { 455 my $to = AE::timer 15, 0, sub {
449 warn "timeout\n"; 456 warn "timeout\n";
450 $cv->(); 457 $cv->();
451 }; 458 };
452 459
453 initialise_node "anon/"; 460 init;
454 461
455 my $reply = port { 462 my $reply = port {
456 my ($node, @neigh) = @_; 463 my ($node, @neigh) = @_;
457 464
458 @neigh = grep $_ ne $NODE, @neigh; 465 @neigh = grep $_ ne $NODE, @neigh;
478sub docmd; 485sub docmd;
479 486
480our %CMD = ( 487our %CMD = (
481 snd => sub { 488 snd => sub {
482 my $port = shift @ARGV; 489 my $port = shift @ARGV;
483 initialise_node "anon/"; 490 init;
484 491
485 snd $port, @ARGV; @ARGV = (); 492 snd $port, @ARGV; @ARGV = ();
486 493
487 my $cv = AE::cv; 494 my $cv = AE::cv;
488 my $to = AE::timer 5, 0, sub { $cv->("timeout") }; 495 my $to = AE::timer 5, 0, sub { $cv->("timeout") };
493 print join " ", $cv->recv, "\n"; 500 print join " ", $cv->recv, "\n";
494 }, 501 },
495 502
496 rpc => sub { 503 rpc => sub {
497 my $port = shift @ARGV; 504 my $port = shift @ARGV;
498 initialise_node "anon/"; 505 init;
499 506
500 my $cv = AE::cv; 507 my $cv = AE::cv;
501 my $to = AE::timer 5, 0, sub { $cv->("timeout") }; 508 my $to = AE::timer 5, 0, sub { $cv->("timeout") };
502 snd $port, @ARGV, port { &$cv }; @ARGV = (); 509 snd $port, @ARGV, port { &$cv }; @ARGV = ();
503 mon $port, $cv; 510 mon $port, $cv;
505 print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n"; 512 print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n";
506 }, 513 },
507 514
508 mon => sub { 515 mon => sub {
509 my $port = shift @ARGV; 516 my $port = shift @ARGV;
510 initialise_node "anon/"; 517 init;
511 518
512 mon $port, my $cv = AE::cv; 519 mon $port, my $cv = AE::cv;
513 print join " ", $cv->recv, "\n"; 520 print join " ", $cv->recv, "\n";
514 }, 521 },
515 522
516 eval => sub { 523 eval => sub {
517 my $node = node_of shift @ARGV; 524 my $node = node_of shift @ARGV;
518 my $expr = join " ", @ARGV; @ARGV = (); 525 my $expr = join " ", @ARGV; @ARGV = ();
519 initialise_node "anon/"; 526 init;
520 527
521 my $cv = AE::cv; 528 my $cv = AE::cv;
522 my $to = AE::timer 5, 0, sub { $cv->("timeout") }; 529 my $to = AE::timer 5, 0, sub { $cv->("timeout") };
523 AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv }; 530 AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv };
524 mon $node, $cv; 531 mon $node, $cv;
705 print JSON::XS->new->pretty->encode ($cfg->{profile}{$name} || {}); 712 print JSON::XS->new->pretty->encode ($cfg->{profile}{$name} || {});
706 }, 713 },
707 showconfig => sub { 714 showconfig => sub {
708 my $name = @ARGV ? shift @ARGV : AnyEvent::MP::Kernel::_nodename; 715 my $name = @ARGV ? shift @ARGV : AnyEvent::MP::Kernel::_nodename;
709 716
710 my $profile = AnyEvent::MP::Config::find_profile $name; 717 my $profile = AnyEvent::MP::Config::find_profile $name, @ARGV;
718 @ARGV = ();
711 719
712 # make it look nicer: 720 # make it look nicer:
713 delete $profile->{profile}; 721 delete $profile->{profile};
714 delete $profile->{parent}; 722 delete $profile->{parent};
715 723
716 print JSON::XS->new->pretty->encode ($profile); 724 print JSON::XS->new->pretty->encode ($profile);
717 }, 725 },
726
727 # undocumented
728 _resolve => sub {
729 print +(join ",", (AnyEvent::MP::Kernel::_resolve shift @ARGV)->recv), "\n";
730 },
718); 731);
719 732
720sub docmd { 733sub docmd {
721 my $cmd = shift @ARGV; 734 my $cmd = shift @ARGV;
722 735

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines