shjung 10 月之前
父節點
當前提交
c21e860d10

+ 2 - 0
src/main/java/com/evp/comm/server/entity/TbEvpsCenter.java

@@ -1,6 +1,7 @@
 package com.evp.comm.server.entity;
 
 import com.evp.comm.server.dto.EvpsCenter;
+import com.evp.comm.server.dto.NetState;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -31,6 +32,7 @@ public class TbEvpsCenter implements Serializable {
                 .serviceBuffer(null)
                 .nodeBuffer(null)
                 .signalBuffer(null)
+                .netState(new NetState())
                 .build();
     }
 }

+ 5 - 4
src/main/java/com/evp/comm/server/entity/TbRegionCenterComm.java

@@ -14,9 +14,10 @@ import java.io.Serializable;
 public class TbRegionCenterComm implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    public static final String CENTER_COMM_START = "0";
-    public static final String CENTER_COMM_STOP = "1";
+    public static final int CENTER_COMM_START = 0;
+    public static final int CENTER_COMM_STOP = 1;
+    public static final int CENTER_COMM_LAST = 2;
 
-    private String regionCd;        /* 지역 센터 코드 */
-    private String commState;       /* 통신상태(0:정상, 1:종료, 2:오류발생) */
+    private String centerId;        /* 지역 센터 코드 */
+    private int commState;       /* 통신상태(0:정상, 1:종료, 2:오류발생) */
 }

+ 15 - 8
src/main/java/com/evp/comm/server/process/dbms/DbmsDataProcess.java

@@ -3,6 +3,7 @@ package com.evp.comm.server.process.dbms;
 import com.evp.app.common.utils.Elapsed;
 import com.evp.comm.server.common.SpringUtils;
 import com.evp.comm.server.config.ThreadPoolInitializer;
+import com.evp.comm.server.dao.mapper.EvpsCenterMapper;
 import com.evp.comm.server.dao.mapper.EvpsServiceMapper;
 import com.evp.comm.server.dao.mapper.ProcessMapper;
 import com.evp.comm.server.dao.mapper.batch.EvpCommServerDao;
