… | |
… | |
82 | |
82 | |
83 | Ports are represented by (printable) strings called "port IDs". |
83 | Ports are represented by (printable) strings called "port IDs". |
84 | |
84 | |
85 | =item port ID - C<nodeid#portname> |
85 | =item port ID - C<nodeid#portname> |
86 | |
86 | |
87 | A port ID is the concatenation of a node ID, a hash-mark (C<#>) as |
87 | A port ID is the concatenation of a node ID, a hash-mark (C<#>) |
88 | separator, and a port name (a printable string of unspecified format). |
88 | as separator, and a port name (a printable string of unspecified |
|
|
89 | format created by AnyEvent::MP). |
89 | |
90 | |
90 | =item node |
91 | =item node |
91 | |
92 | |
92 | A node is a single process containing at least one port - the node port, |
93 | A node is a single process containing at least one port - the node port, |
93 | which enables nodes to manage each other remotely, and to create new |
94 | which enables nodes to manage each other remotely, and to create new |
… | |
… | |
267 | That means that the values specified in the profile have highest priority |
268 | That means that the values specified in the profile have highest priority |
268 | and the values specified directly via C<configure> have lowest priority, |
269 | and the values specified directly via C<configure> have lowest priority, |
269 | and can only be used to specify defaults. |
270 | and can only be used to specify defaults. |
270 | |
271 | |
271 | If the profile specifies a node ID, then this will become the node ID of |
272 | If the profile specifies a node ID, then this will become the node ID of |
272 | this process. If not, then the profile name will be used as node ID. The |
273 | this process. If not, then the profile name will be used as node ID, with |
273 | special node ID of C<anon/> will be replaced by a random node ID. |
274 | a slash (C</>) attached. |
|
|
275 | |
|
|
276 | If the node ID (or profile name) ends with a slash (C</>), then a random |
|
|
277 | string is appended to make it unique. |
274 | |
278 | |
275 | =item step 2, bind listener sockets |
279 | =item step 2, bind listener sockets |
276 | |
280 | |
277 | The next step is to look up the binds in the profile, followed by binding |
281 | The next step is to look up the binds in the profile, followed by binding |
278 | aemp protocol listeners on all binds specified (it is possible and valid |
282 | aemp protocol listeners on all binds specified (it is possible and valid |
… | |
… | |
305 | Example: configure a node using a profile called seed, which is suitable |
309 | Example: configure a node using a profile called seed, which is suitable |
306 | for a seed node as it binds on all local addresses on a fixed port (4040, |
310 | for a seed node as it binds on all local addresses on a fixed port (4040, |
307 | customary for aemp). |
311 | customary for aemp). |
308 | |
312 | |
309 | # use the aemp commandline utility |
313 | # use the aemp commandline utility |
310 | # aemp profile seed nodeid anon/ binds '*:4040' |
314 | # aemp profile seed binds '*:4040' |
311 | |
315 | |
312 | # then use it |
316 | # then use it |
313 | configure profile => "seed"; |
317 | configure profile => "seed"; |
314 | |
318 | |
315 | # or simply use aemp from the shell again: |
319 | # or simply use aemp from the shell again: |
… | |
… | |
385 | sub _kilme { |
389 | sub _kilme { |
386 | die "received message on port without callback"; |
390 | die "received message on port without callback"; |
387 | } |
391 | } |
388 | |
392 | |
389 | sub port(;&) { |
393 | sub port(;&) { |
390 | my $id = "$UNIQ." . ++$ID; |
394 | my $id = $UNIQ . ++$ID; |
391 | my $port = "$NODE#$id"; |
395 | my $port = "$NODE#$id"; |
392 | |
396 | |
393 | rcv $port, shift || \&_kilme; |
397 | rcv $port, shift || \&_kilme; |
394 | |
398 | |
395 | $port |
399 | $port |
… | |
… | |
782 | } |
786 | } |
783 | |
787 | |
784 | sub spawn(@) { |
788 | sub spawn(@) { |
785 | my ($nodeid, undef) = split /#/, shift, 2; |
789 | my ($nodeid, undef) = split /#/, shift, 2; |
786 | |
790 | |
787 | my $id = "$RUNIQ." . ++$ID; |
791 | my $id = $RUNIQ . ++$ID; |
788 | |
792 | |
789 | $_[0] =~ /::/ |
793 | $_[0] =~ /::/ |
790 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
794 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
791 | |
795 | |
792 | snd_to_func $nodeid, "AnyEvent::MP::_spawn" => $id, @_; |
796 | snd_to_func $nodeid, "AnyEvent::MP::_spawn" => $id, @_; |