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

Comparing cvsroot/AnyEvent-MP/MP.pm (file contents):
Revision 1.124 by root, Sat Mar 3 11:38:43 2012 UTC vs.
Revision 1.127 by root, Sat Mar 3 20:35:10 2012 UTC

230 230
231This function configures a node - it must be called exactly once (or 231This function configures a node - it must be called exactly once (or
232never) before calling other AnyEvent::MP functions. 232never) before calling other AnyEvent::MP functions.
233 233
234The key/value pairs are basically the same ones as documented for the 234The 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: 235F<aemp> command line utility (sans the set/del prefix), with these additions:
236 236
237=over 4 237=over 4
238 238
239=item norc => $boolean (default false) 239=item norc => $boolean (default false)
240 240
245=item force => $boolean (default false) 245=item force => $boolean (default false)
246 246
247IF true, then the values specified in the C<configure> will take 247IF true, then the values specified in the C<configure> will take
248precedence over any values configured via the rc file. The default is for 248precedence over any values configured via the rc file. The default is for
249the rc file to override any options specified in the program. 249the rc file to override any options specified in the program.
250
251=item secure => $pass->($nodeid)
252
253In addition to specifying a boolean, you can specify a code reference that
254is called for every remote execution attempt - the execution request is
255granted iff the callback returns a true value.
256
257See F<semp setsecure> for more info.
250 258
251=back 259=back
252 260
253=over 4 261=over 4
254 262
271and the values specified directly via C<configure> have lowest priority, 279and the values specified directly via C<configure> have lowest priority,
272and can only be used to specify defaults. 280and can only be used to specify defaults.
273 281
274If the profile specifies a node ID, then this will become the node ID of 282If the profile specifies a node ID, then this will become the node ID of
275this process. If not, then the profile name will be used as node ID, with 283this process. If not, then the profile name will be used as node ID, with
276a slash (C</>) attached. 284a unique randoms tring (C</%u>) appended.
277 285
278If the node ID (or profile name) ends with a slash (C</>), then a random 286The node ID can contain some C<%> sequences that are expanded: C<%n>
279string is appended to make it unique. 287is expanded to the local nodename, C<%u> is replaced by a random
288strign to make the node unique. For example, the F<aemp> commandline
289utility uses C<aemp/%n/%u> as nodename, which might expand to
290C<aemp/cerebro/ZQDGSIkRhEZQDGSIkRhE>.
280 291
281=item step 2, bind listener sockets 292=item step 2, bind listener sockets
282 293
283The next step is to look up the binds in the profile, followed by binding 294The next step is to look up the binds in the profile, followed by binding
284aemp protocol listeners on all binds specified (it is possible and valid 295aemp protocol listeners on all binds specified (it is possible and valid
301Example: become a distributed node using the local node name as profile. 312Example: become a distributed node using the local node name as profile.
302This should be the most common form of invocation for "daemon"-type nodes. 313This should be the most common form of invocation for "daemon"-type nodes.
303 314
304 configure 315 configure
305 316
306Example: become an anonymous node. This form is often used for commandline 317Example: become a semi-anonymous node. This form is often used for
307clients. 318commandline clients.
308 319
309 configure nodeid => "anon/"; 320 configure nodeid => "myscript/%n/%u";
310 321
311Example: configure a node using a profile called seed, which is suitable 322Example: configure a node using a profile called seed, which is suitable
312for a seed node as it binds on all local addresses on a fixed port (4040, 323for a seed node as it binds on all local addresses on a fixed port (4040,
313customary for aemp). 324customary for aemp).
314 325
887 898
888The database consists of a two-level hash - a hash contains a hash which 899The database consists of a two-level hash - a hash contains a hash which
889contains values. 900contains values.
890 901
891The top level hash key is called "family", and the second-level hash key 902The top level hash key is called "family", and the second-level hash key
892is simply called "key". 903is called "subkey" or simply "key".
893 904
894The family and key must be alphanumeric ASCII strings, i.e. start 905The family must be alphanumeric, i.e. start with a letter and consist
895with a letter and consist of letters, digits, underscores and colons 906of letters, digits, underscores and colons (C<[A-Za-z][A-Za-z0-9_:]*>,
896(C<[A-Za-z][A-Za-z0-9_:]*>, pretty much like Perl module names. 907pretty much like Perl module names.
897 908
898As the family namespaceis global, it is recommended to prefix family names 909As the family namespace is global, it is recommended to prefix family names
899with the name of the application or module using it. 910with the name of the application or module using it.
900 911
912The subkeys must be non-empty strings, with no further restrictions.
913
901The values should preferably be strings, but other perl scalars should 914The values should preferably be strings, but other perl scalars should
902work as well (such as arrays and hashes). 915work as well (such as undef, arrays and hashes).
903 916
904Every database entry is owned by one node - adding the same family/key 917Every database entry is owned by one node - adding the same family/subkey
905combination on multiple nodes will not cause discomfort for AnyEvent::MP, 918combination on multiple nodes will not cause discomfort for AnyEvent::MP,
906but the result might be nondeterministic, i.e. the key might have 919but the result might be nondeterministic, i.e. the key might have
907different values on different nodes. 920different values on different nodes.
908 921
922Different subkeys in the same family can be owned by different nodes
923without problems, and in fact, this is the common method to create worker
924pools. For example, a worker port for image scaling might do this:
925
926 db_set my_image_scalers => $port;
927
928And clients looking for an image scaler will want to get the
929C<my_image_scalers> keys:
930
931 db_keys "my_image_scalers" => 60 => sub {
932 #d##TODO#
933
934=over
935
909=item db_set $family => $key => $value 936=item db_set $family => $subkey [=> $value]
910 937
911Sets (or replaces) a key to the database. 938Sets (or replaces) a key to the database - if C<$value> is omitted,
939C<undef> is used instead.
912 940
913=item db_del $family => $key 941=item db_del $family => $subkey
914 942
915Deletes a key from the database. 943Deletes a key from the database.
916 944
917=item $guard = db_reg $family => $key [=> $value] 945=item $guard = db_reg $family => $subkey [=> $value]
918 946
919Sets the key on the database and returns a guard. When the guard is 947Sets the key on the database and returns a guard. When the guard is
920destroyed, the key is deleted from the database. If C<$value> is missing, 948destroyed, the key is deleted from the database. If C<$value> is missing,
921then C<undef> is used. 949then C<undef> is used.
922 950

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines