docs: add detailed 32960 pipeline comments
This commit is contained in:
@@ -35,6 +35,7 @@ public final class InMemorySessionStore implements SessionStore {
|
||||
@Override
|
||||
public void put(DeviceSession session) {
|
||||
byId.put(session.sessionId(), session);
|
||||
// 三索引用同一个 sessionId 汇聚;HTTP 下行可以拿 sessionId/VIN/phone 任意一种查在线连接。
|
||||
if (session.vin() != null) vinToId.put(session.vin(), session.sessionId());
|
||||
if (session.phone() != null) phoneToId.put(session.phone(), session.sessionId());
|
||||
}
|
||||
@@ -61,6 +62,7 @@ public final class InMemorySessionStore implements SessionStore {
|
||||
DeviceSession old = byId.getIfPresent(sessionId);
|
||||
if (old == null) return Optional.empty();
|
||||
DeviceSession next = updater.apply(old);
|
||||
// update 复用 put,保证 VIN/phone 二级索引和主会话对象一起刷新。
|
||||
put(next);
|
||||
return Optional.of(next);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public final class RedisSessionStore implements SessionStore {
|
||||
|
||||
@Override
|
||||
public void put(DeviceSession session) {
|
||||
// 同一个 sessionId 重新写入时先清理旧 VIN/phone 索引,避免旧外部号继续指向新会话。
|
||||
findBySessionId(session.sessionId()).ifPresent(old -> deleteIndexes(old));
|
||||
redis.opsForHash().putAll(sessionKey(session.sessionId()), toHash(session));
|
||||
redis.expire(sessionKey(session.sessionId()), ttl);
|
||||
@@ -67,6 +68,7 @@ public final class RedisSessionStore implements SessionStore {
|
||||
String sessionId = redis.opsForValue().get(vinIndexKey(vin));
|
||||
Optional<DeviceSession> session = findBySessionId(sessionId);
|
||||
if (session.isEmpty() && hasText(sessionId)) {
|
||||
// 二级索引可能比主 hash 晚过期;发现悬挂索引时立即清理。
|
||||
redis.delete(vinIndexKey(vin));
|
||||
}
|
||||
return session;
|
||||
@@ -80,6 +82,7 @@ public final class RedisSessionStore implements SessionStore {
|
||||
String sessionId = redis.opsForValue().get(phoneIndexKey(phone));
|
||||
Optional<DeviceSession> session = findBySessionId(sessionId);
|
||||
if (session.isEmpty() && hasText(sessionId)) {
|
||||
// 二级索引可能比主 hash 晚过期;发现悬挂索引时立即清理。
|
||||
redis.delete(phoneIndexKey(phone));
|
||||
}
|
||||
return session;
|
||||
@@ -124,6 +127,7 @@ public final class RedisSessionStore implements SessionStore {
|
||||
|
||||
private static Map<String, String> toHash(DeviceSession session) {
|
||||
Map<String, String> values = new LinkedHashMap<>();
|
||||
// attr.* 保留协议侧附加字段,后续扩展不需要改 Redis schema。
|
||||
put(values, "sessionId", session.sessionId());
|
||||
put(values, "protocol", session.protocol() == null ? null : session.protocol().name());
|
||||
put(values, "vin", session.vin());
|
||||
|
||||
@@ -23,6 +23,7 @@ public class SessionCoreAutoConfiguration {
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "redis")
|
||||
@ConditionalOnMissingBean
|
||||
public SessionStore redisSessionStore(StringRedisTemplate redis, SessionProperties properties) {
|
||||
// Redis 只保存会话元数据索引;真实 Netty Channel 仍在各协议进程本地内存中。
|
||||
return new RedisSessionStore(redis, properties.getTtl());
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ public class SessionCoreAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public CommandDispatcher commandDispatcher() {
|
||||
// 没有协议模块提供真实下行实现时使用 Noop,避免仅接收/查询部署因为缺 Bean 启动失败。
|
||||
return new NoopCommandDispatcher();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user