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.4 by root, Sun Aug 16 02:55:17 2009 UTC vs.
Revision 1.5 by root, Sun Aug 16 05:02:24 2009 UTC

40our %port; # our rendezvous port on the other side 40our %port; # our rendezvous port on the other side
41our %lreg; # local registry, name => [pid...] 41our %lreg; # local registry, name => [pid...]
42our %lmon; # local rgeistry monitoring name,pid => mon 42our %lmon; # local rgeistry monitoring name,pid => mon
43our %greg; # global regstry, name => [pid...] 43our %greg; # global regstry, name => [pid...]
44 44
45$AnyEvent::MP::Kernel::WARN->(7, "starting global service.");
46
45sub unreg_groups($) { 47sub unreg_groups($) {
46 my ($noderef) = @_; 48 my ($noderef) = @_;
47 49
48 my $qr = qr/^\Q$noderef\E(?:#|$)/; 50 my $qr = qr/^\Q$noderef\E(?:#|$)/;
49 51
52 } 54 }
53} 55}
54 56
55sub set_groups($$) { 57sub set_groups($$) {
56 my ($noderef, $lreg) = @_; 58 my ($noderef, $lreg) = @_;
59
60 use Data::Dumper; warn Dumper $lreg;#d#
57} 61}
58 62
59=item $guard = register $port, $group 63=item $guard = register $port, $group
60 64
61Register the given (local!) port in the named global group C<$group>. 65Register the given (local!) port in the named global group C<$group>.
107 111
108sub start_node { 112sub start_node {
109 my ($noderef) = @_; 113 my ($noderef) = @_;
110 114
111 return if exists $port{$noderef}; 115 return if exists $port{$noderef};
116 return if $noderef eq $NODE; # do not connect to ourselves
112 117
113 # establish connection 118 # establish connection
114 my $port = $port{$noderef} = spawn $noderef, "AnyEvent::MP::Global::connect", $NODE; 119 my $port = $port{$noderef} = spawn $noderef, "AnyEvent::MP::Global::connect", 0, $NODE;
115 # request any other nodes possibly known to us 120 # request any other nodes possibly known to us
116 mon $port, sub { 121 mon $port, sub {
117 unreg_groups $noderef; 122 unreg_groups $noderef;
118 delete $port{$noderef}; 123 delete $port{$noderef};
119 }; 124 };
120 snd $port, connect_nodes => up_nodes; 125 snd $port, connect_nodes => up_nodes;
121 snd $port, set => \%greg; 126 snd $port, set => \%greg;
122} 127}
123 128
129# other nodes connect via this
124sub connect { 130sub connect {
125 my ($noderef) = @_; 131 my ($version, $noderef) = @_;
126 132
127 # monitor them, silently die 133 # monitor them, silently die
128 mon $noderef, psub { kil $SELF }; 134 mon $noderef, psub { kil $SELF };
129 135
130 warn "$SELF,$NODE\n";#d#
131 rcv $SELF, 136 rcv $SELF,
132 connect_nodes => sub { 137 connect_nodes => sub {
133 for (@_) { 138 for (@_) {
134 connect_node $_; 139 connect_node $_;
135 start_node $_; 140 start_node $_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines