1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
AnyEvent::MP::Global - some network-global services |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use AnyEvent::MP::Global; |
8 |
|
|
# -OR- |
9 |
|
|
aemp addservice AnyEvent::MP::Global:: |
10 |
|
|
|
11 |
|
|
=head1 DESCRIPTION |
12 |
|
|
|
13 |
|
|
This module provides an assortment of network-global functions: group name |
14 |
|
|
registration and non-local locks. |
15 |
|
|
|
16 |
|
|
It will also try to build and maintain a full mesh of all network nodes. |
17 |
|
|
|
18 |
root |
1.3 |
While it isn't mandatory to run the global services, running it on one |
19 |
|
|
node will automatically run it on all nodes. |
20 |
|
|
|
21 |
root |
1.1 |
=head1 GLOBALS AND FUNCTIONS |
22 |
|
|
|
23 |
|
|
=over 4 |
24 |
|
|
|
25 |
|
|
=cut |
26 |
|
|
|
27 |
|
|
package AnyEvent::MP::Global; |
28 |
|
|
|
29 |
|
|
use common::sense; |
30 |
|
|
use Carp (); |
31 |
|
|
use MIME::Base64 (); |
32 |
|
|
|
33 |
|
|
use AnyEvent::MP; |
34 |
|
|
use AnyEvent::MP::Kernel; |
35 |
|
|
|
36 |
|
|
our $VERSION = $AnyEvent::MP::VERSION; |
37 |
|
|
|
38 |
|
|
our $port = port; |
39 |
root |
1.3 |
our %other; # our rendevouz port on the other side |
40 |
|
|
|
41 |
|
|
sub connect { |
42 |
|
|
my ($noderef) = @_; |
43 |
root |
1.1 |
|
44 |
root |
1.3 |
# monitor them, silently die |
45 |
|
|
mon $noderef, psub { kil $SELF }; |
46 |
|
|
|
47 |
|
|
rcv $SELF, connect_nodes => sub { |
48 |
|
|
connect_node $_ for @_; |
49 |
|
|
}; |
50 |
|
|
} |
51 |
root |
1.1 |
|
52 |
|
|
sub mon_node { |
53 |
|
|
my ($noderef, $is_up) = @_; |
54 |
|
|
|
55 |
|
|
if ($is_up) { |
56 |
root |
1.3 |
# establish connection |
57 |
|
|
my $other = $other{$noderef} = spawn $noderef, "AnyEvent::MP::Global::connect", $NODE; |
58 |
root |
1.1 |
# request any other nodes possibly known to us |
59 |
root |
1.3 |
snd $other, connect_nodes => up_nodes; |
60 |
root |
1.2 |
} else { |
61 |
root |
1.3 |
kil delete $other{$noderef}; |
62 |
root |
1.1 |
} |
63 |
|
|
#warn "node<$noderef,$is_up>\n";#d# |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
mon_node $_, 1 |
67 |
|
|
for up_nodes; |
68 |
|
|
|
69 |
|
|
mon_nodes \&mon_node; |
70 |
|
|
|
71 |
|
|
=back |
72 |
|
|
|
73 |
|
|
=head1 SEE ALSO |
74 |
|
|
|
75 |
|
|
L<AnyEvent::MP>. |
76 |
|
|
|
77 |
|
|
=head1 AUTHOR |
78 |
|
|
|
79 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
80 |
|
|
http://home.schmorp.de/ |
81 |
|
|
|
82 |
|
|
=cut |
83 |
|
|
|
84 |
|
|
1 |
85 |
|
|
|