… | |
… | |
35 | |
35 | |
36 | sub init { |
36 | sub init { |
37 | # |
37 | # |
38 | } |
38 | } |
39 | |
39 | |
|
|
40 | #d# only needed for bad global code at the moment |
|
|
41 | sub transport_error { |
|
|
42 | } |
|
|
43 | |
40 | sub send { |
44 | sub send { |
41 | &{ shift->{send} } |
45 | &{ shift->{send} } |
42 | } |
46 | } |
43 | |
47 | |
44 | # nodes reachable via the network |
48 | # nodes reachable via the network |
45 | package AnyEvent::MP::Node::External; |
49 | package AnyEvent::MP::Node::Remote; |
46 | |
50 | |
47 | use base "AnyEvent::MP::Node"; |
51 | use base "AnyEvent::MP::Node"; |
48 | |
52 | |
49 | # called at init time, mostly sets {send} |
53 | # called at init time, mostly sets {send} |
50 | sub transport_reset { |
54 | sub transport_reset { |
… | |
… | |
109 | $transport_send->($_) |
113 | $transport_send->($_) |
110 | for @{ delete $self->{queue} || [] }; |
114 | for @{ delete $self->{queue} || [] }; |
111 | } |
115 | } |
112 | |
116 | |
113 | sub connect { |
117 | sub connect { |
114 | my ($self, @addresses) = @_; |
118 | my ($self) = @_; |
115 | |
119 | |
116 | return if $self->{transport}; |
120 | return if $self->{transport}; |
|
|
121 | return if $self->{connect_w}; |
117 | |
122 | |
118 | Scalar::Util::weaken $self; |
123 | Scalar::Util::weaken $self; |
119 | |
124 | |
120 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
125 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
121 | |
126 | |
122 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
127 | $self->{connect_to} ||= AE::timer $monitor, 0, sub { |
123 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
128 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
124 | }; |
129 | }; |
125 | |
130 | |
|
|
131 | # maybe @$addresses? |
|
|
132 | my @addresses = @{ $AnyEvent::MP::Kernel::GLOBAL_DB{"'l"}{$self->{id}} }; |
|
|
133 | |
126 | return unless @addresses; |
134 | unless (@addresses) { |
127 | |
135 | # on global nodes, all bets are off now - we either know the node, or we don't |
128 | if ($self->{connect_w}) { |
136 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
129 | # sometimes we get told about new addresses after we started to connect |
137 | $self->{connect_w} = AnyEvent::MP::Kernel::global_req (g_find => $self->{id}); |
130 | unshift @{$self->{connect_addr}}, @addresses; |
138 | } |
131 | return; |
139 | return; |
132 | } |
140 | } |
133 | |
141 | |
134 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
142 | $self->{connect_addr} = \@addresses; # a bit weird, but efficient |
135 | |
143 | |
… | |
… | |
142 | |
150 | |
143 | $interval = 0.4 if $interval < 0.4; |
151 | $interval = 0.4 if $interval < 0.4; |
144 | |
152 | |
145 | my @endpoints; |
153 | my @endpoints; |
146 | |
154 | |
147 | $self->{connect_w} = AE::timer 0.050 * rand, $interval * (0.9 + 0.1 * rand), sub { |
155 | $self->{connect_w} = AE::timer 0, $interval * (0.9 + 0.1 * rand), sub { |
148 | @endpoints = @addresses |
156 | @endpoints = @addresses |
149 | unless @endpoints; |
157 | unless @endpoints; |
150 | |
158 | |
151 | my $endpoint = shift @endpoints; |
159 | my $endpoint = shift @endpoints; |
152 | |
160 | |
… | |
… | |
164 | } |
172 | } |
165 | |
173 | |
166 | sub kill { |
174 | sub kill { |
167 | my ($self, $port, @reason) = @_; |
175 | my ($self, $port, @reason) = @_; |
168 | |
176 | |
169 | $self->send (["", kil => $port, @reason]); |
177 | $self->{send} (["", kil => $port, @reason]); |
170 | } |
178 | } |
171 | |
179 | |
172 | sub monitor { |
180 | sub monitor { |
173 | my ($self, $portid, $cb) = @_; |
181 | my ($self, $portid, $cb) = @_; |
174 | |
182 | |
… | |
… | |
191 | unless (@$list) { |
199 | unless (@$list) { |
192 | $self->send (["", mon0 => $portid]); |
200 | $self->send (["", mon0 => $portid]); |
193 | delete $self->{monitor}{$portid}; |
201 | delete $self->{monitor}{$portid}; |
194 | } |
202 | } |
195 | } |
203 | } |
196 | |
|
|
197 | # used for direct slave connections as well |
|
|
198 | package AnyEvent::MP::Node::Direct; |
|
|
199 | |
|
|
200 | use base "AnyEvent::MP::Node::External"; |
|
|
201 | |
204 | |
202 | package AnyEvent::MP::Node::Self; |
205 | package AnyEvent::MP::Node::Self; |
203 | |
206 | |
204 | use base "AnyEvent::MP::Node"; |
207 | use base "AnyEvent::MP::Node"; |
205 | |
208 | |