… | |
… | |
112 | |
112 | |
113 | sub connect { |
113 | sub connect { |
114 | my ($self) = @_; |
114 | my ($self) = @_; |
115 | |
115 | |
116 | return if $self->{transport}; |
116 | return if $self->{transport}; |
|
|
117 | return if $self->{connect_w}; |
117 | |
118 | |
118 | Scalar::Util::weaken $self; |
119 | Scalar::Util::weaken $self; |
119 | |
120 | |
120 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
121 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
121 | |
122 | |
… | |
… | |
128 | $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} |
129 | $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} |
129 | || $AnyEvent::MP::Kernel::NODE_ADDR->{$self->{id}} |
130 | || $AnyEvent::MP::Kernel::NODE_ADDR->{$self->{id}} |
130 | }; |
131 | }; |
131 | |
132 | |
132 | unless (@addresses) { |
133 | unless (@addresses) { |
133 | # on global nodes, all betsa re off now - we either know the node, or we don't |
134 | # on global nodes, all bets are off now - we either know the node, or we don't |
134 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
135 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
135 | $self->{connect_w} = AnyEvent::MP::Kernel::global_req ( |
136 | $self->{connect_w} = AnyEvent::MP::Kernel::global_req ( |
136 | g_find => $self->{id}, |
137 | g_find => $self->{id}, |
137 | sub { |
138 | sub { |
138 | return unless $self; # just to be sure |
139 | return unless $self; # just to be sure |
139 | return unless @{ $_[0] }; |
140 | return unless @{ $_[0] }; |
140 | |
141 | |
141 | local $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} = $_[0]; #d# UGLY |
142 | local $AnyEvent::MP::Kernel::GLOBAL_ADDR->{$self->{id}} = $_[0]; #d# UGLY |
|
|
143 | delete $self->{connect_w}; |
142 | $self->connect; |
144 | $self->connect; |
143 | } |
145 | } |
144 | ); |
146 | ); |
145 | } |
147 | } |
146 | |
148 | |
… | |
… | |
158 | |
160 | |
159 | $interval = 0.4 if $interval < 0.4; |
161 | $interval = 0.4 if $interval < 0.4; |
160 | |
162 | |
161 | my @endpoints; |
163 | my @endpoints; |
162 | |
164 | |
163 | $self->{connect_w} = AE::timer 0.050 * rand, $interval * (0.9 + 0.1 * rand), sub { |
165 | $self->{connect_w} = AE::timer 0, $interval * (0.9 + 0.1 * rand), sub { |
164 | @endpoints = @addresses |
166 | @endpoints = @addresses |
165 | unless @endpoints; |
167 | unless @endpoints; |
166 | |
168 | |
167 | my $endpoint = shift @endpoints; |
169 | my $endpoint = shift @endpoints; |
168 | |
170 | |