Skip to content

Commit 58e91a5

Browse files
committed
refactor(基础模块): 优化设备会话持久化逻辑
1 parent deff207 commit 58e91a5

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

jetlinks-components/configure-component/src/main/java/org/jetlinks/community/configure/device/PersistenceDeviceSessionManager.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
import org.jetlinks.core.device.session.DeviceSessionEvent;
3232
import org.jetlinks.core.message.codec.DefaultTransport;
3333
import org.jetlinks.core.rpc.RpcManager;
34-
import org.jetlinks.core.server.session.DeviceSession;
35-
import org.jetlinks.core.server.session.DeviceSessionProvider;
36-
import org.jetlinks.core.server.session.LostDeviceSession;
37-
import org.jetlinks.core.server.session.PersistentSession;
34+
import org.jetlinks.core.server.session.*;
3835
import org.jetlinks.core.utils.Reactors;
3936
import org.jetlinks.core.utils.RecyclerUtils;
4037
import org.jetlinks.community.codec.Serializers;
@@ -202,19 +199,19 @@ public void init() {
202199
if (ctx.hasKey(PersistenceDeviceSessionManager.class)) {
203200
return Mono.empty();
204201
}
205-
//持久化
206-
if (event.getSession().isWrapFrom(PersistentSession.class)) {
207-
if (event.getType() == DeviceSessionEvent.Type.unregister) {
208-
return removePersistentSession(event.getSession().unwrap(PersistentSession.class));
209-
}
210-
} else if (recordHistory) {
202+
boolean isPersistent
203+
= !(event.getSession() instanceof ChildrenDeviceSession)
204+
&& event.getSession().isWrapFrom(PersistentSession.class);
205+
206+
if (recordHistory && !isPersistent) {
211207
//记录历史设备
212208
if (event.getType() == DeviceSessionEvent.Type.register) {
213209
return this
214210
.operateInStore(
215211
() -> history,
216-
history -> history.put(event.getSession().getDeviceId(),
217-
event.getSession().connectTime())
212+
history -> history
213+
.put(event.getSession().getDeviceId(),
214+
event.getSession().connectTime())
218215
)
219216
.then();
220217
}
@@ -227,6 +224,10 @@ public void init() {
227224
.then();
228225
}
229226
}
227+
if (event.getType() == DeviceSessionEvent.Type.unregister && isPersistent && !isShutdown()) {
228+
return removePersistentSession(event.getSession().unwrap(PersistentSession.class));
229+
}
230+
230231
return Mono.empty();
231232
}))
232233
);

0 commit comments

Comments
 (0)