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

Comparing AnyEvent-MP/MP/Kernel.pm (file contents):
Revision 1.79 by root, Sat Mar 3 11:38:43 2012 UTC vs.
Revision 1.80 by root, Sat Mar 3 13:07:19 2012 UTC

319=cut 319=cut
320 320
321sub node_is_up($) { 321sub node_is_up($) {
322 ($NODE{$_[0]} or return)->{transport} 322 ($NODE{$_[0]} or return)->{transport}
323 ? 1 : 0 323 ? 1 : 0
324}
325
326=item known_nodes
327
328#TODO#
329Returns the node IDs of all nodes currently known to this node, including
330itself and nodes not currently connected.
331
332=cut
333
334sub known_nodes() {
335 map $_->{id}, values %NODE
336} 324}
337 325
338=item up_nodes 326=item up_nodes
339 327
340Return the node IDs of all nodes that are currently connected (excluding 328Return the node IDs of all nodes that are currently connected (excluding
608 596
609# master requests 597# master requests
610our %GLOBAL_REQ; # $id => \@req 598our %GLOBAL_REQ; # $id => \@req
611 599
612sub global_req_add { 600sub global_req_add {
613 my $id = shift; 601 my ($id, $req) = @_;
614 602
615 return if exists $GLOBAL_REQ{$id}; 603 return if exists $GLOBAL_REQ{$id};
616 604
617 $GLOBAL_REQ{$id} = [@_]; 605 $GLOBAL_REQ{$id} = $req;
618 606
619 snd $MASTER, @_ 607 snd $MASTER, @$req
620 if $MASTER; 608 if $MASTER;
621} 609}
622 610
623sub global_req_del { 611sub global_req_del {
624 delete $GLOBAL_REQ{$_[0]}; 612 delete $GLOBAL_REQ{$_[0]};
625} 613}
626 614
627sub g_find { 615sub g_find {
628 global_req_add "g_find $_[0]", g_find => $_[0]; 616 global_req_add "g_find $_[0]", [g_find => $_[0]];
629} 617}
630 618
631# reply for g_find started in Node.pm 619# reply for g_find started in Node.pm
632$NODE_REQ{g_found} = sub { 620$NODE_REQ{g_found} = sub {
633 global_req_del "g_find $_[0]"; 621 global_req_del "g_find $_[0]";
673 661
674# other node wants to make us the master 662# other node wants to make us the master
675$NODE_REQ{g_slave} = sub { 663$NODE_REQ{g_slave} = sub {
676 my ($db) = @_; 664 my ($db) = @_;
677 665
678 warn "slave1\n";#d# 666 # load global module and redo the request
679
680 require AnyEvent::MP::Global; 667 require AnyEvent::MP::Global;
681 &{ $NODE_REQ{g_slave} }; 668 &{ $NODE_REQ{g_slave} }
682}; 669};
683 670
684############################################################################# 671#############################################################################
685# local database operations 672# local database operations
686 673
700sub db_reg($$;$) { 687sub db_reg($$;$) {
701 my ($family, $key) = @_; 688 my ($family, $key) = @_;
702 &db_set; 689 &db_set;
703 Guard::guard { db_del $family => $key } 690 Guard::guard { db_del $family => $key }
704} 691}
692
693sub db_keys($$$) {
694 #d#
695}
696
697#d# db_values
698#d# db_family
699#d# db_key
700
701our %LOCAL_MON;
702
703sub db_mon($$@) {
704 my ($family, $key, @reply) = @_;
705
706 my $id = \@reply + 0;
707
708 $LOCAL_MON{$family}{$key}{$id} = \@reply;
709
710 # always request the data, to generate initial change requests
711 global_req_add "mon1 $family $key" => [g_mon1 => $family => $key];
712
713 Guard::guard {
714 my $key = $LOCAL_MON{$family}{$key};
715 delete $key->{$id};
716
717 unless (%$key) {
718 # no global_req, because we don't care if we are not connected
719 snd $MASTER, g_mon0 => $family => $key
720 if $MASTER;
721
722 delete $LOCAL_MON{$family}{$key};
723 delete $LOCAL_MON{$family}
724 unless %{ $LOCAL_MON{$family} };
725 }
726 }
727}
728
729$NODE_REQ{g_chg1} = sub {
730 warn "one big <@_>\n";#d#
731};
732
733$NODE_REQ{g_chg2} = sub {
734};
705 735
706############################################################################# 736#############################################################################
707# configure 737# configure
708 738
709sub _nodename { 739sub _nodename {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines