… | |
… | |
197 | NODE $NODE *SELF node_of after |
197 | NODE $NODE *SELF node_of after |
198 | configure |
198 | configure |
199 | snd rcv mon mon_guard kil psub peval spawn cal |
199 | snd rcv mon mon_guard kil psub peval spawn cal |
200 | port |
200 | port |
201 | db_set db_del db_reg |
201 | db_set db_del db_reg |
|
|
202 | db_mon db_family db_keys db_values |
202 | ); |
203 | ); |
203 | |
204 | |
204 | our $SELF; |
205 | our $SELF; |
205 | |
206 | |
206 | sub _self_die() { |
207 | sub _self_die() { |
… | |
… | |
946 | |
947 | |
947 | Sets the key on the database and returns a guard. When the guard is |
948 | Sets the key on the database and returns a guard. When the guard is |
948 | destroyed, the key is deleted from the database. If C<$value> is missing, |
949 | destroyed, the key is deleted from the database. If C<$value> is missing, |
949 | then C<undef> is used. |
950 | then C<undef> is used. |
950 | |
951 | |
|
|
952 | =item $guard = db_mon $family => $cb->($familyhash, \@subkeys...) |
|
|
953 | |
|
|
954 | Creates a monitor on the given database family. Each time a key is set or |
|
|
955 | or is deleted the callback is called with a hash containing the database |
|
|
956 | family and an arrayref with subkeys that have changed. |
|
|
957 | |
|
|
958 | Specifically, if one of the passed subkeys exists in the $familyhash, then |
|
|
959 | it is currently set to the value in the $familyhash. Otherwise, it has |
|
|
960 | been deleted. |
|
|
961 | |
|
|
962 | The first call will be with the current contents of the family and all |
|
|
963 | keys, as if they were just added. |
|
|
964 | |
|
|
965 | It is possible that the callback is called with a change event even though |
|
|
966 | the subkey is already present and the value has not changed. |
|
|
967 | |
|
|
968 | The monitoring stops when the guard object is destroyed. |
|
|
969 | |
|
|
970 | Example: on every change to the family "mygroup", print out all keys. |
|
|
971 | |
|
|
972 | my $guard = db_mon mygroup => sub { |
|
|
973 | my ($family, $keys) = @_; |
|
|
974 | print "mygroup members: ", (join " ", keys %$family), "\n"; |
|
|
975 | }; |
|
|
976 | |
|
|
977 | Exmaple: wait until the family "My::Module::workers" is non-empty. |
|
|
978 | |
|
|
979 | my $guard; $guard = db_mon My::Module::workers => sub { |
|
|
980 | my ($family, $keys) = @_; |
|
|
981 | return unless %$family; |
|
|
982 | undef $guard; |
|
|
983 | print "My::Module::workers now nonempty\n"; |
|
|
984 | }; |
|
|
985 | |
|
|
986 | Example: print all changes to the family "AnyRvent::Fantasy::Module". |
|
|
987 | |
|
|
988 | my $guard = db_mon AnyRvent::Fantasy::Module => sub { |
|
|
989 | my ($family, $keys) = @_; |
|
|
990 | |
|
|
991 | for (@$keys) { |
|
|
992 | print "$_: ", |
|
|
993 | (exists $family->{$_} |
|
|
994 | ? $family->{$_} |
|
|
995 | : "(deleted)"), |
|
|
996 | "\n"; |
|
|
997 | } |
|
|
998 | }; |
|
|
999 | |
951 | =cut |
1000 | =cut |
952 | |
1001 | |
953 | =back |
1002 | =back |
954 | |
1003 | |
955 | =head1 AnyEvent::MP vs. Distributed Erlang |
1004 | =head1 AnyEvent::MP vs. Distributed Erlang |