… | |
… | |
43 | add_node load_func snd_to_func snd_on eval_on |
43 | add_node load_func snd_to_func snd_on eval_on |
44 | |
44 | |
45 | NODE $NODE node_of snd kil port_is_local |
45 | NODE $NODE node_of snd kil port_is_local |
46 | configure |
46 | configure |
47 | up_nodes mon_nodes node_is_up |
47 | up_nodes mon_nodes node_is_up |
48 | db_set db_del db_reg |
48 | db_set db_del |
49 | db_mon db_family db_keys db_values |
49 | db_mon db_family db_keys db_values |
50 | ); |
50 | ); |
51 | |
51 | |
52 | =item $AnyEvent::MP::Kernel::WARN->($level, $msg) |
52 | =item $AnyEvent::MP::Kernel::WARN->($level, $msg) |
53 | |
53 | |
… | |
… | |
189 | } |
189 | } |
190 | |
190 | |
191 | our $DELAY_TIMER; |
191 | our $DELAY_TIMER; |
192 | our @DELAY_QUEUE; |
192 | our @DELAY_QUEUE; |
193 | |
193 | |
194 | sub _delay_run { |
194 | our $delay_run = sub { |
195 | (shift @DELAY_QUEUE or return undef $DELAY_TIMER)->() while 1; |
195 | (shift @DELAY_QUEUE or return undef $DELAY_TIMER)->() while 1; |
196 | } |
196 | }; |
197 | |
197 | |
198 | sub delay($) { |
198 | sub delay($) { |
199 | push @DELAY_QUEUE, shift; |
199 | push @DELAY_QUEUE, shift; |
200 | $DELAY_TIMER ||= AE::timer 0, 0, \&_delay_run; |
200 | $DELAY_TIMER ||= AE::timer 0, 0, $delay_run; |
201 | } |
201 | } |
202 | |
202 | |
203 | =item $AnyEvent::MP::Kernel::SRCNODE |
203 | =item $AnyEvent::MP::Kernel::SRCNODE |
204 | |
204 | |
205 | During execution of a message callback, this variable contains the node ID |
205 | During execution of a message callback, this variable contains the node ID |
… | |
… | |
722 | # local database operations |
722 | # local database operations |
723 | |
723 | |
724 | # local database management |
724 | # local database management |
725 | |
725 | |
726 | sub db_set($$;$) { |
726 | sub db_set($$;$) { |
|
|
727 | my ($family, $subkey) = @_; |
|
|
728 | |
727 | # if (ref $_[1]) { |
729 | # if (ref $_[1]) { |
728 | # # bulk |
730 | # # bulk |
729 | # my @del = grep exists $LOCAL_DB{$_[0]}{$_}, keys ${ $_[1] }; |
731 | # my @del = grep exists $LOCAL_DB{$_[0]}{$_}, keys ${ $_[1] }; |
730 | # $LOCAL_DB{$_[0]} = $_[1]; |
732 | # $LOCAL_DB{$_[0]} = $_[1]; |
731 | # snd $MASTER, g_upd => $_[0] => $_[1], \@del |
733 | # snd $MASTER, g_upd => $_[0] => $_[1], \@del |
732 | # if defined $MASTER; |
734 | # if defined $MASTER; |
733 | # } else { |
735 | # } else { |
734 | # single-key |
736 | # single-key |
735 | $LOCAL_DB{$_[0]}{$_[1]} = $_[2]; |
737 | $LOCAL_DB{$family}{$subkey} = $_[2]; |
736 | snd $MASTER, g_upd => $_[0] => { $_[1] => $_[2] } |
738 | snd $MASTER, g_upd => $family => { $subkey => $_[2] } |
737 | if defined $MASTER; |
739 | if defined $MASTER; |
738 | # } |
740 | # } |
|
|
741 | |
|
|
742 | defined wantarray |
|
|
743 | and Guard::guard { db_del $family => $subkey } |
739 | } |
744 | } |
740 | |
745 | |
741 | sub db_del($@) { |
746 | sub db_del($@) { |
742 | my $family = shift; |
747 | my $family = shift; |
743 | |
748 | |
744 | delete @{ $LOCAL_DB{$family} }{@_}; |
749 | delete @{ $LOCAL_DB{$family} }{@_}; |
745 | snd $MASTER, g_upd => $family => undef, \@_ |
750 | snd $MASTER, g_upd => $family => undef, \@_ |
746 | if defined $MASTER; |
751 | if defined $MASTER; |
747 | } |
|
|
748 | |
|
|
749 | sub db_reg($$;$) { |
|
|
750 | my ($family, $key) = @_; |
|
|
751 | &db_set; |
|
|
752 | Guard::guard { db_del $family => $key } |
|
|
753 | } |
752 | } |
754 | |
753 | |
755 | # database query |
754 | # database query |
756 | |
755 | |
757 | sub db_family { |
756 | sub db_family { |