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

Comparing AnyEvent-MP/MP.pm (file contents):
Revision 1.126 by root, Sat Mar 3 19:43:41 2012 UTC vs.
Revision 1.128 by root, Sun Mar 4 14:28:44 2012 UTC

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
204our $SELF; 205our $SELF;
205 206
206sub _self_die() { 207sub _self_die() {
230 231
231This function configures a node - it must be called exactly once (or 232This function configures a node - it must be called exactly once (or
232never) before calling other AnyEvent::MP functions. 233never) before calling other AnyEvent::MP functions.
233 234
234The key/value pairs are basically the same ones as documented for the 235The key/value pairs are basically the same ones as documented for the
235F<aemp> command line utility (sans the set/del prefix), with two additions: 236F<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
247IF true, then the values specified in the C<configure> will take 248IF true, then the values specified in the C<configure> will take
248precedence over any values configured via the rc file. The default is for 249precedence over any values configured via the rc file. The default is for
249the rc file to override any options specified in the program. 250the rc file to override any options specified in the program.
251
252=item secure => $pass->($nodeid)
253
254In addition to specifying a boolean, you can specify a code reference that
255is called for every remote execution attempt - the execution request is
256granted iff the callback returns a true value.
257
258See F<semp setsecure> for more info.
250 259
251=back 260=back
252 261
253=over 4 262=over 4
254 263
938 947
939Sets the key on the database and returns a guard. When the guard is 948Sets the key on the database and returns a guard. When the guard is
940destroyed, the key is deleted from the database. If C<$value> is missing, 949destroyed, the key is deleted from the database. If C<$value> is missing,
941then C<undef> is used. 950then C<undef> is used.
942 951
952=item $guard = db_mon $family => $cb->($familyhash, \@subkeys...)
953
954Creates a monitor on the given database family. Each time a key is set or
955or is deleted the callback is called with a hash containing the database
956family and an arrayref with subkeys that have changed.
957
958Specifically, if one of the passed subkeys exists in the $familyhash, then
959it is currently set to the value in the $familyhash. Otherwise, it has
960been deleted.
961
962The first call will be with the current contents of the family and all
963keys, as if they were just added.
964
965It is possible that the callback is called with a change event even though
966the subkey is already present and the value has not changed.
967
968The monitoring stops when the guard object is destroyed.
969
970Example: 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
977Exmaple: 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
986Example: 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines