… | |
… | |
12 | |
12 | |
13 | This module provides an assortment of network-global functions: group name |
13 | This module provides an assortment of network-global functions: group name |
14 | registration and non-local locks. |
14 | registration and non-local locks. |
15 | |
15 | |
16 | It will also try to build and maintain a full mesh of all network nodes. |
16 | It will also try to build and maintain a full mesh of all network nodes. |
|
|
17 | |
|
|
18 | While it isn't mandatory to run the global services, running it on one |
|
|
19 | node will automatically run it on all nodes. |
17 | |
20 | |
18 | =head1 GLOBALS AND FUNCTIONS |
21 | =head1 GLOBALS AND FUNCTIONS |
19 | |
22 | |
20 | =over 4 |
23 | =over 4 |
21 | |
24 | |
… | |
… | |
31 | use AnyEvent::MP::Kernel; |
34 | use AnyEvent::MP::Kernel; |
32 | |
35 | |
33 | our $VERSION = $AnyEvent::MP::VERSION; |
36 | our $VERSION = $AnyEvent::MP::VERSION; |
34 | |
37 | |
35 | our $port = port; |
38 | our $port = port; |
|
|
39 | our %other; # our rendevouz port on the other side |
36 | |
40 | |
37 | # in response to up_nodes request |
41 | sub connect { |
|
|
42 | my ($noderef) = @_; |
|
|
43 | |
|
|
44 | # monitor them, silently die |
|
|
45 | mon $noderef, psub { kil $SELF }; |
|
|
46 | |
38 | rcv $port, connect_nodes => sub { |
47 | rcv $SELF, connect_nodes => sub { |
39 | connect_node $_ for @_; |
48 | connect_node $_ for @_; |
40 | }; |
49 | }; |
|
|
50 | } |
41 | |
51 | |
42 | sub mon_node { |
52 | sub mon_node { |
43 | my ($noderef, $is_up) = @_; |
53 | my ($noderef, $is_up) = @_; |
44 | |
54 | |
45 | if ($is_up) { |
55 | if ($is_up) { |
|
|
56 | # establish connection |
|
|
57 | my $other = $other{$noderef} = spawn $noderef, "AnyEvent::MP::Global::connect", $NODE; |
46 | # request any other nodes possibly known to us |
58 | # request any other nodes possibly known to us |
47 | snd $noderef, up_nodes => $port, "connect_nodes"; |
59 | snd $other, connect_nodes => up_nodes; |
48 | } else { |
60 | } else { |
|
|
61 | kil delete $other{$noderef}; |
49 | } |
62 | } |
50 | #warn "node<$noderef,$is_up>\n";#d# |
63 | #warn "node<$noderef,$is_up>\n";#d# |
51 | } |
64 | } |
52 | |
65 | |
53 | mon_node $_, 1 |
66 | mon_node $_, 1 |