… | |
… | |
175 | |
175 | |
176 | =cut |
176 | =cut |
177 | |
177 | |
178 | package AnyEvent::MP; |
178 | package AnyEvent::MP; |
179 | |
179 | |
|
|
180 | use AnyEvent::MP::Config (); |
180 | use AnyEvent::MP::Kernel; |
181 | use AnyEvent::MP::Kernel; |
|
|
182 | use AnyEvent::MP::Kernel qw(%NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID); |
181 | |
183 | |
182 | use common::sense; |
184 | use common::sense; |
183 | |
185 | |
184 | use Carp (); |
186 | use Carp (); |
185 | |
187 | |
186 | use AE (); |
188 | use AE (); |
187 | |
189 | |
188 | use base "Exporter"; |
190 | use base "Exporter"; |
189 | |
191 | |
190 | our $VERSION = '1.30'; |
192 | our $VERSION = $AnyEvent::MP::Config::VERSION; |
191 | |
193 | |
192 | our @EXPORT = qw( |
194 | our @EXPORT = qw( |
193 | NODE $NODE *SELF node_of after |
195 | NODE $NODE *SELF node_of after |
194 | configure |
196 | configure |
195 | snd rcv mon mon_guard kil psub peval spawn cal |
197 | snd rcv mon mon_guard kil psub peval spawn cal |
… | |
… | |
221 | Before a node can talk to other nodes on the network (i.e. enter |
223 | Before a node can talk to other nodes on the network (i.e. enter |
222 | "distributed mode") it has to configure itself - the minimum a node needs |
224 | "distributed mode") it has to configure itself - the minimum a node needs |
223 | to know is its own name, and optionally it should know the addresses of |
225 | to know is its own name, and optionally it should know the addresses of |
224 | some other nodes in the network to discover other nodes. |
226 | some other nodes in the network to discover other nodes. |
225 | |
227 | |
226 | The key/value pairs are basically the same ones as documented for the |
|
|
227 | F<aemp> command line utility (sans the set/del prefix). |
|
|
228 | |
|
|
229 | This function configures a node - it must be called exactly once (or |
228 | This function configures a node - it must be called exactly once (or |
230 | never) before calling other AnyEvent::MP functions. |
229 | never) before calling other AnyEvent::MP functions. |
|
|
230 | |
|
|
231 | The key/value pairs are basically the same ones as documented for the |
|
|
232 | F<aemp> command line utility (sans the set/del prefix), with two additions: |
|
|
233 | |
|
|
234 | =over 4 |
|
|
235 | |
|
|
236 | =item norc => $boolean (default false) |
|
|
237 | |
|
|
238 | If true, then the rc file (e.g. F<~/.perl-anyevent-mp>) will I<not> |
|
|
239 | be consulted - all configuraiton options must be specified in the |
|
|
240 | C<configure> call. |
|
|
241 | |
|
|
242 | =item force => $boolean (default false) |
|
|
243 | |
|
|
244 | IF true, then the values specified in the C<configure> will take |
|
|
245 | precedence over any values configured via the rc file. The default is for |
|
|
246 | the rc file to override any options specified in the program. |
|
|
247 | |
|
|
248 | =back |
231 | |
249 | |
232 | =over 4 |
250 | =over 4 |
233 | |
251 | |
234 | =item step 1, gathering configuration from profiles |
252 | =item step 1, gathering configuration from profiles |
235 | |
253 | |
… | |
… | |
367 | sub _kilme { |
385 | sub _kilme { |
368 | die "received message on port without callback"; |
386 | die "received message on port without callback"; |
369 | } |
387 | } |
370 | |
388 | |
371 | sub port(;&) { |
389 | sub port(;&) { |
372 | my $id = "$UNIQ." . $ID++; |
390 | my $id = "$UNIQ." . ++$ID; |
373 | my $port = "$NODE#$id"; |
391 | my $port = "$NODE#$id"; |
374 | |
392 | |
375 | rcv $port, shift || \&_kilme; |
393 | rcv $port, shift || \&_kilme; |
376 | |
394 | |
377 | $port |
395 | $port |
… | |
… | |
764 | } |
782 | } |
765 | |
783 | |
766 | sub spawn(@) { |
784 | sub spawn(@) { |
767 | my ($nodeid, undef) = split /#/, shift, 2; |
785 | my ($nodeid, undef) = split /#/, shift, 2; |
768 | |
786 | |
769 | my $id = "$RUNIQ." . $ID++; |
787 | my $id = "$RUNIQ." . ++$ID; |
770 | |
788 | |
771 | $_[0] =~ /::/ |
789 | $_[0] =~ /::/ |
772 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
790 | or Carp::croak "spawn init function must be a fully-qualified name, caught"; |
773 | |
791 | |
774 | snd_to_func $nodeid, "AnyEvent::MP::_spawn" => $id, @_; |
792 | snd_to_func $nodeid, "AnyEvent::MP::_spawn" => $id, @_; |
775 | |
793 | |
776 | "$nodeid#$id" |
794 | "$nodeid#$id" |
777 | } |
795 | } |
|
|
796 | |
778 | |
797 | |
779 | =item after $timeout, @msg |
798 | =item after $timeout, @msg |
780 | |
799 | |
781 | =item after $timeout, $callback |
800 | =item after $timeout, $callback |
782 | |
801 | |