|
|
@@ -16,6 +16,9 @@ import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ * @author Administrator
|
|
|
+ */
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DeJuRFIDListenerService implements IService {
|
|
|
@@ -30,16 +33,20 @@ public class DeJuRFIDListenerService implements IService {
|
|
|
GServer server;
|
|
|
if (serverMap.containsKey(ipAddress)) {
|
|
|
server = serverMap.get(ipAddress);
|
|
|
+ boolean listen = server.isListend();
|
|
|
+ if (listen){
|
|
|
+ server.close();
|
|
|
+ }
|
|
|
} else {
|
|
|
server = new GServer();
|
|
|
+ serverMap.put(ipAddress,server);
|
|
|
}
|
|
|
if (server.open(DeJuRFIDService.PORT)) {
|
|
|
subscribeServerHandler(server, hardware);
|
|
|
log.info("开始监听");
|
|
|
} else {
|
|
|
log.info("监听失败");
|
|
|
- start(hardware);
|
|
|
- throw new ServiceException("监听失败,请等待设备重连。。。");
|
|
|
+ throw new ServiceException("监听失败,请稍后进行设备重连。。。");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -54,7 +61,11 @@ public class DeJuRFIDListenerService implements IService {
|
|
|
serverMap.remove(ipAddress);
|
|
|
}
|
|
|
|
|
|
- //订阅监听上报
|
|
|
+ /**
|
|
|
+ * 订阅监听上报
|
|
|
+ * @param server 服务对象
|
|
|
+ * @param hardware 设备对象
|
|
|
+ */
|
|
|
private void subscribeServerHandler(GServer server, RemoteLabHardware hardware) {
|
|
|
server.onGClientConnected = (client, serialNumber) -> {
|
|
|
log.info(client.getName() + "---监听成功");
|
|
|
@@ -68,24 +79,18 @@ public class DeJuRFIDListenerService implements IService {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- //订阅TCP断开连接上报
|
|
|
+ /**
|
|
|
+ * 订阅TCP断开连接上报
|
|
|
+ * @param client 客户端对象
|
|
|
+ * @param hardware 设备对象
|
|
|
+ */
|
|
|
private void subscribeTcpHandler(GClient client, RemoteLabHardware hardware) {
|
|
|
client.onDisconnected = s -> {
|
|
|
log.info("连接" + s + "已断开");
|
|
|
client.close();//释放当前连接资源
|
|
|
remoteLaboratoryService.update(HardwareOperate.CLOSE,hardware.getIpAddress());
|
|
|
- start(hardware);
|
|
|
log.info("连接" + s + "重连中。。。");
|
|
|
+ start(hardware);
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
- private void stop(GClient client) {
|
|
|
- MsgBaseStop msg = new MsgBaseStop();
|
|
|
- client.sendSynMsg(msg);
|
|
|
- if (0x00 == msg.getRtCode()) {
|
|
|
- log.info("Stop success");
|
|
|
- } else {
|
|
|
- log.info(msg.getRtMsg());
|
|
|
- }
|
|
|
- }
|
|
|
}
|