diff --git a/src/main/java/com/taover/heartbeat/bean/ServerInstance.java b/src/main/java/com/taover/heartbeat/bean/ServerInstance.java index 503060b..ac54c8d 100644 --- a/src/main/java/com/taover/heartbeat/bean/ServerInstance.java +++ b/src/main/java/com/taover/heartbeat/bean/ServerInstance.java @@ -15,6 +15,7 @@ public class ServerInstance implements Instance { private long latestRequestUnixtime; private ServerResponse latestServerResponse; private int errorServerResponseCount; + private boolean isIncrErrorServerResponseCount; public ServerInstance(String code, String url, int fixRateSec, int maxWaitSec) throws Exception { super(); @@ -30,6 +31,7 @@ public class ServerInstance implements Instance { @Override public void flush() { + this.isIncrErrorServerResponseCount = false; //如果小于设置的发送时间间隔,则不发送请求 if(!this.isLatestRequestGreateEqualFixRateSec()) { return; @@ -43,10 +45,11 @@ public class ServerInstance implements Instance { } catch(SocketTimeoutException timeError) { this.latestServerResponse = ServerResponse.createOverdue(); } catch (Exception e) { - this.latestServerResponse = ServerResponse.createException(e); + this.latestServerResponse = ServerResponse.createException(e); } if(this.latestServerResponse.isOverdue() || !this.latestServerResponse.isCodeOk()) { ++this.errorServerResponseCount; + this.isIncrErrorServerResponseCount = true; } } @@ -65,7 +68,7 @@ public class ServerInstance implements Instance { @Override public boolean needReform() { - return this.isLatestRequestGreateEqualFixRateSec() + return this.isIncrErrorServerResponseCount && this.errorServerResponseCount>=DEFAULT_REFORM_MIN_ERROR_COUNT && this.errorServerResponseCount<=DEFAULT_REFORM_MAX_ERROR_COUNT; } @@ -125,4 +128,21 @@ public class ServerInstance implements Instance { public void setLostServerResponseCount(int lostServerResponseCount) { this.errorServerResponseCount = lostServerResponseCount; } + + public int getErrorServerResponseCount() { + return errorServerResponseCount; + } + + public void setErrorServerResponseCount(int errorServerResponseCount) { + this.errorServerResponseCount = errorServerResponseCount; + } + + public boolean isIncrErrorServerResponseCount() { + return isIncrErrorServerResponseCount; + } + + public void setIncrErrorServerResponseCount(boolean isIncrErrorServerResponseCount) { + this.isIncrErrorServerResponseCount = isIncrErrorServerResponseCount; + } + } -- libgit2 0.21.2