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.54 by root, Fri Aug 14 16:15:37 2009 UTC vs.
Revision 1.58 by root, Sun Aug 16 02:55:16 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
388 396
389sub rcv($@) { 397sub rcv($@) {
390 my $port = shift; 398 my $port = shift;
391 my ($noderef, $portid) = split /#/, $port, 2; 399 my ($noderef, $portid) = split /#/, $port, 2;
392 400
393 ($NODE{$noderef} || add_node $noderef) == $NODE{""} 401 $NODE{$noderef} == $NODE{""}
394 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";
395 403
396 while (@_) { 404 while (@_) {
397 if (ref $_[0]) { 405 if (ref $_[0]) {
398 if (my $self = $PORT_DATA{$portid}) { 406 if (my $self = $PORT_DATA{$portid}) {
497message loss has been detected. No messages will be lost "in between" 505message loss has been detected. No messages will be lost "in between"
498(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
499port). After the monitoring action was invoked, further messages might get 507port). After the monitoring action was invoked, further messages might get
500delivered again. 508delivered again.
501 509
510Note that monitoring-actions are one-shot: once released, they are removed
511and will not trigger again.
512
502In the first form (callback), the callback is simply called with any 513In the first form (callback), the callback is simply called with any
503number of C<@reason> elements (no @reason means that the port was deleted 514number of C<@reason> elements (no @reason means that the port was deleted
504"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
505C<eval> if unsure. 516C<eval> if unsure.
506 517
666 my $id = "$RUNIQ." . $ID++; 677 my $id = "$RUNIQ." . $ID++;
667 678
668 $_[0] =~ /::/ 679 $_[0] =~ /::/
669 or Carp::croak "spawn init function must be a fully-qualified name, caught"; 680 or Carp::croak "spawn init function must be a fully-qualified name, caught";
670 681
671 ($NODE{$noderef} || add_node $noderef) 682 snd_to_func $noderef, "AnyEvent::MP::_spawn" => $id, @_;
672 ->send (["", "AnyEvent::MP::_spawn" => $id, @_]);
673 683
674 "$noderef#$id" 684 "$noderef#$id"
675} 685}
676
677=back
678
679=head1 NODE MESSAGES
680
681Nodes understand the following messages sent to them. Many of them take
682arguments called C<@reply>, which will simply be used to compose a reply
683message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and
684the remaining arguments are simply the message data.
685
686While 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
694Replies with the port ID of the specified well-known port, or C<undef>.
695
696=item devnull => ...
697
698Generic data sink/CPU heat conversion.
699
700=item relay => $port, @msg
701
702Simply forwards the message to the given port.
703
704=item eval => $string[ @reply]
705
706Evaluates the given string. If C<@reply> is given, then a message of the
707form C<@reply, $@, @evalres> is sent.
708
709Example: crash another node.
710
711 snd $othernode, eval => "exit";
712
713=item time => @reply
714
715Replies the the current node time to C<@reply>.
716
717Example: tell the current node to send the current time to C<$myport> in a
718C<timereply> message.
719
720 snd $NODE, time => $myport, timereply => 1, 2;
721 # => snd $myport, timereply => 1, 2, <time>
722 686
723=back 687=back
724 688
725=head1 AnyEvent::MP vs. Distributed Erlang 689=head1 AnyEvent::MP vs. Distributed Erlang
726 690

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines