disconnect from unicast nodes before raising event

This commit is contained in:
Shay Banon 2012-09-22 19:38:34 +02:00
parent aa435a288b
commit d5e11fdcd9
1 changed files with 5 additions and 3 deletions

View File

@ -182,12 +182,12 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
public void run() { public void run() {
sendPings(timeout, TimeValue.timeValueMillis(timeout.millis() / 2), sendPingsHandler); sendPings(timeout, TimeValue.timeValueMillis(timeout.millis() / 2), sendPingsHandler);
ConcurrentMap<DiscoveryNode, PingResponse> responses = receivedResponses.remove(sendPingsHandler.id()); ConcurrentMap<DiscoveryNode, PingResponse> responses = receivedResponses.remove(sendPingsHandler.id());
listener.onPing(responses.values().toArray(new PingResponse[responses.size()])); sendPingsHandler.close();
for (DiscoveryNode node : sendPingsHandler.nodeToDisconnect) { for (DiscoveryNode node : sendPingsHandler.nodeToDisconnect) {
logger.trace("[{}] disconnecting from {}", sendPingsHandler.id(), node); logger.trace("[{}] disconnecting from {}", sendPingsHandler.id(), node);
transportService.disconnectFromNode(node); transportService.disconnectFromNode(node);
} }
sendPingsHandler.close(); listener.onPing(responses.values().toArray(new PingResponse[responses.size()]));
} }
}); });
} }
@ -226,7 +226,6 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
executor.shutdownNow(); executor.shutdownNow();
executor = null; executor = null;
} }
nodeToDisconnect.clear();
} }
} }
@ -266,6 +265,9 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
@Override @Override
public void run() { public void run() {
try { try {
if (sendPingsHandler.isClosed()) {
return;
}
// connect to the node, see if we manage to do it, if not, bail // connect to the node, see if we manage to do it, if not, bail
if (!nodeFoundByAddress) { if (!nodeFoundByAddress) {
logger.trace("[{}] connecting (light) to {}", sendPingsHandler.id(), nodeToSend); logger.trace("[{}] connecting (light) to {}", sendPingsHandler.id(), nodeToSend);