Commit 460b9760948c10b3d8b0afcc58d34b74a5707f99

Authored by 潘钊
1 parent a308a846

update...

src/main/java/com/bsth/data/gpsdata/client/ClientApp.java
@@ -21,6 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
22 22
23 import java.net.InetSocketAddress; 23 import java.net.InetSocketAddress;
  24 +import java.util.concurrent.Executors;
  25 +import java.util.concurrent.ScheduledExecutorService;
  26 +import java.util.concurrent.ThreadFactory;
  27 +import java.util.concurrent.TimeUnit;
24 28
25 /** 29 /**
26 * Created by panzhao on 2017/5/4. 30 * Created by panzhao on 2017/5/4.
@@ -40,6 +44,17 @@ public class ClientApp { @@ -40,6 +44,17 @@ public class ClientApp {
40 44
41 static Logger logger = LoggerFactory.getLogger(ClientApp.class); 45 static Logger logger = LoggerFactory.getLogger(ClientApp.class);
42 46
  47 + private ScheduledExecutorService sexec = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
  48 +
  49 + @Override
  50 + public Thread newThread(Runnable r) {
  51 + // TODO Auto-generated method stub
  52 + Thread t = new Thread(r);
  53 + t.setName("SessionCheckExecutor");
  54 + return t;
  55 + }
  56 + });
  57 +
43 public static boolean dconnect(String device) { 58 public static boolean dconnect(String device) {
44 boolean flag = false; 59 boolean flag = false;
45 try { 60 try {
@@ -62,6 +77,7 @@ public class ClientApp { @@ -62,6 +77,7 @@ public class ClientApp {
62 flag = true; 77 flag = true;
63 78
64 logger.info("dconnect..."); 79 logger.info("dconnect...");
  80 + pdSession = session;
65 //SessionManager.getInstance().register(device, session); 81 //SessionManager.getInstance().register(device, session);
66 } catch (Exception e) { 82 } catch (Exception e) {
67 e.printStackTrace(); 83 e.printStackTrace();
@@ -87,6 +103,7 @@ public class ClientApp { @@ -87,6 +103,7 @@ public class ClientApp {
87 flag = true; 103 flag = true;
88 104
89 logger.info("fconnect..."); 105 logger.info("fconnect...");
  106 + pfSession = session;
90 } catch (Exception e) { 107 } catch (Exception e) {
91 e.printStackTrace(); 108 e.printStackTrace();
92 } 109 }
@@ -95,7 +112,7 @@ public class ClientApp { @@ -95,7 +112,7 @@ public class ClientApp {
95 112
96 public void init() { 113 public void init() {
97 //exec = Executors.newFixedThreadPool(4); 114 //exec = Executors.newFixedThreadPool(4);
98 - //sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES); 115 + sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES);
99 /*******************************浦东********************************/ 116 /*******************************浦东********************************/
100 pdDataConnector = new NioSocketConnector(); 117 pdDataConnector = new NioSocketConnector();
101 118
@@ -141,4 +158,30 @@ public class ClientApp { @@ -141,4 +158,30 @@ public class ClientApp {
141 158
142 gpsBeforeBuffer.init(); 159 gpsBeforeBuffer.init();
143 } 160 }
  161 +
  162 +
  163 + static IoSession pdSession;
  164 + static IoSession pfSession;
  165 + final class SessionChecker implements Runnable {
  166 +
  167 + @Override
  168 + public void run() {
  169 + // TODO Auto-generated method stub
  170 + try {
  171 +
  172 + if(!pdSession.isActive()){
  173 + logger.warn("浦东设备注销");
  174 + ClientApp.pdreconn();
  175 + }
  176 +
  177 + if(!pfSession.isActive()){
  178 + logger.warn("浦东转发设备注销");
  179 + ClientApp.pfreconn();
  180 + }
  181 + } catch (Exception e) {
  182 + logger.error("SessionChecker异常", e);
  183 + }
  184 + }
  185 +
  186 + }
144 } 187 }
145 \ No newline at end of file 188 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/client/pd/handler/PdClientHandler.java
1 package com.bsth.data.gpsdata.client.pd.handler; 1 package com.bsth.data.gpsdata.client.pd.handler;
2 2
3 -import com.bsth.data.gpsdata.client.ClientApp;  
4 import com.bsth.data.gpsdata.client.GpsBeforeBuffer; 3 import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5 import com.bsth.data.gpsdata.client.msg.IMessageBody; 4 import com.bsth.data.gpsdata.client.msg.IMessageBody;
6 import com.bsth.data.gpsdata.client.pd.protocol.PdMessage; 5 import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
@@ -45,7 +44,7 @@ public class PdClientHandler extends IoHandlerAdapter{ @@ -45,7 +44,7 @@ public class PdClientHandler extends IoHandlerAdapter{
45 log.info("连网关设备编号:" + deviceId + "断开连接"); 44 log.info("连网关设备编号:" + deviceId + "断开连接");
46 log.warn(deviceId + "网关设备注销"); 45 log.warn(deviceId + "网关设备注销");
47 46
48 - ClientApp.dconnect(deviceId); 47 + //ClientApp.dconnect(deviceId);
49 } else { 48 } else {
50 log.info("连网关设备编号:" + deviceId + "断开连接"); 49 log.info("连网关设备编号:" + deviceId + "断开连接");
51 } 50 }
src/main/java/com/bsth/data/gpsdata/client/pf/handler/PfClientHandler.java
1 package com.bsth.data.gpsdata.client.pf.handler; 1 package com.bsth.data.gpsdata.client.pf.handler;
2 2
3 -import com.bsth.data.gpsdata.client.ClientApp;  
4 import com.bsth.data.gpsdata.client.GpsBeforeBuffer; 3 import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5 import com.bsth.data.gpsdata.client.common.Protocol2BizUtil; 4 import com.bsth.data.gpsdata.client.common.Protocol2BizUtil;
6 import com.bsth.data.gpsdata.client.msg.IMessageBody; 5 import com.bsth.data.gpsdata.client.msg.IMessageBody;
@@ -44,7 +43,7 @@ public class PfClientHandler extends IoHandlerAdapter{ @@ -44,7 +43,7 @@ public class PfClientHandler extends IoHandlerAdapter{
44 //SessionManager.getInstance().unregister(deviceId); 43 //SessionManager.getInstance().unregister(deviceId);
45 log.info("连老网关设备编号:" + deviceId + "断开连接"); 44 log.info("连老网关设备编号:" + deviceId + "断开连接");
46 log.warn(deviceId + "老网关设备注销"); 45 log.warn(deviceId + "老网关设备注销");
47 - ClientApp.fconnect(deviceId); 46 + //ClientApp.fconnect(deviceId);
48 } 47 }
49 } 48 }
50 49