调整
This commit is contained in:
parent
c561e51a17
commit
3cfde83eef
@ -60,7 +60,9 @@ public class FrameSchemaParse {
|
||||
private static void messageDecode(ByteBuf buf, List<MessageData> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -36,7 +36,6 @@ public class OccMessageHandler extends SimpleChannelInboundHandler<List<MessageD
|
||||
|
||||
static {
|
||||
DeviceStatusConvertorManager.addStatusConvertor(new DeviceInitConvertor());
|
||||
// DeviceStatusConvertorManager.addStatusConvertor(new AlterBlueDisplayConvertor());
|
||||
DeviceStatusConvertorManager.addStatusConvertor(new DeviceChangeStatusConvertor());
|
||||
DeviceStatusConvertorManager.addStatusConvertor(new TrainInitConvertor());
|
||||
DeviceStatusConvertorManager.addStatusConvertor(new TrainRecordConvertor());
|
||||
|
@ -4,19 +4,13 @@ import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
|
||||
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
|
||||
@Slf4j
|
||||
public class XianOccMessagingClient {
|
||||
@ -98,7 +92,6 @@ public class XianOccMessagingClient {
|
||||
* 连接OCC服务
|
||||
*/
|
||||
public void connect(boolean monitorHandwareChange) {
|
||||
this.timeOutHandler.monitorHandwareChange = monitorHandwareChange;
|
||||
this.timeOutHandler.start();
|
||||
|
||||
}
|
||||
@ -126,18 +119,15 @@ public class XianOccMessagingClient {
|
||||
|
||||
static ScheduledExecutorService Executor = Executors.newSingleThreadScheduledExecutor();
|
||||
private final LinkedList<OccTcpClientConnection> 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();
|
||||
|
@ -78,7 +78,7 @@ public abstract class DeviceStatusDataOperate {
|
||||
}));
|
||||
// 对比结果
|
||||
Map<String, Message> compareMap = compare(deviceStatusMap, newDeviceMap);
|
||||
if (!CollectionUtils.isEmpty(compareMap)) {
|
||||
if (!CollectionUtils.isEmpty(compareMap) && (!(data instanceof DeviceStatusData))) {
|
||||
statusVOMap.put(k, compareMap);
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<T> {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user