@@ -33,6 +34,7 @@ public class DbmsDataProcess {
     private final ProcessMapper processMapper;
     private final EvpsServiceMapper serviceMapper;
     private final EvpCommServerDao evpCommServerDao;
+    private final EvpsCenterMapper evpsCenterMapper;
 
     private int maxCore = Runtime.getRuntime().availableProcessors();
 
@@ -123,19 +125,24 @@ public class DbmsDataProcess {
 
                 case DbmsData.DBMS_DATA_CENTER_STTS:
                     TbRegionCenterComm stts = (TbRegionCenterComm) data.getData();
-//                    if (TbRegionCenterComm.CENTER_COMM_START.equals(stts.getCommState())) {
-//                        result = this.centerMapper.updateCommStateConnect(stts);
-//                    }
-//                    else if (TbRegionCenterComm.CENTER_COMM_STOP.equals(stts.getCommState())) {
-//                        result = this.centerMapper.updateCommStateDisconnect(stts);
-//                    }
+                    switch(stts.getCommState()) {
+                        case TbRegionCenterComm.CENTER_COMM_START:
+                            result = this.evpsCenterMapper.updateCommStateConnect(stts.getCenterId());
+                            break;
+                        case TbRegionCenterComm.CENTER_COMM_STOP:
+                            result = this.evpsCenterMapper.updateCommStateDisconnect(stts.getCenterId());
+                            break;
+                        case TbRegionCenterComm.CENTER_COMM_LAST:
+                            result = this.evpsCenterMapper.updateCommLastComm(stts.getCenterId());
+                            break;
+                    }
                     break;
                 default:
                     log.error("DbmsJobProcess.process: Unknown Request {}.", type);
                     break;
             }
-//            log.info("DbmsDataProcess.run: [{}]. {}, {} EA. {}",
-//                    center.getLogKey(), type, result, Elapsed.elapsedTimeStr(elapsed1.nanoSeconds()));
+            log.info("DbmsDataProcess.run: [{}]. {}, {} EA. {}",
+                    center.getLogKey(), type, result, Elapsed.elapsedTimeStr(elapsed1.nanoSeconds()));
         }
         catch (Exception e) {
             log.error("DbmsJobProcess.process: [{}]. {}, Exception: {}", center.getLogKey(), type, e.toString());

+ 14 - 2
src/main/java/com/evp/comm/server/xnet/server/EvpCommServerInitializer.java

@@ -4,6 +4,9 @@ import com.evp.app.common.xnet.NettyUtils;
 import com.evp.comm.server.common.SpringUtils;
 import com.evp.comm.server.config.ApplicationConfig;
 import com.evp.comm.server.dto.EvpsCenter;
+import com.evp.comm.server.entity.TbRegionCenterComm;
+import com.evp.comm.server.process.dbms.DbmsData;
+import com.evp.comm.server.process.dbms.DbmsDataProcess;
 import com.evp.comm.server.repository.ApplicationRepository;
 import com.evp.comm.server.xnet.server.codec.EvpSendByteBufMessageEncoder;
 import com.evp.comm.server.xnet.server.handler.EvpCommServerInboundMessageHandler;
@@ -24,10 +27,12 @@ public class EvpCommServerInitializer extends ChannelInitializer<Channel> {
     private final EvpSendByteBufMessageEncoder evpSendByteBufMessageEncoder;
     private final ApplicationConfig config;
     private final ApplicationRepository appRepository;
+    private final DbmsDataProcess dbmsDataProcess;
 
-    public EvpCommServerInitializer(ApplicationConfig config, ApplicationRepository applicationRepository) {
+    public EvpCommServerInitializer(ApplicationConfig config, ApplicationRepository applicationRepository, DbmsDataProcess dbmsDataProcess) {
         this.config = config;
         this.appRepository = applicationRepository;
+        this.dbmsDataProcess = dbmsDataProcess;
         this.evpCommServerInboundMessageHandler = SpringUtils.getBean(EvpCommServerInboundMessageHandler.class);
         this.evpSendByteBufMessageEncoder = SpringUtils.getBean(EvpSendByteBufMessageEncoder.class);
     }
@@ -53,6 +58,12 @@ public class EvpCommServerInitializer extends ChannelInitializer<Channel> {
             channel.close();
         }
 
+        TbRegionCenterComm stts = TbRegionCenterComm.builder()
+                .centerId(center.getCenterId())
+                .commState(TbRegionCenterComm.CENTER_COMM_START)
+                .build();
+        this.dbmsDataProcess.add(new DbmsData(DbmsData.DBMS_DATA_CENTER_STTS, center, stts));
+
         center.getNetState().connect(channel);
         channel.attr(ApplicationRepository.SIG_REGION_ATTRIBUTE_KEY).set(center);
 
@@ -61,12 +72,13 @@ public class EvpCommServerInitializer extends ChannelInitializer<Channel> {
         pipeline.addLast(new LoggingHandler(LogLevel.INFO));
         pipeline.addLast("idleStateHandler", idleStateHandler);
         pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(
-                EvpsProtocolConst.EVPS_MAX_PACKET *2,
+                EvpsProtocolConst.EVPS_MAX_PACKET *4,
                 EvpsProtocolConst.EVPS_PACKET_LENGTH_FIELD_OFFSET,    /* 패킷 에서 길이 필드의 시작 위치 */
                 EvpsProtocolConst.EVPS_PACKET_LENGTH_FIELD_SIZE,      /* 길이 필드의 크기 */
                 EvpsProtocolConst.EVPS_PACKET_LENGTH_ADJUSTMENTS,     /* 길이 필드 값에 +-해서 길이 필드 이후의 전체 길이를 구한다 */
                 0));
         pipeline.addLast("packetInboundHandler", this.evpCommServerInboundMessageHandler);
         pipeline.addLast("frameEncoder", this.evpSendByteBufMessageEncoder);
+
     }
 }

+ 6 - 2
src/main/java/com/evp/comm/server/xnet/server/EvpCommServerService.java

@@ -4,6 +4,7 @@ import com.evp.app.common.utils.OS;
 import com.evp.app.common.xnet.NettyTcpServer;
 import com.evp.app.common.xnet.NettyUtils;
 import com.evp.comm.server.config.ApplicationConfig;
+import com.evp.comm.server.process.dbms.DbmsDataProcess;
 import com.evp.comm.server.repository.ApplicationRepository;
 import io.netty.channel.epoll.Epoll;
 import lombok.extern.slf4j.Slf4j;
@@ -17,16 +18,19 @@ public class EvpCommServerService extends NettyTcpServer {
 
     private final ApplicationConfig config;
     private final ApplicationRepository applicationRepository;
-    public EvpCommServerService(ApplicationConfig config, ApplicationRepository applicationRepository) {
+    private final DbmsDataProcess dbmsDataProcess;
+
+    public EvpCommServerService(ApplicationConfig config, ApplicationRepository applicationRepository, DbmsDataProcess dbmsDataProcess) {
         super(config);
 
         this.config = config;
         this.applicationRepository = applicationRepository;
+        this.dbmsDataProcess = dbmsDataProcess;
     }
 
     @PostConstruct
     public void initialize() {
-        super.setChannelInitializer(new EvpCommServerInitializer(this.config, this.applicationRepository));
+        super.setChannelInitializer(new EvpCommServerInitializer(this.config, this.applicationRepository, this.dbmsDataProcess));
         if (!OS.isWindows() && (!Epoll.isAvailable())) {
             log.warn("SigTcpCommServerService.initialize: {}", Epoll.unavailabilityCause().toString());
         }

+ 7 - 1
src/main/java/com/evp/comm/server/xnet/server/handler/EvpCommServerInboundMessageHandler.java

@@ -67,6 +67,12 @@ public class EvpCommServerInboundMessageHandler extends SimpleChannelInboundHand
 
                 center.getNetState().setLastRecvTime();
                 this.dataPacketProcess.add(packet);
+
+                TbRegionCenterComm stts = TbRegionCenterComm.builder()
+                        .centerId(center.getCenterId())
+                        .commState(TbRegionCenterComm.CENTER_COMM_LAST)
+                        .build();
+                this.dbmsDataProcess.add(new DbmsData(DbmsData.DBMS_DATA_CENTER_STTS, center, stts));
             }
         }
         catch (Exception e) {
@@ -97,7 +103,7 @@ public class EvpCommServerInboundMessageHandler extends SimpleChannelInboundHand
         ctx.fireChannelInactive();
 
         TbRegionCenterComm stts = TbRegionCenterComm.builder()
-                .regionCd(center.getCenterId())
+                .centerId(center.getCenterId())
                 .commState(TbRegionCenterComm.CENTER_COMM_STOP)
                 .build();
         this.dbmsDataProcess.add(new DbmsData(DbmsData.DBMS_DATA_CENTER_STTS, center, stts));

+ 1 - 1
src/main/java/com/evp/comm/server/xnet/server/process/protocol/EvpsCommPacket.java

@@ -117,7 +117,7 @@ public class EvpsCommPacket implements Serializable {
         this.hour       = (short)(this.headBuffer[idx++] & 0xFF);
         this.min        = (short)(this.headBuffer[idx++] & 0xFF);
         this.sec        = (short)(this.headBuffer[idx++] & 0xFF);
-        this.serviceIdArr = Arrays.copyOfRange(this.headBuffer, idx, EvpsProtocolConst.EVPS_SERVICE_ID_SIZE);
+        this.serviceIdArr = Arrays.copyOfRange(this.headBuffer, idx, idx+EvpsProtocolConst.EVPS_SERVICE_ID_SIZE);
         idx += EvpsProtocolConst.EVPS_SERVICE_ID_SIZE;
         this.dataLength = ((this.headBuffer[idx++] & 0xFF) << 8) | (this.headBuffer[idx] & 0xFF);
 //        this.dataLength = ((this.headBuffer[idx++] & 0xFF) << 24) | ((this.headBuffer[idx++] & 0xFF) << 16) | ((this.headBuffer[idx++] & 0xFF) << 8) | (this.headBuffer[idx++] & 0xFF);

+ 1 - 1
src/main/java/com/evp/comm/server/xnet/server/process/protocol/EvpsProtocolConst.java

@@ -25,7 +25,7 @@ public class EvpsProtocolConst {
 
     public static final int EVPS_MAX_PACKET = 8192;                 /* 한번에 전송하는 최대 패킷 크기, 8192 */
     public static final int EVPS_HEAD_SIZE = 37;                    /* 프로토콜 헤더 크기 37 byte */
-    public static final int EVPS_PACKET_LENGTH_FIELD_OFFSET = 36;   /* Netty Fixed Packet Length position */
+    public static final int EVPS_PACKET_LENGTH_FIELD_OFFSET = 35;   /* Netty Fixed Packet Length position */
     public static final int EVPS_PACKET_LENGTH_FIELD_SIZE = 2;      /* Netty Fixed Packet Length field size */
     public static final int EVPS_PACKET_LENGTH_ADJUSTMENTS = 0;     /* Length Field 이후의 데이터 나머지 크기 */
 

+ 3 - 0
src/main/java/com/evp/comm/server/xnet/server/process/response/EvpsEvent.java

@@ -84,6 +84,9 @@ public class EvpsEvent implements EvpsCommResponse {
         }
 
         KafkaEvpsEventDto data = getData(packet.getPacket().getServiceId(), buffer, 0);
+
+        log.info("[{}], EvpsEvent.response: Service Id: {}, {}", center.getLogKey(), packet.getPacket().getServiceId(), data);
+
         // kafka 전송
         this.kafkaProducerService.sendEvpsEventTopic(data);
 

+ 3 - 4
src/main/java/com/evp/comm/server/xnet/server/process/response/EvpsNode.java

@@ -88,8 +88,8 @@ public class EvpsNode implements EvpsCommResponse {
         int nodeCount = ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
         int reqDataSize = EvpsProtocolConst.MIN_NODE_DATA_NODE_SIZE * nodeCount;
         if ((buffer.length - idx) < reqDataSize) {
-            log.error("[{}], EvpsNode.response: Data Length Error: Required data length({}), Cur({}). will be closed.",
-                    center.getLogKey(), reqDataSize, (buffer.length-idx));
+            log.error("[{}], EvpsNode.response: Data Length Error: nodeCount({}), Required data length({}), Cur({}). will be closed.",
+                    center.getLogKey(), nodeCount, reqDataSize, (buffer.length-idx));
             return false;
         }
 
@@ -164,13 +164,12 @@ public class EvpsNode implements EvpsCommResponse {
             }
         }
         log.info("[{}], EvpsNode.response: Service Node List {} EA.", center.getLogKey(), lists.size());
+        log.info("[{}], EvpsNode.response: Service Node: {}.", center.getLogKey(), lists);
 
         KafkaEvpsServiceDto service = ApplicationRepository.serviceMap.get(data.getServiceId());
         if (service == null) {
             log.error("[{}], EvpsNode.response: Not Found Service Information. Service Id: {}", center.getLogKey(), data.getServiceId());
         }
-        else {
-        }
 
         if (!lists.isEmpty()) {
             // kafka 전송

+ 6 - 3
src/main/java/com/evp/comm/server/xnet/server/process/response/EvpsService.java

@@ -119,13 +119,13 @@ public class EvpsService implements EvpsCommResponse {
         // 예상도착시각
         int arrivalTime = ((buffer[idx++] & 0xFF) << 24) | ((buffer[idx++] & 0xFF) << 16) | ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
         // 거리
-        int distance = ((buffer[idx++] & 0xFF) << 24) | ((buffer[idx++] & 0xFF) << 16) | ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
+        int distance    = ((buffer[idx++] & 0xFF) << 24) | ((buffer[idx++] & 0xFF) << 16) | ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
 
         int routeCount = ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
         int reqDataSize = EvpsProtocolConst.SERVICE_DATA_ROUTE_SIZE * routeCount;
         if ((buffer.length - idx) != reqDataSize) {
-            log.error("[{}], EvpsService.response: Data Length Error: Required data length({}), Cur({}). will be closed.",
-                    center.getLogKey(), reqDataSize, (buffer.length-idx));
+            log.error("[{}], EvpsService.response: Data Length Error: routeCount({}), Required data length({}), Cur({}). will be closed.",
+                    center.getLogKey(), routeCount, reqDataSize, (buffer.length-idx));
             return false;
         }
 
@@ -149,6 +149,8 @@ public class EvpsService implements EvpsCommResponse {
                 .routeList(new ArrayList<>())
                 .build();
 
+        log.info("[{}], EvpsService.response: Service Id: {}, {}", center.getLogKey(), packet.getPacket().getServiceId(), service);
+
         List<HashMap<String, Object>> lists = new ArrayList<>();
         for (int ii = 0; ii < routeCount; ii++) {
             int routeLat = ((buffer[idx++] & 0xFF) << 24) | ((buffer[idx++] & 0xFF) << 16) | ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
@@ -169,6 +171,7 @@ public class EvpsService implements EvpsCommResponse {
             lists.add(param);
         }
         log.info("[{}], EvpsService.response: Service Route List {} EA.", center.getLogKey(), lists.size());
+        log.info("[{}], EvpsService.response: Service Route: {}.", center.getLogKey(), lists);
 
         ApplicationRepository.serviceMap.put(service.getServiceId(), service);
 

+ 2 - 0
src/main/java/com/evp/comm/server/xnet/server/process/response/EvpsServiceEnd.java

@@ -77,6 +77,7 @@ public class EvpsServiceEnd implements EvpsCommResponse {
         }
 
         KafkaEvpsServiceEndDto data = getData(packet.getPacket().getServiceId(), buffer, 0);
+        log.info("[{}], EvpsServiceEnd.response: Service Id: {}, {}", center.getLogKey(), data.getServiceId(), data);
 
         // 이벤트 정보 입력(서비스 종료)
         KafkaEvpsEventDto event = KafkaEvpsEventDto.builder()
@@ -95,6 +96,7 @@ public class EvpsServiceEnd implements EvpsCommResponse {
             service.setCurLat(0.);
             service.setCurLng(0.);
             service.setCurSpd(0);
+            service.setServiceDist(0);
         }
         service.setStatusCd(data.getReason());
 

+ 3 - 4
src/main/java/com/evp/comm/server/xnet/server/process/response/EvpsSignal.java

@@ -91,8 +91,8 @@ public class EvpsSignal implements EvpsCommResponse {
         int nodeCount = ((buffer[idx++] & 0xFF) << 8) | (buffer[idx++] & 0xFF);
         int reqDataSize = EvpsProtocolConst.SIGNAL_DATA_SIGNAL_SIZE * nodeCount;
         if ((buffer.length - idx) < reqDataSize) {
-            log.error("[{}], EvpsSignal.response: Data Length Error: Required data length({}), Cur({}). will be closed.",
-                    center.getLogKey(), reqDataSize, (buffer.length-idx));
+            log.error("[{}], EvpsSignal.response: Data Length Error: nodeCount({}), Required data length({}), Cur({}). will be closed.",
+                    center.getLogKey(), nodeCount, reqDataSize, (buffer.length-idx));
             return false;
         }
 
@@ -128,13 +128,12 @@ public class EvpsSignal implements EvpsCommResponse {
             lists.add(param);
         }
         log.info("[{}], EvpsSignal.response: Service Signal List {} EA.", center.getLogKey(), lists.size());
+        log.info("[{}], EvpsSignal.response: Service Signal: {}.", center.getLogKey(), lists);
 
         KafkaEvpsServiceDto service = ApplicationRepository.serviceMap.get(data.getServiceId());
         if (service == null) {
             log.error("[{}], EvpsSignal.response: Not Found Service Information. Service Id: {}", center.getLogKey(), data.getServiceId());
         }
-        else {
-        }
 
         if (!lists.isEmpty()) {
             // kafka 전송

+ 0 - 2
src/main/resources/mybatis/mapper/EvpsServiceMapper.xml

@@ -21,7 +21,6 @@
                                     status_cd)
                           VALUES ( #{obj.serviceId},
                                    current_timestamp(),
---                                    #{obj.clctDt},
                                    #{obj.evNo},
                                    #{obj.curLat},
                                    #{obj.curLng},
@@ -56,7 +55,6 @@
                                   cur_spd,
                                   rem_dist)
         VALUES ( current_timestamp(),
---                  #{obj.clctDt},
                  #{obj.serviceId},
                  #{obj.eventCd},
                  #{obj.curLat},