ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Base.pm
(Generate patch)

Comparing AnyEvent-MP/MP/Base.pm (file contents):
Revision 1.14 by root, Wed Aug 5 23:24:58 2009 UTC vs.
Revision 1.15 by root, Fri Aug 7 22:55:18 2009 UTC

31 31
32use base "Exporter"; 32use base "Exporter";
33 33
34our $VERSION = '0.01'; 34our $VERSION = '0.01';
35our @EXPORT = qw( 35our @EXPORT = qw(
36 %NODE %PORT %PORT_DATA %REG $UNIQ $ID add_node 36 %NODE %PORT %PORT_DATA %REG $UNIQ $RUNIQ $ID add_node load_func
37 37
38 NODE $NODE node_of snd kil _any_ 38 NODE $NODE node_of snd kil _any_
39 resolve_node initialise_node 39 resolve_node initialise_node
40); 40);
41 41
110 110
111sub gen_uniq { 111sub gen_uniq {
112 asciibits pack "wNa*", $$, time, nonce 2 112 asciibits pack "wNa*", $$, time, nonce 2
113} 113}
114 114
115our $NODE = asciibits nonce 12;
116our $UNIQ = gen_uniq; # per-process/node unique cookie
117our $ID = "a";
118our $PUBLIC = 0; 115our $PUBLIC = 0;
119our $SLAVE = 0; 116our $SLAVE = 0;
117
118our $NODE = asciibits nonce 16;
119our $RUNIQ = $NODE; # remote uniq value
120our $UNIQ = gen_uniq; # per-process/node unique cookie
121our $ID = "a";
120 122
121our %NODE; # node id to transport mapping, or "undef", for local node 123our %NODE; # node id to transport mapping, or "undef", for local node
122our (%PORT, %PORT_DATA); # local ports 124our (%PORT, %PORT_DATA); # local ports
123 125
124our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb) 126our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb)
323} 325}
324 326
325############################################################################# 327#############################################################################
326# self node code 328# self node code
327 329
330sub load_func($) {
331 my $func = $_[0];
332
333 unless (defined &$func) {
334 my $pkg = $func;
335 do {
336 $pkg =~ s/::[^:]+$//
337 or return sub { die "unable to resolve $func" };
338 eval "require $pkg";
339 } until defined &$func;
340 }
341
342 \&$func
343}
344
328our %node_req = ( 345our %node_req = (
329 # internal services 346 # internal services
330 347
331 # monitoring 348 # monitoring
332 mon0 => sub { # disable monitoring 349 mon0 => sub { # disable monitoring
357 374
358 # well-known-port lookup 375 # well-known-port lookup
359 lookup => sub { 376 lookup => sub {
360 my $name = shift; 377 my $name = shift;
361 my $port = $REG{$name}; 378 my $port = $REG{$name};
362 #TODO: check vailidity 379 #TODO: check validity
363 snd @_, $port; 380 snd @_, $port;
364 }, 381 },
365 382
366 # relay message to another node / generic echo 383 # relay message to another node / generic echo
367 relay => sub { 384 relay => sub {
368 &snd; 385 &snd;
386 },
387 relay_multiple => sub {
388 snd @$_ for @_
369 }, 389 },
370 390
371 # random garbage 391 # random garbage
372 eval => sub { 392 eval => sub {
373 my @res = eval shift; 393 my @res = eval shift;
380 # 400 #
381 }, 401 },
382); 402);
383 403
384$NODE{""} = $NODE{$NODE} = new AnyEvent::MP::Node::Self noderef => $NODE; 404$NODE{""} = $NODE{$NODE} = new AnyEvent::MP::Node::Self noderef => $NODE;
385$PORT{""} = sub { &{ $node_req{+shift} or return } }; 405$PORT{""} = sub {
406 my $tag = shift;
407 eval { &{ $node_req{$tag} ||= load_func $tag } };
408 $WARN->("error processing node message: $@") if $@;
409};
386 410
387=back 411=back
388 412
389=head1 SEE ALSO 413=head1 SEE ALSO
390 414

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines