… | |
… | |
396 | |
396 | |
397 | sub rcv($@) { |
397 | sub rcv($@) { |
398 | my $port = shift; |
398 | my $port = shift; |
399 | my ($noderef, $portid) = split /#/, $port, 2; |
399 | my ($noderef, $portid) = split /#/, $port, 2; |
400 | |
400 | |
401 | ($NODE{$noderef} || add_node $noderef) == $NODE{""} |
401 | $NODE{$noderef} == $NODE{""} |
402 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
402 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
403 | |
403 | |
404 | while (@_) { |
404 | while (@_) { |
405 | if (ref $_[0]) { |
405 | if (ref $_[0]) { |
406 | if (my $self = $PORT_DATA{$portid}) { |
406 | if (my $self = $PORT_DATA{$portid}) { |
… | |
… | |
505 | message loss has been detected. No messages will be lost "in between" |
505 | message loss has been detected. No messages will be lost "in between" |
506 | (after the first lost message no further messages will be received by the |
506 | (after the first lost message no further messages will be received by the |
507 | port). After the monitoring action was invoked, further messages might get |
507 | port). After the monitoring action was invoked, further messages might get |
508 | delivered again. |
508 | delivered again. |
509 | |
509 | |
|
|
510 | Note that monitoring-actions are one-shot: once released, they are removed |
|
|
511 | and will not trigger again. |
|
|
512 | |
510 | In the first form (callback), the callback is simply called with any |
513 | In the first form (callback), the callback is simply called with any |
511 | number of C<@reason> elements (no @reason means that the port was deleted |
514 | number of C<@reason> elements (no @reason means that the port was deleted |
512 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
515 | "normally"). Note also that I<< the callback B<must> never die >>, so use |
513 | C<eval> if unsure. |
516 | C<eval> if unsure. |
514 | |
517 | |
… | |
… | |
681 | "$noderef#$id" |
684 | "$noderef#$id" |
682 | } |
685 | } |
683 | |
686 | |
684 | =back |
687 | =back |
685 | |
688 | |
686 | =head1 NODE MESSAGES |
|
|
687 | |
|
|
688 | Nodes understand the following messages sent to them. Many of them take |
|
|
689 | arguments called C<@reply>, which will simply be used to compose a reply |
|
|
690 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
|
|
691 | the remaining arguments are simply the message data. |
|
|
692 | |
|
|
693 | While other messages exist, they are not public and subject to change. |
|
|
694 | |
|
|
695 | =over 4 |
|
|
696 | |
|
|
697 | =cut |
|
|
698 | |
|
|
699 | =item lookup => $name, @reply |
|
|
700 | |
|
|
701 | Replies with the port ID of the specified well-known port, or C<undef>. |
|
|
702 | |
|
|
703 | =item devnull => ... |
|
|
704 | |
|
|
705 | Generic data sink/CPU heat conversion. |
|
|
706 | |
|
|
707 | =item relay => $port, @msg |
|
|
708 | |
|
|
709 | Simply forwards the message to the given port. |
|
|
710 | |
|
|
711 | =item eval => $string[ @reply] |
|
|
712 | |
|
|
713 | Evaluates the given string. If C<@reply> is given, then a message of the |
|
|
714 | form C<@reply, $@, @evalres> is sent. |
|
|
715 | |
|
|
716 | Example: crash another node. |
|
|
717 | |
|
|
718 | snd $othernode, eval => "exit"; |
|
|
719 | |
|
|
720 | =item time => @reply |
|
|
721 | |
|
|
722 | Replies the the current node time to C<@reply>. |
|
|
723 | |
|
|
724 | Example: tell the current node to send the current time to C<$myport> in a |
|
|
725 | C<timereply> message. |
|
|
726 | |
|
|
727 | snd $NODE, time => $myport, timereply => 1, 2; |
|
|
728 | # => snd $myport, timereply => 1, 2, <time> |
|
|
729 | |
|
|
730 | =back |
|
|
731 | |
|
|
732 | =head1 AnyEvent::MP vs. Distributed Erlang |
689 | =head1 AnyEvent::MP vs. Distributed Erlang |
733 | |
690 | |
734 | AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node |
691 | AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node |
735 | == aemp node, Erlang process == aemp port), so many of the documents and |
692 | == aemp node, Erlang process == aemp port), so many of the documents and |
736 | programming techniques employed by Erlang apply to AnyEvent::MP. Here is a |
693 | programming techniques employed by Erlang apply to AnyEvent::MP. Here is a |