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