作者 crossoverJie

:bug: Fixing a bug.

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