|
@@ -1,11 +1,6 @@
|
|
|
package com.tsi.comm.server.tcp.handler;
|
|
package com.tsi.comm.server.tcp.handler;
|
|
|
|
|
|
|
|
-import com.tsi.comm.server.service.TsiQueueDistributorService;
|
|
|
|
|
-import com.tsi.comm.server.xnet.NettyUtils;
|
|
|
|
|
import com.tsi.comm.server.config.TsiCvimServerConfig;
|
|
import com.tsi.comm.server.config.TsiCvimServerConfig;
|
|
|
-import com.tsi.comm.server.vo.mariadb.AbstractDbmsVo;
|
|
|
|
|
-import com.tsi.comm.server.vo.mariadb.AlarmOccrVo;
|
|
|
|
|
-import com.tsi.comm.server.vo.mariadb.NodeStatusVo;
|
|
|
|
|
import com.tsi.comm.server.process.dbms.TsiCvimDbmsProcess;
|
|
import com.tsi.comm.server.process.dbms.TsiCvimDbmsProcess;
|
|
|
import com.tsi.comm.server.process.packet.TsiChannelSession;
|
|
import com.tsi.comm.server.process.packet.TsiChannelSession;
|
|
|
import com.tsi.comm.server.process.packet.TsiCvimPacketProcess;
|
|
import com.tsi.comm.server.process.packet.TsiCvimPacketProcess;
|
|
@@ -14,8 +9,13 @@ import com.tsi.comm.server.protocol.TsiCpuDisconnected;
|
|
|
import com.tsi.comm.server.repository.TsiAlarmManager;
|
|
import com.tsi.comm.server.repository.TsiAlarmManager;
|
|
|
import com.tsi.comm.server.repository.TsiNodeManager;
|
|
import com.tsi.comm.server.repository.TsiNodeManager;
|
|
|
import com.tsi.comm.server.repository.TsiSessionManager;
|
|
import com.tsi.comm.server.repository.TsiSessionManager;
|
|
|
|
|
+import com.tsi.comm.server.service.TsiQueueDistributorService;
|
|
|
import com.tsi.comm.server.vo.TsiAlarmConfigVo;
|
|
import com.tsi.comm.server.vo.TsiAlarmConfigVo;
|
|
|
import com.tsi.comm.server.vo.TsiNodeVo;
|
|
import com.tsi.comm.server.vo.TsiNodeVo;
|
|
|
|
|
+import com.tsi.comm.server.vo.mariadb.AbstractDbmsVo;
|
|
|
|
|
+import com.tsi.comm.server.vo.mariadb.AlarmOccrVo;
|
|
|
|
|
+import com.tsi.comm.server.vo.mariadb.NodeStatusVo;
|
|
|
|
|
+import com.tsi.comm.server.xnet.NettyUtils;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandler;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
@@ -59,8 +59,18 @@ public class CvimServerInboundMessageHandler extends ChannelInboundHandlerAdapte
|
|
|
final String remoteIpAddr = NettyUtils.getRemoteIpAddress(ctx.channel());
|
|
final String remoteIpAddr = NettyUtils.getRemoteIpAddress(ctx.channel());
|
|
|
log.info("--channelActive: {}, {} Sessions.", remoteIpAddr, sessions);
|
|
log.info("--channelActive: {}, {} Sessions.", remoteIpAddr, sessions);
|
|
|
TsiNodeVo ipNodeVo = this.nodeManager.getIpAddr(remoteIpAddr);
|
|
TsiNodeVo ipNodeVo = this.nodeManager.getIpAddr(remoteIpAddr);
|
|
|
- if (ipNodeVo != null) {
|
|
|
|
|
|
|
+ if (ipNodeVo == null) {
|
|
|
|
|
+ this.alarmManager.reportUnknownIp(remoteIpAddr);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
TsiChannelSession.sessionActive(ipNodeVo, remoteIpAddr);
|
|
TsiChannelSession.sessionActive(ipNodeVo, remoteIpAddr);
|
|
|
|
|
+// if (ipNodeVo.isConnect()) {
|
|
|
|
|
+// // 이미 연결된 상태라면 새 채널을 종료, 이전 채널이 통신을 수행중일수 있으므로 현재 채널을 종료시킴
|
|
|
|
|
+// log.warn("--channelActive: {}, Duplicate connection detected, closing new channel: {}",
|
|
|
|
|
+// ipNodeVo.getKey(), remoteIpAddr);
|
|
|
|
|
+// ctx.channel().close();
|
|
|
|
|
+// return;
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
ctx.fireChannelActive();
|
|
ctx.fireChannelActive();
|
|
|
}
|
|
}
|
|
@@ -84,19 +94,19 @@ public class CvimServerInboundMessageHandler extends ChannelInboundHandlerAdapte
|
|
|
packet.setObj(nodeVo);
|
|
packet.setObj(nodeVo);
|
|
|
this.packetProcess.add(packet, nodeVo.getPktQIdx()); // 패킷인덱스큐로 데이터 전송
|
|
this.packetProcess.add(packet, nodeVo.getPktQIdx()); // 패킷인덱스큐로 데이터 전송
|
|
|
}
|
|
}
|
|
|
- log.info("channelInactive: Node {}, Channel close: {}", nodeVo.getNodeId(), remoteIpAddr);
|
|
|
|
|
|
|
+ log.info("channelInactive: Node {}, {}, sessions: {}", nodeVo.getNodeId(), remoteIpAddr, sessions);
|
|
|
|
|
|
|
|
TsiChannelSession.sessionInactive(nodeVo, remoteIpAddr);
|
|
TsiChannelSession.sessionInactive(nodeVo, remoteIpAddr);
|
|
|
|
|
|
|
|
- nodeVo.setConnect(null);
|
|
|
|
|
this.sessionManager.removeChannel(ctx.channel());
|
|
this.sessionManager.removeChannel(ctx.channel());
|
|
|
ctx.channel().attr(TsiSessionManager.TSI_NODE_ATTRIBUTE_KEY).set(null);
|
|
ctx.channel().attr(TsiSessionManager.TSI_NODE_ATTRIBUTE_KEY).set(null);
|
|
|
|
|
|
|
|
this.queueDistributorService.releaseQueue(nodeVo); // 작업큐를 할당을 해제한다.
|
|
this.queueDistributorService.releaseQueue(nodeVo); // 작업큐를 할당을 해제한다.
|
|
|
|
|
+ nodeVo.setConnect(null);
|
|
|
}
|
|
}
|
|
|
- else {
|
|
|
|
|
- log.info("channelInactive: {}, {} Sessions.", remoteIpAddr, sessions);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// else {
|
|
|
|
|
+// log.info("channelInactive: {}, {} Sessions.", remoteIpAddr, sessions);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
ctx.fireChannelInactive();
|
|
ctx.fireChannelInactive();
|
|
|
}
|
|
}
|
|
@@ -106,27 +116,36 @@ public class CvimServerInboundMessageHandler extends ChannelInboundHandlerAdapte
|
|
|
if (e instanceof IdleStateEvent) {
|
|
if (e instanceof IdleStateEvent) {
|
|
|
IdleStateEvent evt = (IdleStateEvent) e;
|
|
IdleStateEvent evt = (IdleStateEvent) e;
|
|
|
TsiNodeVo nodeVo = this.sessionManager.getNodeVo(ctx.channel());
|
|
TsiNodeVo nodeVo = this.sessionManager.getNodeVo(ctx.channel());
|
|
|
-// if (nodeVo != null) {
|
|
|
|
|
-// log.error("{}.userEventTriggered: {}, {}, {}", this.getClass().getSimpleName(), nodeVo.getNodeId(), ctx.channel(), evt.state().toString());
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
// 연결이 완료된 후 송수신 데이터가 일정시간 동안 없을 경우 이곳에서 처리
|
|
// 연결이 완료된 후 송수신 데이터가 일정시간 동안 없을 경우 이곳에서 처리
|
|
|
if (evt.state() == IdleState.READER_IDLE) {
|
|
if (evt.state() == IdleState.READER_IDLE) {
|
|
|
|
|
+ String remoteIpAddr = NettyUtils.getRemoteIpAddress(ctx.channel());
|
|
|
if (nodeVo == null) {
|
|
if (nodeVo == null) {
|
|
|
|
|
+ log.warn("userEventTriggered: Recv Timeout: {}", remoteIpAddr);
|
|
|
// 통신 접속 후 수신 데이터가 없이 READ 타임아웃이 발생한 경우임
|
|
// 통신 접속 후 수신 데이터가 없이 READ 타임아웃이 발생한 경우임
|
|
|
if (this.alarmManager.checkAlarm(TsiAlarmConfigVo.COMM_02)) {
|
|
if (this.alarmManager.checkAlarm(TsiAlarmConfigVo.COMM_02)) {
|
|
|
AlarmOccrVo alarm = new AlarmOccrVo(AbstractDbmsVo.DBMS_ALARM_OCCR_HS);
|
|
AlarmOccrVo alarm = new AlarmOccrVo(AbstractDbmsVo.DBMS_ALARM_OCCR_HS);
|
|
|
alarm.setAlarmCode(TsiAlarmConfigVo.COMM_02);
|
|
alarm.setAlarmCode(TsiAlarmConfigVo.COMM_02);
|
|
|
- alarm.setAlarmTarget(NettyUtils.getRemoteIpAddress(ctx.channel()));
|
|
|
|
|
- alarm.setAlarmValue(NettyUtils.getRemoteIpAddress(ctx.channel()));
|
|
|
|
|
|
|
+ alarm.setAlarmTarget(remoteIpAddr);
|
|
|
|
|
+ alarm.setAlarmValue(remoteIpAddr);
|
|
|
this.dbmsProcess.add(alarm, (int) Thread.currentThread().getId());
|
|
this.dbmsProcess.add(alarm, (int) Thread.currentThread().getId());
|
|
|
- log.warn("{}.userEventTriggered: Recv Timeout: {}", this.getClass().getSimpleName(), NettyUtils.getRemoteIpAddress(ctx.channel()));
|
|
|
|
|
}
|
|
}
|
|
|
- ctx.channel().disconnect();
|
|
|
|
|
|
|
+// ctx.channel().disconnect();
|
|
|
ctx.channel().close();
|
|
ctx.channel().close();
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
|
|
+ log.warn("userEventTriggered: Recv Timeout: {}, {}", remoteIpAddr, nodeVo.getNodeId());
|
|
|
// 통신 접속 후 데이터를 한번이라도 수신한 경우에는 스케쥴러에서 처리한다.
|
|
// 통신 접속 후 데이터를 한번이라도 수신한 경우에는 스케쥴러에서 처리한다.
|
|
|
|
|
+ if (this.alarmManager.checkAlarm(TsiAlarmConfigVo.COMM_02)) {
|
|
|
|
|
+ AlarmOccrVo alarm = new AlarmOccrVo(AbstractDbmsVo.DBMS_ALARM_OCCR_HS);
|
|
|
|
|
+ alarm.setAlarmCode(TsiAlarmConfigVo.COMM_02);
|
|
|
|
|
+ alarm.setAlarmTarget(nodeVo.getKey());
|
|
|
|
|
+ alarm.setAlarmValue(remoteIpAddr);
|
|
|
|
|
+ this.dbmsProcess.add(alarm, (int) Thread.currentThread().getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TsiChannelSession.sessionTimeout(nodeVo, NettyUtils.getRemoteIpAddress(ctx.channel()));
|
|
|
|
|
+
|
|
|
|
|
+ ctx.channel().close();
|
|
|
}
|
|
}
|
|
|
} else if (evt.state() == IdleState.WRITER_IDLE) {
|
|
} else if (evt.state() == IdleState.WRITER_IDLE) {
|
|
|
log.error("{}.userEventTriggered: WRITER_IDLE: {}", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()));
|
|
log.error("{}.userEventTriggered: WRITER_IDLE: {}", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()));
|