… | |
… | |
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 | |
… | |
… | |
348 | The default callback received all messages not matched by a more specific |
356 | The default callback received all messages not matched by a more specific |
349 | C<tag> match. |
357 | C<tag> match. |
350 | |
358 | |
351 | =item rcv $local_port, tag => $callback->(@msg_without_tag), ... |
359 | =item rcv $local_port, tag => $callback->(@msg_without_tag), ... |
352 | |
360 | |
353 | Register callbacks to be called on messages starting with the given tag on |
361 | Register (or replace) callbacks to be called on messages starting with the |
354 | the given port (and return the port), or unregister it (when C<$callback> |
362 | given tag on the given port (and return the port), or unregister it (when |
355 | is C<$undef>). |
363 | C<$callback> is C<$undef> or missing). There can only be one callback |
|
|
364 | registered for each tag. |
356 | |
365 | |
357 | The original message will be passed to the callback, after the first |
366 | The original message will be passed to the callback, after the first |
358 | element (the tag) has been removed. The callback will use the same |
367 | element (the tag) has been removed. The callback will use the same |
359 | environment as the default callback (see above). |
368 | environment as the default callback (see above). |
360 | |
369 | |
… | |
… | |
371 | snd $otherport, reply => |
380 | snd $otherport, reply => |
372 | rcv port, |
381 | rcv port, |
373 | msg1 => sub { ... }, |
382 | msg1 => sub { ... }, |
374 | ... |
383 | ... |
375 | ; |
384 | ; |
|
|
385 | |
|
|
386 | Example: temporarily register a rcv callback for a tag matching some port |
|
|
387 | (e.g. for a rpc reply) and unregister it after a message was received. |
|
|
388 | |
|
|
389 | rcv $port, $otherport => sub { |
|
|
390 | my @reply = @_; |
|
|
391 | |
|
|
392 | rcv $SELF, $otherport; |
|
|
393 | }; |
376 | |
394 | |
377 | =cut |
395 | =cut |
378 | |
396 | |
379 | sub rcv($@) { |
397 | sub rcv($@) { |
380 | my $port = shift; |
398 | my $port = shift; |
… | |
… | |
656 | my $id = "$RUNIQ." . $ID++; |
674 | my $id = "$RUNIQ." . $ID++; |
657 | |
675 | |
658 | $_[0] =~ /::/ |
676 | $_[0] =~ /::/ |
659 | 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"; |
660 | |
678 | |
661 | ($NODE{$noderef} || add_node $noderef) |
679 | snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_; |
662 | ->send (["", "AnyEvent::MP::_spawn" => $id, @_]); |
|
|
663 | |
680 | |
664 | "$noderef#$id" |
681 | "$noderef#$id" |
665 | } |
682 | } |
666 | |
|
|
667 | =back |
|
|
668 | |
|
|
669 | =head1 NODE MESSAGES |
|
|
670 | |
|
|
671 | Nodes understand the following messages sent to them. Many of them take |
|
|
672 | arguments called C<@reply>, which will simply be used to compose a reply |
|
|
673 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
|
|
674 | the remaining arguments are simply the message data. |
|
|
675 | |
|
|
676 | While other messages exist, they are not public and subject to change. |
|
|
677 | |
|
|
678 | =over 4 |
|
|
679 | |
|
|
680 | =cut |
|
|
681 | |
|
|
682 | =item lookup => $name, @reply |
|
|
683 | |
|
|
684 | Replies with the port ID of the specified well-known port, or C<undef>. |
|
|
685 | |
|
|
686 | =item devnull => ... |
|
|
687 | |
|
|
688 | Generic data sink/CPU heat conversion. |
|
|
689 | |
|
|
690 | =item relay => $port, @msg |
|
|
691 | |
|
|
692 | Simply forwards the message to the given port. |
|
|
693 | |
|
|
694 | =item eval => $string[ @reply] |
|
|
695 | |
|
|
696 | Evaluates the given string. If C<@reply> is given, then a message of the |
|
|
697 | form C<@reply, $@, @evalres> is sent. |
|
|
698 | |
|
|
699 | Example: crash another node. |
|
|
700 | |
|
|
701 | snd $othernode, eval => "exit"; |
|
|
702 | |
|
|
703 | =item time => @reply |
|
|
704 | |
|
|
705 | Replies the the current node time to C<@reply>. |
|
|
706 | |
|
|
707 | Example: tell the current node to send the current time to C<$myport> in a |
|
|
708 | C<timereply> message. |
|
|
709 | |
|
|
710 | snd $NODE, time => $myport, timereply => 1, 2; |
|
|
711 | # => snd $myport, timereply => 1, 2, <time> |
|
|
712 | |
683 | |
713 | =back |
684 | =back |
714 | |
685 | |
715 | =head1 AnyEvent::MP vs. Distributed Erlang |
686 | =head1 AnyEvent::MP vs. Distributed Erlang |
716 | |
687 | |
… | |
… | |
735 | convenience functionality. |
706 | convenience functionality. |
736 | |
707 | |
737 | This means that AEMP requires a less tightly controlled environment at the |
708 | This means that AEMP requires a less tightly controlled environment at the |
738 | cost of longer node references and a slightly higher management overhead. |
709 | cost of longer node references and a slightly higher management overhead. |
739 | |
710 | |
740 | =item Erlang has a "remote ports are like local ports" philosophy, AEMP |
711 | =item * Erlang has a "remote ports are like local ports" philosophy, AEMP |
741 | uses "local ports are like remote ports". |
712 | uses "local ports are like remote ports". |
742 | |
713 | |
743 | The failure modes for local ports are quite different (runtime errors |
714 | The failure modes for local ports are quite different (runtime errors |
744 | only) then for remote ports - when a local port dies, you I<know> it dies, |
715 | only) then for remote ports - when a local port dies, you I<know> it dies, |
745 | when a connection to another node dies, you know nothing about the other |
716 | when a connection to another node dies, you know nothing about the other |