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.125 by root, Sat Mar 3 13:07:19 2012 UTC vs.
Revision 1.126 by root, Sat Mar 3 19:43:41 2012 UTC

271and the values specified directly via C<configure> have lowest priority, 271and the values specified directly via C<configure> have lowest priority,
272and can only be used to specify defaults. 272and can only be used to specify defaults.
273 273
274If the profile specifies a node ID, then this will become the node ID of 274If 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 275this process. If not, then the profile name will be used as node ID, with
276a slash (C</>) attached. 276a unique randoms tring (C</%u>) appended.
277 277
278If the node ID (or profile name) ends with a slash (C</>), then a random 278The node ID can contain some C<%> sequences that are expanded: C<%n>
279string is appended to make it unique. 279is expanded to the local nodename, C<%u> is replaced by a random
280strign to make the node unique. For example, the F<aemp> commandline
281utility uses C<aemp/%n/%u> as nodename, which might expand to
282C<aemp/cerebro/ZQDGSIkRhEZQDGSIkRhE>.
280 283
281=item step 2, bind listener sockets 284=item step 2, bind listener sockets
282 285
283The next step is to look up the binds in the profile, followed by binding 286The 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 287aemp protocol listeners on all binds specified (it is possible and valid
301Example: become a distributed node using the local node name as profile. 304Example: become a distributed node using the local node name as profile.
302This should be the most common form of invocation for "daemon"-type nodes. 305This should be the most common form of invocation for "daemon"-type nodes.
303 306
304 configure 307 configure
305 308
306Example: become an anonymous node. This form is often used for commandline 309Example: become a semi-anonymous node. This form is often used for
307clients. 310commandline clients.
308 311
309 configure nodeid => "anon/"; 312 configure nodeid => "myscript/%n/%u";
310 313
311Example: configure a node using a profile called seed, which is suitable 314Example: 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, 315for a seed node as it binds on all local addresses on a fixed port (4040,
313customary for aemp). 316customary for aemp).
314 317
887 890
888The database consists of a two-level hash - a hash contains a hash which 891The database consists of a two-level hash - a hash contains a hash which
889contains values. 892contains values.
890 893
891The top level hash key is called "family", and the second-level hash key 894The top level hash key is called "family", and the second-level hash key
892is simply called "key". 895is called "subkey" or simply "key".
893 896
894The family must be alphanumeric, i.e. start with a letter and consist 897The family must be alphanumeric, i.e. start with a letter and consist
895of letters, digits, underscores and colons (C<[A-Za-z][A-Za-z0-9_:]*>, 898of letters, digits, underscores and colons (C<[A-Za-z][A-Za-z0-9_:]*>,
896pretty much like Perl module names. 899pretty much like Perl module names.
897 900
898As the family namespace is global, it is recommended to prefix family names 901As the family namespace is global, it is recommended to prefix family names
899with the name of the application or module using it. 902with the name of the application or module using it.
900 903
901The keys must be strings, with no other limitations. 904The subkeys must be non-empty strings, with no further restrictions.
902 905
903The values should preferably be strings, but other perl scalars should 906The values should preferably be strings, but other perl scalars should
904work as well (such as undef, arrays and hashes). 907work as well (such as undef, arrays and hashes).
905 908
906Every database entry is owned by one node - adding the same family/key 909Every database entry is owned by one node - adding the same family/subkey
907combination on multiple nodes will not cause discomfort for AnyEvent::MP, 910combination on multiple nodes will not cause discomfort for AnyEvent::MP,
908but the result might be nondeterministic, i.e. the key might have 911but the result might be nondeterministic, i.e. the key might have
909different values on different nodes. 912different values on different nodes.
910 913
914Different subkeys in the same family can be owned by different nodes
915without problems, and in fact, this is the common method to create worker
916pools. For example, a worker port for image scaling might do this:
917
918 db_set my_image_scalers => $port;
919
920And clients looking for an image scaler will want to get the
921C<my_image_scalers> keys:
922
923 db_keys "my_image_scalers" => 60 => sub {
924 #d##TODO#
925
926=over
927
911=item db_set $family => $key => $value 928=item db_set $family => $subkey [=> $value]
912 929
913Sets (or replaces) a key to the database. 930Sets (or replaces) a key to the database - if C<$value> is omitted,
931C<undef> is used instead.
914 932
915=item db_del $family => $key 933=item db_del $family => $subkey
916 934
917Deletes a key from the database. 935Deletes a key from the database.
918 936
919=item $guard = db_reg $family => $key [=> $value] 937=item $guard = db_reg $family => $subkey [=> $value]
920 938
921Sets the key on the database and returns a guard. When the guard is 939Sets the key on the database and returns a guard. When the guard is
922destroyed, the key is deleted from the database. If C<$value> is missing, 940destroyed, the key is deleted from the database. If C<$value> is missing,
923then C<undef> is used. 941then C<undef> is used.
924 942

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines