Commit 7092f8c584777b3512fb811ee08718760c8fc06d

Authored by wangbin
1 parent 7c217d06
Exists in master

fix a bug

src/main/java/com/taover/heartbeat/bean/ServerInstance.java
@@ -15,6 +15,7 @@ public class ServerInstance implements Instance { @@ -15,6 +15,7 @@ public class ServerInstance implements Instance {
15 private long latestRequestUnixtime; 15 private long latestRequestUnixtime;
16 private ServerResponse latestServerResponse; 16 private ServerResponse latestServerResponse;
17 private int errorServerResponseCount; 17 private int errorServerResponseCount;
  18 + private boolean isIncrErrorServerResponseCount;
18 19
19 public ServerInstance(String code, String url, int fixRateSec, int maxWaitSec) throws Exception { 20 public ServerInstance(String code, String url, int fixRateSec, int maxWaitSec) throws Exception {
20 super(); 21 super();
@@ -30,6 +31,7 @@ public class ServerInstance implements Instance { @@ -30,6 +31,7 @@ public class ServerInstance implements Instance {
30 31
31 @Override 32 @Override
32 public void flush() { 33 public void flush() {
  34 + this.isIncrErrorServerResponseCount = false;
33 //如果小于设置的发送时间间隔,则不发送请求 35 //如果小于设置的发送时间间隔,则不发送请求
34 if(!this.isLatestRequestGreateEqualFixRateSec()) { 36 if(!this.isLatestRequestGreateEqualFixRateSec()) {
35 return; 37 return;
@@ -43,10 +45,11 @@ public class ServerInstance implements Instance { @@ -43,10 +45,11 @@ public class ServerInstance implements Instance {
43 } catch(SocketTimeoutException timeError) { 45 } catch(SocketTimeoutException timeError) {
44 this.latestServerResponse = ServerResponse.createOverdue(); 46 this.latestServerResponse = ServerResponse.createOverdue();
45 } catch (Exception e) { 47 } catch (Exception e) {
46 - this.latestServerResponse = ServerResponse.createException(e); 48 + this.latestServerResponse = ServerResponse.createException(e);
47 } 49 }
48 if(this.latestServerResponse.isOverdue() || !this.latestServerResponse.isCodeOk()) { 50 if(this.latestServerResponse.isOverdue() || !this.latestServerResponse.isCodeOk()) {
49 ++this.errorServerResponseCount; 51 ++this.errorServerResponseCount;
  52 + this.isIncrErrorServerResponseCount = true;
50 } 53 }
51 } 54 }
52 55
@@ -65,7 +68,7 @@ public class ServerInstance implements Instance { @@ -65,7 +68,7 @@ public class ServerInstance implements Instance {
65 68
66 @Override 69 @Override
67 public boolean needReform() { 70 public boolean needReform() {
68 - return this.isLatestRequestGreateEqualFixRateSec() 71 + return this.isIncrErrorServerResponseCount
69 && this.errorServerResponseCount>=DEFAULT_REFORM_MIN_ERROR_COUNT 72 && this.errorServerResponseCount>=DEFAULT_REFORM_MIN_ERROR_COUNT
70 && this.errorServerResponseCount<=DEFAULT_REFORM_MAX_ERROR_COUNT; 73 && this.errorServerResponseCount<=DEFAULT_REFORM_MAX_ERROR_COUNT;
71 } 74 }
@@ -125,4 +128,21 @@ public class ServerInstance implements Instance { @@ -125,4 +128,21 @@ public class ServerInstance implements Instance {
125 public void setLostServerResponseCount(int lostServerResponseCount) { 128 public void setLostServerResponseCount(int lostServerResponseCount) {
126 this.errorServerResponseCount = lostServerResponseCount; 129 this.errorServerResponseCount = lostServerResponseCount;
127 } 130 }
  131 +
  132 + public int getErrorServerResponseCount() {
  133 + return errorServerResponseCount;
  134 + }
  135 +
  136 + public void setErrorServerResponseCount(int errorServerResponseCount) {
  137 + this.errorServerResponseCount = errorServerResponseCount;
  138 + }
  139 +
  140 + public boolean isIncrErrorServerResponseCount() {
  141 + return isIncrErrorServerResponseCount;
  142 + }
  143 +
  144 + public void setIncrErrorServerResponseCount(boolean isIncrErrorServerResponseCount) {
  145 + this.isIncrErrorServerResponseCount = isIncrErrorServerResponseCount;
  146 + }
  147 +
128 } 148 }