diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java index bfc2281..0641d16 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/BlueAlertListener.java @@ -56,7 +56,7 @@ public class BlueAlertListener implements AlertSourceEventListener onTick() { - Builder builder = NccAlertInfoMessage.newBuilder(); - NccAlertInfo alertInfo; + List list = Lists.newArrayListWithCapacity(10); for (int i = 0; i < 10; i++) { //加循环次数主要是为了防止while死循环 + Builder builder = NccAlertInfoMessage.newBuilder(); + NccAlertInfo alertInfo; if ((alertInfo = pendingMsgQueue.poll()) != null) { Message message = convertToMessage(alertInfo); builder.addMessages(message); + byte[] bytes = builder.build().toByteArray(); + if (bytes != null && bytes.length != 0) { + list.add(new TopicMessage(getDestinationPattern(), bytes)); + } } else { break; } } - byte[] bytes = builder.build().toByteArray(); - if (bytes != null && bytes.length != 0) { - return List.of(new TopicMessage(getDestinationPattern(), bytes)); - } - return new ArrayList<>(); + + return list; } private NccAlertMessageServer(String id) {