From 8e589b5a04d14b4847b1bd06c6ceb8f8e9f606df Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 15 Jun 2010 23:14:04 +0300 Subject: [PATCH] nicer code --- .../discovery/zen/fd/NodesFaultDetection.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index 7230ce761fc..a3f702416b3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -194,32 +194,34 @@ public class NodesFaultDetection extends AbstractComponent { } @Override public void handleResponse(PingResponse response) { - if (running) { - NodeFD nodeFD = nodesFD.get(node); - if (nodeFD != null) { - nodeFD.retryCount = 0; - threadPool.schedule(SendPingRequest.this, pingInterval); - } + if (!running) { + return; + } + NodeFD nodeFD = nodesFD.get(node); + if (nodeFD != null) { + nodeFD.retryCount = 0; + threadPool.schedule(SendPingRequest.this, pingInterval); } } @Override public void handleException(RemoteTransportException exp) { // check if the master node did not get switched on us... - if (running) { - NodeFD nodeFD = nodesFD.get(node); - if (nodeFD != null) { - int retryCount = ++nodeFD.retryCount; - logger.trace("Node [{}] failed to ping, retry [{}] out of [{}]", exp, node, retryCount, pingRetryCount); - if (retryCount >= pingRetryCount) { - logger.debug("Node [{}] failed on ping, tried [{}] times, each with [{}] timeout", node, pingRetryCount, pingRetryTimeout); - // not good, failure - if (nodesFD.remove(node) != null) { - notifyNodeFailure(node, "Failed on ping, tried [" + pingRetryCount + "] times, each with [" + pingRetryTimeout + "] timeout"); - } - } else { - // resend the request, not reschedule, rely on send timeout - transportService.sendRequest(node, PingRequestHandler.ACTION, new PingRequest(node.id()), pingRetryTimeout, this); + if (!running) { + return; + } + NodeFD nodeFD = nodesFD.get(node); + if (nodeFD != null) { + int retryCount = ++nodeFD.retryCount; + logger.trace("Node [{}] failed to ping, retry [{}] out of [{}]", exp, node, retryCount, pingRetryCount); + if (retryCount >= pingRetryCount) { + logger.debug("Node [{}] failed on ping, tried [{}] times, each with [{}] timeout", node, pingRetryCount, pingRetryTimeout); + // not good, failure + if (nodesFD.remove(node) != null) { + notifyNodeFailure(node, "Failed on ping, tried [" + pingRetryCount + "] times, each with [" + pingRetryTimeout + "] timeout"); } + } else { + // resend the request, not reschedule, rely on send timeout + transportService.sendRequest(node, PingRequestHandler.ACTION, new PingRequest(node.id()), pingRetryTimeout, this); } } }