1078-查询终端属性完成

This commit is contained in:
648540858
2024-04-30 00:42:22 +08:00
parent 76580d8fdc
commit 5be7c7636e
2 changed files with 28 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@@ -89,7 +90,14 @@ public class J0107 extends Re {
deviceAttribute.setGnssAttribute(JGnssAttribute.getInstance(buf.getUnsignedByte(79 + n + m))); deviceAttribute.setGnssAttribute(JGnssAttribute.getInstance(buf.getUnsignedByte(79 + n + m)));
deviceAttribute.setCommunicationModuleAttribute(JCommunicationModuleAttribute.getInstance(buf.getUnsignedByte(80 + n + m))); deviceAttribute.setCommunicationModuleAttribute(JCommunicationModuleAttribute.getInstance(buf.getUnsignedByte(80 + n + m)));
System.out.println(deviceAttribute); System.out.println(deviceAttribute);
SessionManager.INSTANCE.response(header.getTerminalId(), "0107", (long) respNo, deviceAttribute); List<String> allRequestKey = SessionManager.INSTANCE.getAllRequestKey();
String prefix = String.join("_", header.getTerminalId().replaceFirst("^0*", ""), "0107");
for (String key : allRequestKey) {
if (key.startsWith(prefix)) {
SessionManager.INSTANCE.response(key, deviceAttribute);
}
}
return null; return null;
} }

View File

@@ -5,6 +5,8 @@ import io.netty.channel.Channel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
@@ -109,6 +111,23 @@ public enum SessionManager {
return false; return false;
} }
public Boolean response(String key, Object data) {
SynchronousQueue<Object> queue = topicSubscribers.get(key);
if (queue != null) {
try {
return queue.offer(data, 2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
}
}
log.warn("Not find response,key:{} data:{} ", key, data);
return false;
}
public List<String> getAllRequestKey() {
return new ArrayList<>(topicSubscribers.keySet());
}
private void unsubscribe(String key) { private void unsubscribe(String key) {
topicSubscribers.remove(key); topicSubscribers.remove(key);
} }