… | |
… | |
197 | At least one additional noderef is required (either by specifying it |
197 | At least one additional noderef is required (either by specifying it |
198 | directly or because it is part of the configuration profile): The node |
198 | directly or because it is part of the configuration profile): The node |
199 | will try to connect to all of them and will become a slave attached to the |
199 | will try to connect to all of them and will become a slave attached to the |
200 | first node it can successfully connect to. |
200 | first node it can successfully connect to. |
201 | |
201 | |
|
|
202 | Note that slave nodes cannot change their name, and consequently, their |
|
|
203 | master, so if the master goes down, the slave node will not function well |
|
|
204 | anymore until it can re-establish conenciton to its master. This makes |
|
|
205 | slave nodes unsuitable for long-term nodes or fault-tolerant networks. |
|
|
206 | |
202 | =back |
207 | =back |
203 | |
208 | |
204 | This function will block until all nodes have been resolved and, for slave |
209 | This function will block until all nodes have been resolved and, for slave |
205 | nodes, until it has successfully established a connection to a master |
210 | nodes, until it has successfully established a connection to a master |
206 | server. |
211 | server. |
|
|
212 | |
|
|
213 | All the seednodes will also be specially marked to automatically retry |
|
|
214 | connecting to them infinitely. |
207 | |
215 | |
208 | Example: become a public node listening on the guessed noderef, or the one |
216 | Example: become a public node listening on the guessed noderef, or the one |
209 | specified via C<aemp> for the current node. This should be the most common |
217 | specified via C<aemp> for the current node. This should be the most common |
210 | form of invocation for "daemon"-type nodes. |
218 | form of invocation for "daemon"-type nodes. |
211 | |
219 | |
… | |
… | |
666 | my $id = "$RUNIQ." . $ID++; |
674 | my $id = "$RUNIQ." . $ID++; |
667 | |
675 | |
668 | $_[0] =~ /::/ |
676 | $_[0] =~ /::/ |
669 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
677 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
670 | |
678 | |
671 | ($NODE{$noderef} || add_node $noderef) |
679 | snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_; |
672 | ->send (["", "AnyEvent::MP::_spawn" => $id, @_]); |
|
|
673 | |
680 | |
674 | "$noderef#$id" |
681 | "$noderef#$id" |
675 | } |
682 | } |
676 | |
|
|
677 | =back |
|
|
678 | |
|
|
679 | =head1 NODE MESSAGES |
|
|
680 | |
|
|
681 | Nodes understand the following messages sent to them. Many of them take |
|
|
682 | arguments called C<@reply>, which will simply be used to compose a reply |
|
|
683 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
|
|
684 | the remaining arguments are simply the message data. |
|
|
685 | |
|
|
686 | While other messages exist, they are not public and subject to change. |
|
|
687 | |
|
|
688 | =over 4 |
|
|
689 | |
|
|
690 | =cut |
|
|
691 | |
|
|
692 | =item lookup => $name, @reply |
|
|
693 | |
|
|
694 | Replies with the port ID of the specified well-known port, or C<undef>. |
|
|
695 | |
|
|
696 | =item devnull => ... |
|
|
697 | |
|
|
698 | Generic data sink/CPU heat conversion. |
|
|
699 | |
|
|
700 | =item relay => $port, @msg |
|
|
701 | |
|
|
702 | Simply forwards the message to the given port. |
|
|
703 | |
|
|
704 | =item eval => $string[ @reply] |
|
|
705 | |
|
|
706 | Evaluates the given string. If C<@reply> is given, then a message of the |
|
|
707 | form C<@reply, $@, @evalres> is sent. |
|
|
708 | |
|
|
709 | Example: crash another node. |
|
|
710 | |
|
|
711 | snd $othernode, eval => "exit"; |
|
|
712 | |
|
|
713 | =item time => @reply |
|
|
714 | |
|
|
715 | Replies the the current node time to C<@reply>. |
|
|
716 | |
|
|
717 | Example: tell the current node to send the current time to C<$myport> in a |
|
|
718 | C<timereply> message. |
|
|
719 | |
|
|
720 | snd $NODE, time => $myport, timereply => 1, 2; |
|
|
721 | # => snd $myport, timereply => 1, 2, <time> |
|
|
722 | |
683 | |
723 | =back |
684 | =back |
724 | |
685 | |
725 | =head1 AnyEvent::MP vs. Distributed Erlang |
686 | =head1 AnyEvent::MP vs. Distributed Erlang |
726 | |
687 | |