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.53 by root, Fri Aug 14 15:31:21 2009 UTC vs.
Revision 1.57 by root, Sat Aug 15 04:34:34 2009 UTC

197At least one additional noderef is required (either by specifying it 197At least one additional noderef is required (either by specifying it
198directly or because it is part of the configuration profile): The node 198directly or because it is part of the configuration profile): The node
199will try to connect to all of them and will become a slave attached to the 199will try to connect to all of them and will become a slave attached to the
200first node it can successfully connect to. 200first node it can successfully connect to.
201 201
202Note that slave nodes cannot change their name, and consequently, their
203master, so if the master goes down, the slave node will not function well
204anymore until it can re-establish conenciton to its master. This makes
205slave nodes unsuitable for long-term nodes or fault-tolerant networks.
206
202=back 207=back
203 208
204This function will block until all nodes have been resolved and, for slave 209This function will block until all nodes have been resolved and, for slave
205nodes, until it has successfully established a connection to a master 210nodes, until it has successfully established a connection to a master
206server. 211server.
212
213All the seednodes will also be specially marked to automatically retry
214connecting to them infinitely.
207 215
208Example: become a public node listening on the guessed noderef, or the one 216Example: become a public node listening on the guessed noderef, or the one
209specified via C<aemp> for the current node. This should be the most common 217specified via C<aemp> for the current node. This should be the most common
210form of invocation for "daemon"-type nodes. 218form of invocation for "daemon"-type nodes.
211 219
348The default callback received all messages not matched by a more specific 356The default callback received all messages not matched by a more specific
349C<tag> match. 357C<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
353Register callbacks to be called on messages starting with the given tag on 361Register (or replace) callbacks to be called on messages starting with the
354the given port (and return the port), or unregister it (when C<$callback> 362given tag on the given port (and return the port), or unregister it (when
355is C<$undef>). 363C<$callback> is C<$undef> or missing). There can only be one callback
364registered for each tag.
356 365
357The original message will be passed to the callback, after the first 366The original message will be passed to the callback, after the first
358element (the tag) has been removed. The callback will use the same 367element (the tag) has been removed. The callback will use the same
359environment as the default callback (see above). 368environment 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
386Example: 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
379sub rcv($@) { 397sub 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
671Nodes understand the following messages sent to them. Many of them take
672arguments called C<@reply>, which will simply be used to compose a reply
673message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and
674the remaining arguments are simply the message data.
675
676While 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
684Replies with the port ID of the specified well-known port, or C<undef>.
685
686=item devnull => ...
687
688Generic data sink/CPU heat conversion.
689
690=item relay => $port, @msg
691
692Simply forwards the message to the given port.
693
694=item eval => $string[ @reply]
695
696Evaluates the given string. If C<@reply> is given, then a message of the
697form C<@reply, $@, @evalres> is sent.
698
699Example: crash another node.
700
701 snd $othernode, eval => "exit";
702
703=item time => @reply
704
705Replies the the current node time to C<@reply>.
706
707Example: tell the current node to send the current time to C<$myport> in a
708C<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
735convenience functionality. 706convenience functionality.
736 707
737This means that AEMP requires a less tightly controlled environment at the 708This means that AEMP requires a less tightly controlled environment at the
738cost of longer node references and a slightly higher management overhead. 709cost 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
741uses "local ports are like remote ports". 712uses "local ports are like remote ports".
742 713
743The failure modes for local ports are quite different (runtime errors 714The failure modes for local ports are quite different (runtime errors
744only) then for remote ports - when a local port dies, you I<know> it dies, 715only) then for remote ports - when a local port dies, you I<know> it dies,
745when a connection to another node dies, you know nothing about the other 716when a connection to another node dies, you know nothing about the other

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines