ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Global.pm
(Generate patch)

Comparing AnyEvent-MP/MP/Global.pm (file contents):
Revision 1.2 by root, Sat Aug 15 04:12:38 2009 UTC vs.
Revision 1.3 by root, Sat Aug 15 04:34:34 2009 UTC

12 12
13This module provides an assortment of network-global functions: group name 13This module provides an assortment of network-global functions: group name
14registration and non-local locks. 14registration and non-local locks.
15 15
16It will also try to build and maintain a full mesh of all network nodes. 16It will also try to build and maintain a full mesh of all network nodes.
17
18While it isn't mandatory to run the global services, running it on one
19node 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
31use AnyEvent::MP::Kernel; 34use AnyEvent::MP::Kernel;
32 35
33our $VERSION = $AnyEvent::MP::VERSION; 36our $VERSION = $AnyEvent::MP::VERSION;
34 37
35our $port = port; 38our $port = port;
39our %other; # our rendevouz port on the other side
36 40
37# in response to up_nodes request 41sub connect {
42 my ($noderef) = @_;
43
44 # monitor them, silently die
45 mon $noderef, psub { kil $SELF };
46
38rcv $port, connect_nodes => sub { 47 rcv $SELF, connect_nodes => sub {
39 connect_node $_ for @_; 48 connect_node $_ for @_;
40}; 49 };
50}
41 51
42sub mon_node { 52sub 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
53mon_node $_, 1 66mon_node $_, 1

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines