… | |
… | |
52 | |
52 | |
53 | Initially, nodes are either private (single-process only) or hidden |
53 | Initially, nodes are either private (single-process only) or hidden |
54 | (connected to a master node only). Only when they epxlicitly "become |
54 | (connected to a master node only). Only when they epxlicitly "become |
55 | public" can you send them messages from unrelated other nodes. |
55 | public" can you send them messages from unrelated other nodes. |
56 | |
56 | |
57 | =item noderef - C<host:port,host:port...>, C<id@noderef, C<id> |
57 | =item noderef - C<host:port,host:port...>, C<id@noderef>, C<id> |
58 | |
58 | |
59 | A noderef is a string that either uniquely identifies a given node (for |
59 | A noderef is a string that either uniquely identifies a given node (for |
60 | private and hidden nodes), or contains a recipe on how to reach a given |
60 | private and hidden nodes), or contains a recipe on how to reach a given |
61 | node (for public nodes). |
61 | node (for public nodes). |
62 | |
62 | |
… | |
… | |
172 | that Storable can serialise and deserialise is allowed, and for the local |
172 | that Storable can serialise and deserialise is allowed, and for the local |
173 | node, anything can be passed. |
173 | node, anything can be passed. |
174 | |
174 | |
175 | =cut |
175 | =cut |
176 | |
176 | |
177 | sub snd($@) { |
177 | sub snd(@) { |
178 | my ($noderef, $port) = split /#/, shift, 2; |
178 | my ($noderef, $port) = split /#/, shift, 2; |
179 | |
179 | |
180 | add_node $noderef |
180 | add_node $noderef |
181 | unless exists $NODE{$noderef}; |
181 | unless exists $NODE{$noderef}; |
182 | |
182 | |
… | |
… | |
362 | } |
362 | } |
363 | |
363 | |
364 | $PUBLIC = 1; |
364 | $PUBLIC = 1; |
365 | } |
365 | } |
366 | |
366 | |
|
|
367 | =back |
|
|
368 | |
|
|
369 | =head1 NODE MESSAGES |
|
|
370 | |
|
|
371 | Nodes understand the following messages sent to them. Many of them take |
|
|
372 | arguments called C<@reply>, which will simply be used to compose a reply |
|
|
373 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
|
|
374 | the remaining arguments are simply the message data. |
|
|
375 | |
|
|
376 | =over 4 |
|
|
377 | |
|
|
378 | =cut |
|
|
379 | |
367 | ############################################################################# |
380 | ############################################################################# |
368 | # self node code |
381 | # self node code |
369 | |
382 | |
370 | sub _new_port($) { |
383 | sub _new_port($) { |
371 | my ($name) = @_; |
384 | my ($name) = @_; |
… | |
… | |
379 | } |
392 | } |
380 | |
393 | |
381 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
394 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
382 | _new_port ""; |
395 | _new_port ""; |
383 | |
396 | |
|
|
397 | =item relay => $port, @msg |
|
|
398 | |
|
|
399 | Simply forwards the message to the given port. |
|
|
400 | |
|
|
401 | =cut |
|
|
402 | |
384 | rcv "", relay => \&snd; |
403 | rcv "", relay => \&snd; |
|
|
404 | |
|
|
405 | =item eval => $string[ @reply] |
|
|
406 | |
|
|
407 | Evaluates the given string. If C<@reply> is given, then a message of the |
|
|
408 | form C<@reply, $@, @evalres> is sent. |
|
|
409 | |
|
|
410 | Example: crash another node. |
|
|
411 | |
|
|
412 | snd $othernode, eval => "exit"; |
|
|
413 | |
|
|
414 | =cut |
|
|
415 | |
|
|
416 | rcv "", eval => sub { |
|
|
417 | my (undef, $string, @reply) = @_; |
|
|
418 | my @res = eval $string; |
|
|
419 | snd @reply, "$@", @res if @reply; |
|
|
420 | }; |
|
|
421 | |
|
|
422 | =item time => @reply |
|
|
423 | |
|
|
424 | Replies the the current node time to C<@reply>. |
|
|
425 | |
|
|
426 | Example: tell the current node to send the current time to C<$myport> in a |
|
|
427 | C<timereply> message. |
|
|
428 | |
|
|
429 | snd $NODE, time => $myport, timereply => 1, 2; |
|
|
430 | # => snd $myport, timereply => 1, 2, <time> |
|
|
431 | |
|
|
432 | =cut |
|
|
433 | |
|
|
434 | rcv "", time => sub { shift; snd @_, AE::time }; |
385 | |
435 | |
386 | =back |
436 | =back |
387 | |
437 | |
388 | =head1 SEE ALSO |
438 | =head1 SEE ALSO |
389 | |
439 | |