优化tcp keepalive

This commit is contained in:
zhou-hao 2020-03-23 14:33:30 +08:00
parent 547ba4c6d9
commit dbea53aa75
1 changed files with 8 additions and 4 deletions

View File

@ -177,12 +177,12 @@ class TcpServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGatew
);
}))
.flatMap(device -> {
DeviceSession fSession = sessionRef.get() == null ?
sessionManager.getSession(device.getDeviceId()) :
sessionRef.get();
//处理设备上线消息
if (message instanceof DeviceOnlineMessage) {
DeviceSession fSession = sessionRef.get() == null ?
sessionManager.getSession(device.getDeviceId()) :
sessionRef.get();
if (fSession == null) {
fSession = new TcpDeviceSession(client.getId(), device, client, getTransport()) {
@Override
@ -199,11 +199,15 @@ class TcpServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGatew
sessionRef.set(fSession);
sessionManager.register(fSession);
}
fSession.keepAlive();
if (keepaliveTimeout.get() != null) {
fSession.setKeepAliveTimeout(keepaliveTimeout.get());
}
return Mono.empty();
}
if (fSession != null) {
fSession.keepAlive();
}
//设备下线
if (message instanceof DeviceOfflineMessage) {
sessionManager.unregister(device.getDeviceId());