… | |
… | |
41 | |
41 | |
42 | bin/aemp - stable. |
42 | bin/aemp - stable. |
43 | AnyEvent::MP - stable API, should work. |
43 | AnyEvent::MP - stable API, should work. |
44 | AnyEvent::MP::Intro - explains most concepts. |
44 | AnyEvent::MP::Intro - explains most concepts. |
45 | AnyEvent::MP::Kernel - mostly stable. |
45 | AnyEvent::MP::Kernel - mostly stable. |
46 | AnyEvent::MP::Global - stable API, protocol not yet final. |
46 | AnyEvent::MP::Global - stable but incomplete, protocol not yet final. |
47 | |
47 | |
48 | stay tuned. |
48 | stay tuned. |
49 | |
49 | |
50 | =head1 DESCRIPTION |
50 | =head1 DESCRIPTION |
51 | |
51 | |
52 | This module (-family) implements a simple message passing framework. |
52 | This module (-family) implements a simple message passing framework. |
53 | |
53 | |
… | |
… | |
61 | |
61 | |
62 | =over 4 |
62 | =over 4 |
63 | |
63 | |
64 | =item port |
64 | =item port |
65 | |
65 | |
66 | A port is something you can send messages to (with the C<snd> function). |
66 | Not to be confused with a TCP port, a "port" is something you can send |
|
|
67 | messages to (with the C<snd> function). |
67 | |
68 | |
68 | Ports allow you to register C<rcv> handlers that can match all or just |
69 | Ports allow you to register C<rcv> handlers that can match all or just |
69 | some messages. Messages send to ports will not be queued, regardless of |
70 | some messages. Messages send to ports will not be queued, regardless of |
70 | anything was listening for them or not. |
71 | anything was listening for them or not. |
71 | |
72 | |
… | |
… | |
474 | |
475 | |
475 | Monitor the given port and do something when the port is killed or |
476 | Monitor the given port and do something when the port is killed or |
476 | messages to it were lost, and optionally return a guard that can be used |
477 | messages to it were lost, and optionally return a guard that can be used |
477 | to stop monitoring again. |
478 | to stop monitoring again. |
478 | |
479 | |
|
|
480 | In the first form (callback), the callback is simply called with any |
|
|
481 | number of C<@reason> elements (no @reason means that the port was deleted |
|
|
482 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
|
|
483 | C<eval> if unsure. |
|
|
484 | |
|
|
485 | In the second form (another port given), the other port (C<$rcvport>) |
|
|
486 | will be C<kil>'ed with C<@reason>, if a @reason was specified, i.e. on |
|
|
487 | "normal" kils nothing happens, while under all other conditions, the other |
|
|
488 | port is killed with the same reason. |
|
|
489 | |
|
|
490 | The third form (kill self) is the same as the second form, except that |
|
|
491 | C<$rvport> defaults to C<$SELF>. |
|
|
492 | |
|
|
493 | In the last form (message), a message of the form C<@msg, @reason> will be |
|
|
494 | C<snd>. |
|
|
495 | |
|
|
496 | Monitoring-actions are one-shot: once messages are lost (and a monitoring |
|
|
497 | alert was raised), they are removed and will not trigger again. |
|
|
498 | |
|
|
499 | As a rule of thumb, monitoring requests should always monitor a port from |
|
|
500 | a local port (or callback). The reason is that kill messages might get |
|
|
501 | lost, just like any other message. Another less obvious reason is that |
|
|
502 | even monitoring requests can get lost (for example, when the connection |
|
|
503 | to the other node goes down permanently). When monitoring a port locally |
|
|
504 | these problems do not exist. |
|
|
505 | |
479 | C<mon> effectively guarantees that, in the absence of hardware failures, |
506 | C<mon> effectively guarantees that, in the absence of hardware failures, |
480 | after starting the monitor, either all messages sent to the port will |
507 | after starting the monitor, either all messages sent to the port will |
481 | arrive, or the monitoring action will be invoked after possible message |
508 | arrive, or the monitoring action will be invoked after possible message |
482 | loss has been detected. No messages will be lost "in between" (after |
509 | loss has been detected. No messages will be lost "in between" (after |
483 | the first lost message no further messages will be received by the |
510 | the first lost message no further messages will be received by the |
484 | port). After the monitoring action was invoked, further messages might get |
511 | port). After the monitoring action was invoked, further messages might get |
485 | delivered again. |
512 | delivered again. |
486 | |
513 | |
487 | Note that monitoring-actions are one-shot: once messages are lost (and a |
514 | Inter-host-connection timeouts and monitoring depend on the transport |
488 | monitoring alert was raised), they are removed and will not trigger again. |
515 | used. The only transport currently implemented is TCP, and AnyEvent::MP |
|
|
516 | relies on TCP to detect node-downs (this can take 10-15 minutes on a |
|
|
517 | non-idle connection, and usually around two hours for idle conenctions). |
489 | |
518 | |
490 | In the first form (callback), the callback is simply called with any |
519 | This means that monitoring is good for program errors and cleaning up |
491 | number of C<@reason> elements (no @reason means that the port was deleted |
520 | stuff eventually, but they are no replacement for a timeout when you need |
492 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
521 | to ensure some maximum latency. |
493 | C<eval> if unsure. |
|
|
494 | |
|
|
495 | In the second form (another port given), the other port (C<$rcvport>) |
|
|
496 | will be C<kil>'ed with C<@reason>, if a @reason was specified, i.e. on |
|
|
497 | "normal" kils nothing happens, while under all other conditions, the other |
|
|
498 | port is killed with the same reason. |
|
|
499 | |
|
|
500 | The third form (kill self) is the same as the second form, except that |
|
|
501 | C<$rvport> defaults to C<$SELF>. |
|
|
502 | |
|
|
503 | In the last form (message), a message of the form C<@msg, @reason> will be |
|
|
504 | C<snd>. |
|
|
505 | |
|
|
506 | As a rule of thumb, monitoring requests should always monitor a port from |
|
|
507 | a local port (or callback). The reason is that kill messages might get |
|
|
508 | lost, just like any other message. Another less obvious reason is that |
|
|
509 | even monitoring requests can get lost (for example, when the connection |
|
|
510 | to the other node goes down permanently). When monitoring a port locally |
|
|
511 | these problems do not exist. |
|
|
512 | |
522 | |
513 | Example: call a given callback when C<$port> is killed. |
523 | Example: call a given callback when C<$port> is killed. |
514 | |
524 | |
515 | mon $port, sub { warn "port died because of <@_>\n" }; |
525 | mon $port, sub { warn "port died because of <@_>\n" }; |
516 | |
526 | |