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 15 private long latestRequestUnixtime;
16 16 private ServerResponse latestServerResponse;
17 17 private int errorServerResponseCount;
  18 + private boolean isIncrErrorServerResponseCount;
18 19  
19 20 public ServerInstance(String code, String url, int fixRateSec, int maxWaitSec) throws Exception {
20 21 super();
... ... @@ -30,6 +31,7 @@ public class ServerInstance implements Instance {
30 31  
31 32 @Override
32 33 public void flush() {
  34 + this.isIncrErrorServerResponseCount = false;
33 35 //如果小于设置的发送时间间隔,则不发送请求
34 36 if(!this.isLatestRequestGreateEqualFixRateSec()) {
35 37 return;
... ... @@ -43,10 +45,11 @@ public class ServerInstance implements Instance {
43 45 } catch(SocketTimeoutException timeError) {
44 46 this.latestServerResponse = ServerResponse.createOverdue();
45 47 } catch (Exception e) {
46   - this.latestServerResponse = ServerResponse.createException(e);
  48 + this.latestServerResponse = ServerResponse.createException(e);
47 49 }
48 50 if(this.latestServerResponse.isOverdue() || !this.latestServerResponse.isCodeOk()) {
49 51 ++this.errorServerResponseCount;
  52 + this.isIncrErrorServerResponseCount = true;
50 53 }
51 54 }
52 55  
... ... @@ -65,7 +68,7 @@ public class ServerInstance implements Instance {
65 68  
66 69 @Override
67 70 public boolean needReform() {
68   - return this.isLatestRequestGreateEqualFixRateSec()
  71 + return this.isIncrErrorServerResponseCount
69 72 && this.errorServerResponseCount>=DEFAULT_REFORM_MIN_ERROR_COUNT
70 73 && this.errorServerResponseCount<=DEFAULT_REFORM_MAX_ERROR_COUNT;
71 74 }
... ... @@ -125,4 +128,21 @@ public class ServerInstance implements Instance {
125 128 public void setLostServerResponseCount(int lostServerResponseCount) {
126 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 }
... ...