diff --git a/src/main/java/club/joylink/xiannccda/ats/message/FrameSchemaParse.java b/src/main/java/club/joylink/xiannccda/ats/message/FrameSchemaParse.java index 2c7c0bc..193bba4 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/FrameSchemaParse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/FrameSchemaParse.java @@ -60,7 +60,9 @@ public class FrameSchemaParse { private static void messageDecode(ByteBuf buf, List messages) throws Exception { int len = buf.getUnsignedShort(0); byte[] msgData = new byte[len + 2]; +// ByteBuf msgBuf = buf.readBytes(msgData); + ByteBuf msgBuf = Unpooled.wrappedBuffer(msgData); int msgId = msgBuf.getUnsignedShort(8); @@ -86,7 +88,7 @@ public class FrameSchemaParse { inByteBuf.markReaderIndex(); int totalReadables = inByteBuf.readableBytes(); if (totalReadables < 4) { -// inByteBuf.resetReaderIndex(); + inByteBuf.resetReaderIndex(); log.error("数据不全,当前可读[{}]", totalReadables); return false; } @@ -100,9 +102,10 @@ public class FrameSchemaParse { log.error("可读内容不足 sysId[{}] totalLen[{}] flag[{}] contentLen[{}] readableBytes[{}]", sysId, totalLength, flag, contentLen, readables); return false; } -// byte[] bb = new byte[contentLen]; -// inByteBuf.readBytes(bb); - packageData.writeBytes(inByteBuf, contentLen); + byte[] bb = new byte[contentLen]; + inByteBuf.readBytes(bb); + packageData.writeBytes(inByteBuf); +// packageData.writeBytes(inByteBuf, contentLen); return flag != Flag_Multi; } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java b/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java index b0b6ef4..1047d94 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java @@ -74,8 +74,10 @@ public abstract class MessageData { this.version = buf.readUnsignedShort(); this.msgId = MessageId.of(buf.readShort()); this.decode2(buf); +// buf.clear(); buf.release(); } else { +// buf.clear(); buf.release(); throw new Exception( String.format("OCC消息可读字节数小于%s:readableBytes=%s", headerBytes, readableBytes)); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java index 8555a49..71b25dd 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageHandler.java @@ -36,7 +36,6 @@ public class OccMessageHandler extends SimpleChannelInboundHandler clientConnections = new LinkedList<>(); - private final SystemInfo systemInfo; - private boolean monitorHandwareChange; - - private long[] ticks; +// private long[] ticks; public void shutdown() { Executor.shutdownNow(); } public ConnectionTimeOutHandler() { - this.systemInfo = new SystemInfo(); +// this.systemInfo = new SystemInfo(); if (Executor.isShutdown()) { Executor = Executors.newSingleThreadScheduledExecutor(); } @@ -147,47 +137,15 @@ public class XianOccMessagingClient { this.clientConnections.add(conn); } - private String hardWareUserInfo() { - CentralProcessor cpu = systemInfo.getHardware().getProcessor(); - GlobalMemory memory = systemInfo.getHardware().getMemory(); - if (Objects.isNull(ticks)) { - ticks = cpu.getSystemCpuLoadTicks(); - } else { - double d2 = cpu.getSystemCpuLoadBetweenTicks(ticks); - ticks = cpu.getSystemCpuLoadTicks(); - long totalMemory = memory.getTotal(); - long availableMemory = memory.getAvailable(); - long usedMemory = totalMemory - availableMemory; - return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024), - (availableMemory / 1024 / 1024)); - } - return null; - -/* GlobalMemory memory = systemInfo.getHardware().getMemory(); - long totalMemory = memory.getTotal(); - long availableMemory = memory.getAvailable(); - long usedMemory = totalMemory - availableMemory; - if (Objects.isNull(this.osProcess)) { - return String.format("内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024), - (availableMemory / 1024 / 1024)); - } else { - OSProcess osp = this.systemInfo.getOperatingSystem().getProcess(this.processId); - - double d2 = this.osProcess.getProcessCpuLoadBetweenTicks(osp); - return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024), - (availableMemory / 1024 / 1024)); - }*/ - } public void start() { Executor.scheduleWithFixedDelay(() -> { - if (this.monitorHandwareChange) { + /* if (this.monitorHandwareChange) { String moitorContent = this.hardWareUserInfo(); if (StringUtils.isNotEmpty(moitorContent)) { log.info(moitorContent); } - } - + }*/ for (OccTcpClientConnection cc : this.clientConnections) { if (cc.connected) { long ctm = System.currentTimeMillis(); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java index 668ab3a..cb18fcd 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/collect/DeviceStatusDataOperate.java @@ -78,7 +78,7 @@ public abstract class DeviceStatusDataOperate { })); // 对比结果 Map compareMap = compare(deviceStatusMap, newDeviceMap); - if (!CollectionUtils.isEmpty(compareMap)) { + if (!CollectionUtils.isEmpty(compareMap) && (!(data instanceof DeviceStatusData))) { statusVOMap.put(k, compareMap); } }); diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java index 40974fc..5117bcb 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java @@ -65,7 +65,8 @@ public class DateTimeUtil { public static LocalDateTime convert(ByteBuf buf) { byte[] data = new byte[7]; - buf.readBytes(data); + ByteBuf bb = buf.readBytes(data); +// bb.clear(); return convert(data); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/EntityParseUtil.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/EntityParseUtil.java index b455d2e..550af8a 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/EntityParseUtil.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/EntityParseUtil.java @@ -28,9 +28,11 @@ public class EntityParseUtil { public static String convertStr(ByteBuf buf, int len) { - byte[] data = new byte[len]; - buf.readBytes(data); - return new String(data, MessageCons.STRING_CHARSET).trim(); + ByteBuf bb = buf.readBytes(len); + String str = new String(bb.array(), MessageCons.STRING_CHARSET).trim(); + bb.clear(); + bb.release(); + return str; } public interface ReadData { diff --git a/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java b/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java index 20aae0b..8f1bccd 100644 --- a/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java +++ b/src/main/java/club/joylink/xiannccda/mock/message/MockLoadData.java @@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -27,6 +28,7 @@ import org.springframework.stereotype.Component; @Component @Order(1) @RequiredArgsConstructor +@Slf4j public class MockLoadData implements ApplicationRunner { static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor(); @@ -40,13 +42,13 @@ public class MockLoadData implements ApplicationRunner { public void run(ApplicationArguments args) throws Exception { this.nccMockDataService.reset(10); AtomicInteger ai = new AtomicInteger(0); - CIRCLE_QUERY_THREAD.scheduleAtFixedRate(() -> { + CIRCLE_QUERY_THREAD.scheduleWithFixedDelay(() -> { // this.nccMockDataService.skip(170L, 1100L, 1180L); // if (ai.incrementAndGet() > 1) { // return; // } loadData(); - }, 1500, 1500, TimeUnit.MILLISECONDS); + }, 500, 500, TimeUnit.MILLISECONDS); } private void loadData() { @@ -65,7 +67,7 @@ public class MockLoadData implements ApplicationRunner { DeviceStatusConvertorManager.doConvertor(dataList.stream().map(d -> (MessageData) d).collect(Collectors.toList())); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } }