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.58 by root, Wed Mar 14 22:59:58 2012 UTC vs.
Revision 1.59 by root, Wed Mar 21 15:22:16 2012 UTC

51 51
52our %GLOBAL_DB; # global db 52our %GLOBAL_DB; # global db
53our %LOCAL_DBS; # local databases of other global nodes 53our %LOCAL_DBS; # local databases of other global nodes
54our %LOCAL_DB; # this node database 54our %LOCAL_DB; # this node database
55 55
56our $SRCNODE; 56our $SRCNODE; # the origin node id
57our %NODE_REQ; 57our %NODE_REQ;
58 58
59# only in global code 59# only in global code
60our %GLOBAL_MON; # monitors {family} 60our %GLOBAL_MON; # monitors {family}
61 61
142# other node wants to make us the master 142# other node wants to make us the master
143$NODE_REQ{g_slave} = sub { 143$NODE_REQ{g_slave} = sub {
144 my ($db) = @_ 144 my ($db) = @_
145 or return; # empty g_slave is used to start global service 145 or return; # empty g_slave is used to start global service
146 146
147 my $node = $SRCNODE->{id}; 147 my $node = $SRCNODE;
148 undef $GLOBAL_SLAVE{$node}; 148 undef $GLOBAL_SLAVE{$node};
149 g_set $node, $db; 149 g_set $node, $db;
150}; 150};
151 151
152$NODE_REQ{g_set} = sub { 152$NODE_REQ{g_set} = sub {
153 g_set $SRCNODE->{id}, @_; 153 g_set $SRCNODE, @_;
154}; 154};
155 155
156$NODE_REQ{g_upd} = sub { 156$NODE_REQ{g_upd} = sub {
157 g_upd $SRCNODE->{id}, @_; 157 g_upd $SRCNODE, @_;
158}; 158};
159 159
160$NODE_REQ{g_find} = sub { 160$NODE_REQ{g_find} = sub {
161 my ($node) = @_; 161 my ($node) = @_;
162 162
163 snd $SRCNODE->{id}, g_found => $node, $GLOBAL_DB{"'l"}{$node}; 163 snd $SRCNODE, g_found => $node, $GLOBAL_DB{"'l"}{$node};
164}; 164};
165 165
166$NODE_REQ{g_db_family} = sub { 166$NODE_REQ{g_db_family} = sub {
167 my ($family, $id) = @_; 167 my ($family, $id) = @_;
168 snd $SRCNODE->{id}, g_reply => $id, $GLOBAL_DB{$family} || {}; 168 snd $SRCNODE, g_reply => $id, $GLOBAL_DB{$family} || {};
169}; 169};
170 170
171$NODE_REQ{g_db_keys} = sub { 171$NODE_REQ{g_db_keys} = sub {
172 my ($family, $id) = @_; 172 my ($family, $id) = @_;
173 snd $SRCNODE->{id}, g_reply => $id, [keys %{ $GLOBAL_DB{$family} } ]; 173 snd $SRCNODE, g_reply => $id, [keys %{ $GLOBAL_DB{$family} } ];
174}; 174};
175 175
176$NODE_REQ{g_db_values} = sub { 176$NODE_REQ{g_db_values} = sub {
177 my ($family, $id) = @_; 177 my ($family, $id) = @_;
178 snd $SRCNODE->{id}, g_reply => $id, [values %{ $GLOBAL_DB{$family} } ]; 178 snd $SRCNODE, g_reply => $id, [values %{ $GLOBAL_DB{$family} } ];
179}; 179};
180 180
181# monitoring 181# monitoring
182 182
183sub g_slave_disconnect($) { 183sub g_slave_disconnect($) {
196 } 196 }
197} 197}
198 198
199# g_mon0 family - stop monitoring 199# g_mon0 family - stop monitoring
200$NODE_REQ{g_mon0} = sub { 200$NODE_REQ{g_mon0} = sub {
201 delete $GLOBAL_MON{$_[0]}{$SRCNODE->{id}}; 201 delete $GLOBAL_MON{$_[0]}{$SRCNODE};
202 delete $GLOBAL_MON{$_[0]} unless %{ $GLOBAL_MON{$_[0]} }; 202 delete $GLOBAL_MON{$_[0]} unless %{ $GLOBAL_MON{$_[0]} };
203 203
204 delete $GLOBAL_SLAVE{$SRCNODE->{id}}{$_[0]}; 204 delete $GLOBAL_SLAVE{$SRCNODE}{$_[0]};
205}; 205};
206 206
207# g_mon1 family key - start monitoring 207# g_mon1 family key - start monitoring
208$NODE_REQ{g_mon1} = sub { 208$NODE_REQ{g_mon1} = sub {
209 undef $GLOBAL_SLAVE{$SRCNODE->{id}}{$_[0]}; 209 undef $GLOBAL_SLAVE{$SRCNODE}{$_[0]};
210 undef $GLOBAL_MON{$_[0]}{$SRCNODE->{id}}; 210 undef $GLOBAL_MON{$_[0]}{$SRCNODE};
211 211
212 snd $SRCNODE->{id}, g_chg1 => $_[0], $GLOBAL_DB{$_[0]}; 212 snd $SRCNODE, g_chg1 => $_[0], $GLOBAL_DB{$_[0]};
213}; 213};
214 214
215############################################################################# 215#############################################################################
216# switch to global mode 216# switch to global mode
217 217
278 g_global_connect $_->{id}; 278 g_global_connect $_->{id};
279 } 279 }
280} 280}
281 281
282$NODE_REQ{g_global} = sub { 282$NODE_REQ{g_global} = sub {
283 g_slave_disconnect $SRCNODE->{id}; 283 g_slave_disconnect $SRCNODE;
284
285 my $node = $NODE{$SRCNODE};
284 $SRCNODE->{transport}{remote_greeting}{global} = 1; 286 $node->{transport}{remote_greeting}{global} = 1;
287
285 g_global_connect $SRCNODE->{id}; 288 g_global_connect $SRCNODE;
286}; 289};
287 290
288# enable global mode 291# enable global mode
289$GLOBAL = 1; 292$GLOBAL = 1;
290 293

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines