ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Intro.pod
(Generate patch)

Comparing AnyEvent-MP/MP/Intro.pod (file contents):
Revision 1.30 by root, Mon Aug 31 13:18:06 2009 UTC vs.
Revision 1.31 by elmex, Mon Aug 31 13:44:27 2009 UTC

387Ok, so far, this works. In the real world, however, the person configuring 387Ok, so far, this works. In the real world, however, the person configuring
388your application to run on a specific network (the end user or network 388your application to run on a specific network (the end user or network
389administrator) is often different to the person coding the application. 389administrator) is often different to the person coding the application.
390 390
391Or to put it differently: the arguments passed to configure are usually 391Or to put it differently: the arguments passed to configure are usually
392provided not by the programmer, but by whoeever is deplying the program. 392provided not by the programmer, but by whoever is deploying the program.
393 393
394To make this easy, AnyEvent::MP supports a simple configuration database, 394To make this easy, AnyEvent::MP supports a simple configuration database,
395using profiles, which can be managed using the F<aemp> command-line 395using profiles, which can be managed using the F<aemp> command-line
396utility (yes, this section is about the advanced tinkering we mentioned 396utility (yes, this section is about the advanced tinkering we mentioned
397before). 397before).
533=head3 Network Errors and the AEMP Guarantee 533=head3 Network Errors and the AEMP Guarantee
534 534
535I mentioned another important source of monitoring failures: network 535I mentioned another important source of monitoring failures: network
536problems. When a node loses connection to another node, it will invoke all 536problems. When a node loses connection to another node, it will invoke all
537monitoring actions as if the port was killed, even if it is possible that 537monitoring actions as if the port was killed, even if it is possible that
538the prot sitll lives happily on another node (not being able to talk to a 538the port still lives happily on another node (not being able to talk to a
539node means we have no clue what's going on with it, it could be crashed, 539node means we have no clue what's going on with it, it could be crashed,
540but also still running without knowing we lost the connection). 540but also still running without knowing we lost the connection).
541 541
542So another way to view monitors is "notify me when some of my messages 542So another way to view monitors is "notify me when some of my messages
543couldn't be delivered". AEMP has a guarantee about message delivery to a 543couldn't be delivered". AEMP has a guarantee about message delivery to a
544port: After starting a monitor, any message sent to a port will either 544port: After starting a monitor, any message sent to a port will either
545be delivered, or, when it is lost, any further messages will also be lost 545be delivered, or, when it is lost, any further messages will also be lost
546until the monitoring action is invoked. After that, further messgaes 546until the monitoring action is invoked. After that, further messages
547I<might> get delivered again. 547I<might> get delivered again.
548 548
549This doesn't sound like a very big guarantee, but it is kind of the best 549This doesn't sound like a very big guarantee, but it is kind of the best
550you can get whiel staying sane: Specifically, it means that there will 550you can get while staying sane: Specifically, it means that there will
551be no "wholes" in the message sequence: all messages sent are delivered 551be no "holes" in the message sequence: all messages sent are delivered
552in order, without any missing in between, and when some were lost, you 552in order, without any missing in between, and when some were lost, you
553I<will> be notified of that, so you can take recovery action. 553I<will> be notified of that, so you can take recovery action.
554 554
555=head3 Supervising 555=head3 Supervising
556 556
558I<more> stable? Well in fact, the goal is not really to make them more 558I<more> stable? Well in fact, the goal is not really to make them more
559stable, but to make them more resilient against actual errors and 559stable, but to make them more resilient against actual errors and
560crashes. And this is not done by crashing I<everything>, but by crashing 560crashes. And this is not done by crashing I<everything>, but by crashing
561everything except a supervisor. 561everything except a supervisor.
562 562
563A supervisor is simply some code that ensures that an applciation (or a 563A supervisor is simply some code that ensures that an application (or a
564part of it) is running, and if it crashes, is restarted properly. 564part of it) is running, and if it crashes, is restarted properly.
565 565
566To show how to do all this we will create a simple chat server that can 566To show how to do all this we will create a simple chat server that can
567handle many chat clients. Both server and clients can be killed and 567handle many chat clients. Both server and clients can be killed and
568restarted, and even crash, to some extent. 568restarted, and even crash, to some extent.
609 609
610 warn "server ready.\n"; 610 warn "server ready.\n";
611 611
612 AnyEvent->condvar->recv; 612 AnyEvent->condvar->recv;
613 613
614Looks like a lot, but it is actually quite simple: after your usualy 614Looks like a lot, but it is actually quite simple: after your usual
615preamble (this time we use common sense), we define a helper function that 615preamble (this time we use common sense), we define a helper function that
616sends some message to every registered chat client: 616sends some message to every registered chat client:
617 617
618 sub msg { 618 sub msg {
619 print "relaying: $_[0]\n"; 619 print "relaying: $_[0]\n";
652 rcv $server, privmsg => sub { 652 rcv $server, privmsg => sub {
653 my ($nick, $msg) = @_; 653 my ($nick, $msg) = @_;
654 msg "$nick: $msg"; 654 msg "$nick: $msg";
655 }; 655 };
656 656
657And finally, the server rgeisters itself in the server group, so that 657And finally, the server registers itself in the server group, so that
658clients can find it: 658clients can find it:
659 659
660 AnyEvent::MP::Global::register $server, "eg_chat_server"; 660 AnyEvent::MP::Global::register $server, "eg_chat_server";
661 661
662Well, well... and where is this supervisor stuff? Well... we cheated, 662Well, well... and where is this supervisor stuff? Well... we cheated,
751 751
752The rest of the program deals with the boring details of actually invoking 752The rest of the program deals with the boring details of actually invoking
753the supervisor function to start the whole client process and handle the 753the supervisor function to start the whole client process and handle the
754actual terminal input, sending it to the server. 754actual terminal input, sending it to the server.
755 755
756You should now try to start the server and one or more clients in diferent 756You should now try to start the server and one or more clients in different
757terminal windows (and the seed node): 757terminal windows (and the seed node):
758 758
759 perl eg/chat_client nick1 759 perl eg/chat_client nick1
760 perl eg/chat_client nick2 760 perl eg/chat_client nick2
761 perl eg/chat_server 761 perl eg/chat_server

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines