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