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.61 by root, Mon Aug 24 08:06:49 2009 UTC vs.
Revision 1.63 by root, Thu Aug 27 21:29:37 2009 UTC

11 NODE $port # returns the noderef of the port 11 NODE $port # returns the noderef of the port
12 12
13 $SELF # receiving/own port id in rcv callbacks 13 $SELF # receiving/own port id in rcv callbacks
14 14
15 # initialise the node so it can send/receive messages 15 # initialise the node so it can send/receive messages
16 initialise_node; # -OR- 16 initialise_node;
17 initialise_node "localhost:4040"; # -OR-
18 initialise_node "slave/", "localhost:4040"
19 17
20 # ports are message endpoints 18 # ports are message endpoints
21 19
22 # sending messages 20 # sending messages
23 snd $port, type => data...; 21 snd $port, type => data...;
72A port is something you can send messages to (with the C<snd> function). 70A port is something you can send messages to (with the C<snd> function).
73 71
74Ports allow you to register C<rcv> handlers that can match all or just 72Ports allow you to register C<rcv> handlers that can match all or just
75some messages. Messages will not be queued. 73some messages. Messages will not be queued.
76 74
77=item port id - C<noderef#portname> 75=item port ID - C<noderef#portname>
78 76
79A port ID is the concatenation of a noderef, a hash-mark (C<#>) as 77A port ID is the concatenation of a noderef, a hash-mark (C<#>) as
80separator, and a port name (a printable string of unspecified format). An 78separator, and a port name (a printable string of unspecified format). An
81exception is the the node port, whose ID is identical to its node 79exception is the the node port, whose ID is identical to its node
82reference. 80reference.
85 83
86A node is a single process containing at least one port - the node port, 84A node is a single process containing at least one port - the node port,
87which provides nodes to manage each other remotely, and to create new 85which provides nodes to manage each other remotely, and to create new
88ports. 86ports.
89 87
90Nodes are either private (single-process only), slaves (connected to a 88Nodes are either private (single-process only), slaves (can only talk to
91master node only) or public nodes (connectable from unrelated nodes). 89public nodes, but do not need an open port) or public nodes (connectable
90from any other node).
92 91
93=item noderef - C<host:port,host:port...>, C<id@noderef>, C<id> 92=item node ID - C<[a-za-Z0-9_\-.:]+>
94 93
95A node reference is a string that either simply identifies the node (for 94A node ID is a string that either simply identifies the node (for
96private and slave nodes), or contains a recipe on how to reach a given 95private and slave nodes), or contains a recipe on how to reach a given
97node (for public nodes). 96node (for public nodes).
98 97
99This recipe is simply a comma-separated list of C<address:port> pairs (for 98This recipe is simply a comma-separated list of C<address:port> pairs (for
100TCP/IP, other protocols might look different). 99TCP/IP, other protocols might look different).
143} 142}
144 143
145=item $thisnode = NODE / $NODE 144=item $thisnode = NODE / $NODE
146 145
147The C<NODE> function returns, and the C<$NODE> variable contains the 146The C<NODE> function returns, and the C<$NODE> variable contains the
148noderef of the local node. The value is initialised by a call to 147node id of the local node. The value is initialised by a call to
149C<initialise_node>. 148C<initialise_node>.
150 149
151=item $noderef = node_of $port 150=item $nodeid = node_of $port
152 151
153Extracts and returns the noderef from a port ID or a noderef. 152Extracts and returns the noderef from a port ID or a node ID.
154 153
155=item initialise_node $noderef, $seednode, $seednode... 154=item initialise_node $profile_name
156
157=item initialise_node "slave/", $master, $master...
158 155
159Before a node can talk to other nodes on the network it has to initialise 156Before a node can talk to other nodes on the network it has to initialise
160itself - the minimum a node needs to know is it's own name, and optionally 157itself - the minimum a node needs to know is it's own name, and optionally
161it should know the noderefs of some other nodes in the network. 158it should know the noderefs of some other nodes in the network.
162 159
180 177
181For public nodes, C<$noderef> (supplied either directly to 178For public nodes, C<$noderef> (supplied either directly to
182C<initialise_node> or indirectly via a profile or the nodename) must be a 179C<initialise_node> or indirectly via a profile or the nodename) must be a
183noderef (possibly unresolved, in which case it will be resolved). 180noderef (possibly unresolved, in which case it will be resolved).
184 181
185After resolving, the node will bind itself on all endpoints and try to 182After resolving, the node will bind itself on all endpoints.
186connect to all additional C<$seednodes> that are specified. Seednodes are 183
184=item slave nodes
185
186When the C<$noderef> (either as given or overriden by the config file)
187is the special string C<slave/>, then the node will become a slave
188node. Slave nodes cannot be contacted from outside, and cannot talk to
189each other (at least in this version of AnyEvent::MP).
190
191Slave nodes work by creating connections to all public nodes, using the
192L<AnyEvent::MP::Global> service.
193
194=back
195
196After initialising itself, the node will connect to all additional
197C<$seednodes> that are specified diretcly or via a profile. Seednodes are
187optional and can be used to quickly bootstrap the node into an existing 198optional and can be used to quickly bootstrap the node into an existing
188network. 199network.
189 200
190=item slave nodes
191
192When the C<$noderef> (either as given or overriden by the config file)
193is the special string C<slave/>, then the node will become a slave
194node. Slave nodes cannot be contacted from outside and will route most of
195their traffic to the master node that they attach to.
196
197At least one additional noderef is required (either by specifying it
198directly or because it is part of the configuration profile): The node
199will try to connect to all of them and will become a slave attached to the
200first node it can successfully connect to.
201
202Note that slave nodes cannot change their name, and consequently, their
203master, so if the master goes down, the slave node will not function well
204anymore until it can re-establish conenciton to its master. This makes
205slave nodes unsuitable for long-term nodes or fault-tolerant networks.
206
207=back
208
209This function will block until all nodes have been resolved and, for slave
210nodes, until it has successfully established a connection to a master
211server.
212
213All the seednodes will also be specially marked to automatically retry 201All the seednodes will also be specially marked to automatically retry
214connecting to them infinitely. 202connecting to them indefinitely, so make sure that seednodes are really
203reliable and up (this might also change in the future).
215 204
216Example: become a public node listening on the guessed noderef, or the one 205Example: become a public node listening on the guessed noderef, or the one
217specified via C<aemp> for the current node. This should be the most common 206specified via C<aemp> for the current node. This should be the most common
218form of invocation for "daemon"-type nodes. 207form of invocation for "daemon"-type nodes.
219 208
221 210
222Example: become a slave node to any of the the seednodes specified via 211Example: become a slave node to any of the the seednodes specified via
223C<aemp>. This form is often used for commandline clients. 212C<aemp>. This form is often used for commandline clients.
224 213
225 initialise_node "slave/"; 214 initialise_node "slave/";
226
227Example: become a slave node to any of the specified master servers. This
228form is also often used for commandline clients.
229
230 initialise_node "slave/", "master1", "192.168.13.17", "mp.example.net";
231 215
232Example: become a public node, and try to contact some well-known master 216Example: become a public node, and try to contact some well-known master
233servers to become part of the network. 217servers to become part of the network.
234 218
235 initialise_node undef, "master1", "master2"; 219 initialise_node undef, "master1", "master2";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines