… | |
… | |
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() { |
… | |
… | |
230 | |
231 | |
231 | This function configures a node - it must be called exactly once (or |
232 | This function configures a node - it must be called exactly once (or |
232 | never) before calling other AnyEvent::MP functions. |
233 | never) before calling other AnyEvent::MP functions. |
233 | |
234 | |
234 | The key/value pairs are basically the same ones as documented for the |
235 | The key/value pairs are basically the same ones as documented for the |
235 | F<aemp> command line utility (sans the set/del prefix), with two additions: |
236 | F<aemp> command line utility (sans the set/del prefix), with these additions: |
236 | |
237 | |
237 | =over 4 |
238 | =over 4 |
238 | |
239 | |
239 | =item norc => $boolean (default false) |
240 | =item norc => $boolean (default false) |
240 | |
241 | |
… | |
… | |
245 | =item force => $boolean (default false) |
246 | =item force => $boolean (default false) |
246 | |
247 | |
247 | IF true, then the values specified in the C<configure> will take |
248 | IF true, then the values specified in the C<configure> will take |
248 | precedence over any values configured via the rc file. The default is for |
249 | precedence over any values configured via the rc file. The default is for |
249 | the rc file to override any options specified in the program. |
250 | the rc file to override any options specified in the program. |
|
|
251 | |
|
|
252 | =item secure => $pass->($nodeid) |
|
|
253 | |
|
|
254 | In addition to specifying a boolean, you can specify a code reference that |
|
|
255 | is called for every remote execution attempt - the execution request is |
|
|
256 | granted iff the callback returns a true value. |
|
|
257 | |
|
|
258 | See F<semp setsecure> for more info. |
250 | |
259 | |
251 | =back |
260 | =back |
252 | |
261 | |
253 | =over 4 |
262 | =over 4 |
254 | |
263 | |
… | |
… | |
938 | |
947 | |
939 | 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 |
940 | 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, |
941 | then C<undef> is used. |
950 | then C<undef> is used. |
942 | |
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 | |
943 | =cut |
1000 | =cut |
944 | |
1001 | |
945 | =back |
1002 | =back |
946 | |
1003 | |
947 | =head1 AnyEvent::MP vs. Distributed Erlang |
1004 | =head1 AnyEvent::MP vs. Distributed Erlang |