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 21 import org.springframework.stereotype.Component;
22 22  
23 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 30 * Created by panzhao on 2017/5/4.
... ... @@ -40,6 +44,17 @@ public class ClientApp {
40 44  
41 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 58 public static boolean dconnect(String device) {
44 59 boolean flag = false;
45 60 try {
... ... @@ -62,6 +77,7 @@ public class ClientApp {
62 77 flag = true;
63 78  
64 79 logger.info("dconnect...");
  80 + pdSession = session;
65 81 //SessionManager.getInstance().register(device, session);
66 82 } catch (Exception e) {
67 83 e.printStackTrace();
... ... @@ -87,6 +103,7 @@ public class ClientApp {
87 103 flag = true;
88 104  
89 105 logger.info("fconnect...");
  106 + pfSession = session;
90 107 } catch (Exception e) {
91 108 e.printStackTrace();
92 109 }
... ... @@ -95,7 +112,7 @@ public class ClientApp {
95 112  
96 113 public void init() {
97 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 117 pdDataConnector = new NioSocketConnector();
101 118  
... ... @@ -141,4 +158,30 @@ public class ClientApp {
141 158  
142 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 188 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/handler/PdClientHandler.java
1 1 package com.bsth.data.gpsdata.client.pd.handler;
2 2  
3   -import com.bsth.data.gpsdata.client.ClientApp;
4 3 import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5 4 import com.bsth.data.gpsdata.client.msg.IMessageBody;
6 5 import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
... ... @@ -45,7 +44,7 @@ public class PdClientHandler extends IoHandlerAdapter{
45 44 log.info("连网关设备编号:" + deviceId + "断开连接");
46 45 log.warn(deviceId + "网关设备注销");
47 46  
48   - ClientApp.dconnect(deviceId);
  47 + //ClientApp.dconnect(deviceId);
49 48 } else {
50 49 log.info("连网关设备编号:" + deviceId + "断开连接");
51 50 }
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/handler/PfClientHandler.java
1 1 package com.bsth.data.gpsdata.client.pf.handler;
2 2  
3   -import com.bsth.data.gpsdata.client.ClientApp;
4 3 import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5 4 import com.bsth.data.gpsdata.client.common.Protocol2BizUtil;
6 5 import com.bsth.data.gpsdata.client.msg.IMessageBody;
... ... @@ -44,7 +43,7 @@ public class PfClientHandler extends IoHandlerAdapter{
44 43 //SessionManager.getInstance().unregister(deviceId);
45 44 log.info("连老网关设备编号:" + deviceId + "断开连接");
46 45 log.warn(deviceId + "老网关设备注销");
47   - ClientApp.fconnect(deviceId);
  46 + //ClientApp.fconnect(deviceId);
48 47 }
49 48 }
50 49  
... ...