作者 crossoverJie

:bug: Fixing a bug.

1. :q 数组越界
2. 主动退出还出现重连
1 package com.crossoverjie.cim.client.handle; 1 package com.crossoverjie.cim.client.handle;
2 2
  3 +import com.crossoverjie.cim.client.service.ShutDownMsg;
3 import com.crossoverjie.cim.client.thread.ReConnectJob; 4 import com.crossoverjie.cim.client.thread.ReConnectJob;
4 import com.crossoverjie.cim.client.util.SpringBeanFactory; 5 import com.crossoverjie.cim.client.util.SpringBeanFactory;
5 import com.crossoverjie.cim.common.constant.Constants; 6 import com.crossoverjie.cim.common.constant.Constants;
@@ -37,6 +38,8 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt @@ -37,6 +38,8 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt
37 38
38 private ScheduledExecutorService scheduledExecutorService ; 39 private ScheduledExecutorService scheduledExecutorService ;
39 40
  41 + private ShutDownMsg shutDownMsg ;
  42 +
40 43
41 @Override 44 @Override
42 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 45 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
@@ -71,11 +74,20 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt @@ -71,11 +74,20 @@ public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProt
71 74
72 @Override 75 @Override
73 public void channelInactive(ChannelHandlerContext ctx) throws Exception { 76 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
74 - LOGGER.info("客户端断开了,重新连接!"); 77 +
  78 + if (shutDownMsg == null){
  79 + shutDownMsg = SpringBeanFactory.getBean(ShutDownMsg.class) ;
  80 + }
  81 +
  82 + //用户主动退出,不执行重连逻辑
  83 + if (shutDownMsg.checkStatus()){
  84 + return;
  85 + }
75 86
76 if (scheduledExecutorService == null){ 87 if (scheduledExecutorService == null){
77 scheduledExecutorService = SpringBeanFactory.getBean("scheduledTask",ScheduledExecutorService.class) ; 88 scheduledExecutorService = SpringBeanFactory.getBean("scheduledTask",ScheduledExecutorService.class) ;
78 } 89 }
  90 + LOGGER.info("客户端断开了,重新连接!");
79 // TODO: 2019-01-22 后期可以改为不用定时任务,连上后就关闭任务 节省性能。 91 // TODO: 2019-01-22 后期可以改为不用定时任务,连上后就关闭任务 节省性能。
80 scheduledExecutorService.scheduleAtFixedRate(new ReConnectJob(ctx),0,10, TimeUnit.SECONDS) ; 92 scheduledExecutorService.scheduleAtFixedRate(new ReConnectJob(ctx),0,10, TimeUnit.SECONDS) ;
81 } 93 }
  1 +package com.crossoverjie.cim.client.service;
  2 +
  3 +import org.springframework.stereotype.Component;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2019-02-27 16:17
  10 + * @since JDK 1.8
  11 + */
  12 +@Component
  13 +public class ShutDownMsg {
  14 + private boolean isCommand ;
  15 +
  16 + /**
  17 + * 置为用户主动退出状态
  18 + */
  19 + public void shutdown(){
  20 + isCommand = true ;
  21 + }
  22 +
  23 + public boolean checkStatus(){
  24 + return isCommand ;
  25 + }
  26 +}
@@ -25,6 +25,9 @@ public class QueryHistoryCommand implements InnerCommand { @@ -25,6 +25,9 @@ public class QueryHistoryCommand implements InnerCommand {
25 @Override 25 @Override
26 public void process(String msg) { 26 public void process(String msg) {
27 String[] split = msg.split(" "); 27 String[] split = msg.split(" ");
  28 + if (split.length < 2){
  29 + return;
  30 + }
28 String res = msgLogger.query(split[1]); 31 String res = msgLogger.query(split[1]);
29 System.out.println(res); 32 System.out.println(res);
30 } 33 }
@@ -4,6 +4,7 @@ import com.crossoverjie.cim.client.client.CIMClient; @@ -4,6 +4,7 @@ import com.crossoverjie.cim.client.client.CIMClient;
4 import com.crossoverjie.cim.client.service.InnerCommand; 4 import com.crossoverjie.cim.client.service.InnerCommand;
5 import com.crossoverjie.cim.client.service.MsgLogger; 5 import com.crossoverjie.cim.client.service.MsgLogger;
6 import com.crossoverjie.cim.client.service.RouteRequest; 6 import com.crossoverjie.cim.client.service.RouteRequest;
  7 +import com.crossoverjie.cim.client.service.ShutDownMsg;
7 import org.slf4j.Logger; 8 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,9 +37,14 @@ public class ShutDownCommand implements InnerCommand { @@ -36,9 +37,14 @@ public class ShutDownCommand implements InnerCommand {
36 @Resource(name = "callBackThreadPool") 37 @Resource(name = "callBackThreadPool")
37 private ThreadPoolExecutor executor; 38 private ThreadPoolExecutor executor;
38 39
  40 +
  41 + @Autowired
  42 + private ShutDownMsg shutDownMsg ;
  43 +
39 @Override 44 @Override
40 public void process(String msg) { 45 public void process(String msg) {
41 LOGGER.info("系统关闭中。。。。"); 46 LOGGER.info("系统关闭中。。。。");
  47 + shutDownMsg.shutdown();
42 routeRequest.offLine(); 48 routeRequest.offLine();
43 msgLogger.stop(); 49 msgLogger.stop();
44 executor.shutdown(); 50 executor.shutdown();
@@ -45,7 +45,7 @@ cim.clear.route.request.url=http://45.78.28.220:8083/offLine @@ -45,7 +45,7 @@ cim.clear.route.request.url=http://45.78.28.220:8083/offLine
45 #cim.clear.route.request.url=http://localhost:8083/offLine 45 #cim.clear.route.request.url=http://localhost:8083/offLine
46 46
47 # 客户端唯一ID 47 # 客户端唯一ID
48 -cim.user.id=1545574841528 48 +cim.user.id=1551152636573
49 cim.user.userName=zhangsan 49 cim.user.userName=zhangsan
50 50
51 # 回调线程队列大小 51 # 回调线程队列大小