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

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.40 by root, Sat Aug 8 00:22:16 2009 UTC vs.
Revision 1.45 by root, Thu Aug 13 01:16:24 2009 UTC

38 # monitoring 38 # monitoring
39 mon $port, $cb->(@msg) # callback is invoked on death 39 mon $port, $cb->(@msg) # callback is invoked on death
40 mon $port, $otherport # kill otherport on abnormal death 40 mon $port, $otherport # kill otherport on abnormal death
41 mon $port, $otherport, @msg # send message on death 41 mon $port, $otherport, @msg # send message on death
42 42
43=head1 CURRENT STATUS
44
45 AnyEvent::MP - stable API, should work
46 AnyEvent::MP::Intro - outdated
47 AnyEvent::MP::Kernel - WIP
48 AnyEvent::MP::Transport - mostly stable
49
50 stay tuned.
51
43=head1 DESCRIPTION 52=head1 DESCRIPTION
44 53
45This module (-family) implements a simple message passing framework. 54This module (-family) implements a simple message passing framework.
46 55
47Despite its simplicity, you can securely message other processes running 56Despite its simplicity, you can securely message other processes running
50For an introduction to this module family, see the L<AnyEvent::MP::Intro> 59For an introduction to this module family, see the L<AnyEvent::MP::Intro>
51manual page. 60manual page.
52 61
53At the moment, this module family is severly broken and underdocumented, 62At the moment, this module family is severly broken and underdocumented,
54so do not use. This was uploaded mainly to reserve the CPAN namespace - 63so do not use. This was uploaded mainly to reserve the CPAN namespace -
55stay tuned! The basic API should be finished, however. 64stay tuned!
56 65
57=head1 CONCEPTS 66=head1 CONCEPTS
58 67
59=over 4 68=over 4
60 69
105 114
106=cut 115=cut
107 116
108package AnyEvent::MP; 117package AnyEvent::MP;
109 118
110use AnyEvent::MP::Base; 119use AnyEvent::MP::Kernel;
111 120
112use common::sense; 121use common::sense;
113 122
114use Carp (); 123use Carp ();
115 124
116use AE (); 125use AE ();
117 126
118use base "Exporter"; 127use base "Exporter";
119 128
120our $VERSION = '0.1'; 129our $VERSION = $AnyEvent::MP::Kernel::VERSION;
130
121our @EXPORT = qw( 131our @EXPORT = qw(
122 NODE $NODE *SELF node_of _any_ 132 NODE $NODE *SELF node_of _any_
123 resolve_node initialise_node 133 resolve_node initialise_node
124 snd rcv mon kil reg psub spawn 134 snd rcv mon kil reg psub spawn
125 port 135 port
501 511
502=item $guard = mon $port 512=item $guard = mon $port
503 513
504=item $guard = mon $port, $rcvport, @msg 514=item $guard = mon $port, $rcvport, @msg
505 515
506Monitor the given port and do something when the port is killed, and 516Monitor the given port and do something when the port is killed or
507optionally return a guard that can be used to stop monitoring again. 517messages to it were lost, and optionally return a guard that can be used
518to stop monitoring again.
519
520C<mon> effectively guarantees that, in the absence of hardware failures,
521that after starting the monitor, either all messages sent to the port
522will arrive, or the monitoring action will be invoked after possible
523message loss has been detected. No messages will be lost "in between"
524(after the first lost message no further messages will be received by the
525port). After the monitoring action was invoked, further messages might get
526delivered again.
508 527
509In the first form (callback), the callback is simply called with any 528In the first form (callback), the callback is simply called with any
510number of C<@reason> elements (no @reason means that the port was deleted 529number of C<@reason> elements (no @reason means that the port was deleted
511"normally"). Note also that I<< the callback B<must> never die >>, so use 530"normally"). Note also that I<< the callback B<must> never die >>, so use
512C<eval> if unsure. 531C<eval> if unsure.
513 532
514In the second form (another port given), the other port (C<$rcvport) 533In the second form (another port given), the other port (C<$rcvport>)
515will be C<kil>'ed with C<@reason>, iff a @reason was specified, i.e. on 534will be C<kil>'ed with C<@reason>, iff a @reason was specified, i.e. on
516"normal" kils nothing happens, while under all other conditions, the other 535"normal" kils nothing happens, while under all other conditions, the other
517port is killed with the same reason. 536port is killed with the same reason.
518 537
519The third form (kill self) is the same as the second form, except that 538The third form (kill self) is the same as the second form, except that
546sub mon { 565sub mon {
547 my ($noderef, $port) = split /#/, shift, 2; 566 my ($noderef, $port) = split /#/, shift, 2;
548 567
549 my $node = $NODE{$noderef} || add_node $noderef; 568 my $node = $NODE{$noderef} || add_node $noderef;
550 569
551 my $cb = @_ ? $_[0] : $SELF || Carp::croak 'mon: called with one argument only, but $SELF not set,'; 570 my $cb = @_ ? shift : $SELF || Carp::croak 'mon: called with one argument only, but $SELF not set,';
552 571
553 unless (ref $cb) { 572 unless (ref $cb) {
554 if (@_) { 573 if (@_) {
555 # send a kill info message 574 # send a kill info message
556 my (@msg) = @_; 575 my (@msg) = ($cb, @_);
557 $cb = sub { snd @msg, @_ }; 576 $cb = sub { snd @msg, @_ };
558 } else { 577 } else {
559 # simply kill other port 578 # simply kill other port
560 my $port = $cb; 579 my $port = $cb;
561 $cb = sub { kil $port, @_ if @_ }; 580 $cb = sub { kil $port, @_ if @_ };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines