… | |
… | |
43 | |
43 | |
44 | =over 4 |
44 | =over 4 |
45 | |
45 | |
46 | =item port |
46 | =item port |
47 | |
47 | |
48 | A port is something you can send messages to with the C<snd> function, and |
48 | A port is something you can send messages to (with the C<snd> function). |
49 | you can register C<rcv> handlers with. All C<rcv> handlers will receive |
49 | |
50 | messages they match, messages will not be queued. |
50 | Some ports allow you to register C<rcv> handlers that can match specific |
|
|
51 | messages. All C<rcv> handlers will receive messages they match, messages |
|
|
52 | will not be queued. |
51 | |
53 | |
52 | =item port id - C<noderef#portname> |
54 | =item port id - C<noderef#portname> |
53 | |
55 | |
54 | A port id is always the noderef, a hash-mark (C<#>) as separator, followed |
56 | A port id is normaly the concatenation of a noderef, a hash-mark (C<#>) as |
55 | by a port name (a printable string of unspecified format). |
57 | separator, and a port name (a printable string of unspecified format). An |
|
|
58 | exception is the the node port, whose ID is identical to it's node |
|
|
59 | reference. |
56 | |
60 | |
57 | =item node |
61 | =item node |
58 | |
62 | |
59 | A node is a single process containing at least one port - the node |
63 | A node is a single process containing at least one port - the node |
60 | port. You can send messages to node ports to let them create new ports, |
64 | port. You can send messages to node ports to find existing ports or to |
61 | among other things. |
65 | create new ports, among other things. |
62 | |
66 | |
63 | Initially, nodes are either private (single-process only) or hidden |
67 | Nodes are either private (single-process only), slaves (connected to a |
64 | (connected to a master node only). Only when they epxlicitly "become |
68 | master node only) or public nodes (connectable from unrelated nodes). |
65 | public" can you send them messages from unrelated other nodes. |
|
|
66 | |
69 | |
67 | =item noderef - C<host:port,host:port...>, C<id@noderef>, C<id> |
70 | =item noderef - C<host:port,host:port...>, C<id@noderef>, C<id> |
68 | |
71 | |
69 | A noderef is a string that either uniquely identifies a given node (for |
72 | A node reference is a string that either simply identifies the node (for |
70 | private and hidden nodes), or contains a recipe on how to reach a given |
73 | private and slave nodes), or contains a recipe on how to reach a given |
71 | node (for public nodes). |
74 | node (for public nodes). |
|
|
75 | |
|
|
76 | This recipe is simply a comma-separated list of C<address:port> pairs (for |
|
|
77 | TCP/IP, other protocols might look different). |
|
|
78 | |
|
|
79 | Node references come in two flavours: resolved (containing only numerical |
|
|
80 | addresses) or unresolved (where hostnames are used instead of addresses). |
|
|
81 | |
|
|
82 | Before using an unresolved node reference in a message you first have to |
|
|
83 | resolve it. |
72 | |
84 | |
73 | =back |
85 | =back |
74 | |
86 | |
75 | =head1 VARIABLES/FUNCTIONS |
87 | =head1 VARIABLES/FUNCTIONS |
76 | |
88 | |
… | |
… | |
91 | use base "Exporter"; |
103 | use base "Exporter"; |
92 | |
104 | |
93 | our $VERSION = '0.1'; |
105 | our $VERSION = '0.1'; |
94 | our @EXPORT = qw( |
106 | our @EXPORT = qw( |
95 | NODE $NODE *SELF node_of _any_ |
107 | NODE $NODE *SELF node_of _any_ |
|
|
108 | resolve_node |
96 | become_slave become_public |
109 | become_slave become_public |
97 | snd rcv mon kil reg psub |
110 | snd rcv mon kil reg psub |
98 | port |
111 | port |
99 | ); |
112 | ); |
100 | |
113 | |
… | |
… | |
114 | identifiers become invalid. |
127 | identifiers become invalid. |
115 | |
128 | |
116 | =item $noderef = node_of $portid |
129 | =item $noderef = node_of $portid |
117 | |
130 | |
118 | Extracts and returns the noderef from a portid or a noderef. |
131 | Extracts and returns the noderef from a portid or a noderef. |
|
|
132 | |
|
|
133 | =item $cv = resolve_node $noderef |
|
|
134 | |
|
|
135 | Takes an unresolved node reference that may contain hostnames and |
|
|
136 | abbreviated IDs, resolves all of them and returns a resolved node |
|
|
137 | reference. |
|
|
138 | |
|
|
139 | In addition to C<address:port> pairs allowed in resolved noderefs, the |
|
|
140 | following forms are supported: |
|
|
141 | |
|
|
142 | =over 4 |
|
|
143 | |
|
|
144 | =item the empty string |
|
|
145 | |
|
|
146 | An empty-string component gets resolved as if the default port (4040) was |
|
|
147 | specified. |
|
|
148 | |
|
|
149 | =item naked port numbers (e.g. C<1234>) |
|
|
150 | |
|
|
151 | These are resolved by prepending the local nodename and a colon, to be |
|
|
152 | further resolved. |
|
|
153 | |
|
|
154 | =item hostnames (e.g. C<localhost:1234>, C<localhost>) |
|
|
155 | |
|
|
156 | These are resolved by using AnyEvent::DNS to resolve them, optionally |
|
|
157 | looking up SRV records for the C<aemp=4040> port, if no port was |
|
|
158 | specified. |
|
|
159 | |
|
|
160 | =back |
119 | |
161 | |
120 | =item $SELF |
162 | =item $SELF |
121 | |
163 | |
122 | Contains the current port id while executing C<rcv> callbacks or C<psub> |
164 | Contains the current port id while executing C<rcv> callbacks or C<psub> |
123 | blocks. |
165 | blocks. |
… | |
… | |
447 | |
489 | |
448 | =head1 FUNCTIONS FOR NODES |
490 | =head1 FUNCTIONS FOR NODES |
449 | |
491 | |
450 | =over 4 |
492 | =over 4 |
451 | |
493 | |
452 | =item become_public endpoint... |
494 | =item become_public $noderef |
453 | |
495 | |
454 | Tells the node to become a public node, i.e. reachable from other nodes. |
496 | Tells the node to become a public node, i.e. reachable from other nodes. |
455 | |
497 | |
456 | If no arguments are given, or the first argument is C<undef>, then |
498 | The first argument is the (unresolved) node reference of the local node |
457 | AnyEvent::MP tries to bind on port C<4040> on all IP addresses that the |
499 | (if missing then the empty string is used). |
458 | local nodename resolves to. |
|
|
459 | |
500 | |
460 | Otherwise the first argument must be an array-reference with transport |
501 | It is quite common to not specify anything, in which case the local node |
461 | endpoints ("ip:port", "hostname:port") or port numbers (in which case the |
502 | tries to listen on the default port, or to only specify a port number, in |
462 | local nodename is used as hostname). The endpoints are all resolved and |
503 | which case AnyEvent::MP tries to guess the local addresses. |
463 | will become the node reference. |
|
|
464 | |
504 | |
465 | =cut |
505 | =cut |
466 | |
506 | |
467 | =back |
507 | =back |
468 | |
508 | |
… | |
… | |
471 | Nodes understand the following messages sent to them. Many of them take |
511 | Nodes understand the following messages sent to them. Many of them take |
472 | arguments called C<@reply>, which will simply be used to compose a reply |
512 | arguments called C<@reply>, which will simply be used to compose a reply |
473 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
513 | message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and |
474 | the remaining arguments are simply the message data. |
514 | the remaining arguments are simply the message data. |
475 | |
515 | |
|
|
516 | While other messages exist, they are not public and subject to change. |
|
|
517 | |
476 | =over 4 |
518 | =over 4 |
477 | |
519 | |
478 | =cut |
520 | =cut |
479 | |
521 | |
480 | =item lookup => $name, @reply |
522 | =item lookup => $name, @reply |