Browse Source

定时采集中对采集超时处理完善

chenwen 1 year ago
parent
commit
0dd4e84ff5
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/main/java/com/hb/proj/gather/business/GatherTask.java

+ 10 - 4
src/main/java/com/hb/proj/gather/business/GatherTask.java

@@ -18,7 +18,7 @@ public class GatherTask implements Runnable{
 
 	private Channel  channel;
 	
-	private long cmdTimeout=35*1000; //指令等待回复超时时间 30s
+	private long cmdTimeout=25*1000; //指令等待回复超时时间 2次超时=50s  不能超过采集周期60s
 	
 	private int timeoutCount=0;  //超时发送指令次数
 	
@@ -28,6 +28,9 @@ public class GatherTask implements Runnable{
 	
 	@Override
 	public void run() {
+		//新的采集开始先复位 ATTR_KEY_PRE_TIME,timeoutCount
+		channel.attr(ChannelGroupMgr.ATTR_KEY_PRE_TIME).set(null);
+		timeoutCount=0;
 		
 		ByteBufAllocator alloc=channel.alloc(); 
 		synchronized(channel) {
@@ -104,7 +107,10 @@ public class GatherTask implements Runnable{
 					ZLOpdProtCMDEnum.DIAGRAM_POWER_3	
 					
 			};
+			
 			ByteBuf byteBuf=null;
+			timeoutCount=0 ;  //多值采集开始前复位该值(因为单值与多值有5分钟间隔,该间隔不能算作超时)
+			
 			for(ZLOpdProtCMDEnum cmd : cmds) {
 				
 				if(needCloseChannel()) {
@@ -150,7 +156,7 @@ public class GatherTask implements Runnable{
 		}
 		boolean isTimeout= ((new Date()).getTime()-pre.longValue())>(cmdTimeout-1000);
 		
-		/**
+		
 		if(!isTimeout) {
 			timeoutCount=0;  //有一次不超时就清空超时次数
 		}
@@ -159,8 +165,8 @@ public class GatherTask implements Runnable{
 		}
 		
 		return timeoutCount>1;  //多次超时(2次及以上)需要关闭通道,等待重连
-		**/
 		
-		return isTimeout;
+		
+		
 	}
 }