Search in sources :

Example 1 with DeviceSessionsCacheEntry

use of org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry in project thingsboard by thingsboard.

the class DeviceActorMessageProcessor method restoreSessions.

void restoreSessions() {
    if (systemContext.isLocalCacheType()) {
        return;
    }
    log.debug("[{}] Restoring sessions from cache", deviceId);
    DeviceSessionsCacheEntry sessionsDump = null;
    try {
        sessionsDump = DeviceSessionsCacheEntry.parseFrom(systemContext.getDeviceSessionCacheService().get(deviceId));
    } catch (InvalidProtocolBufferException e) {
        log.warn("[{}] Failed to decode device sessions from cache", deviceId);
        return;
    }
    if (sessionsDump.getSessionsCount() == 0) {
        log.debug("[{}] No session information found", deviceId);
        return;
    }
    // TODO: Take latest max allowed sessions size from cache
    for (SessionSubscriptionInfoProto sessionSubscriptionInfoProto : sessionsDump.getSessionsList()) {
        SessionInfoProto sessionInfoProto = sessionSubscriptionInfoProto.getSessionInfo();
        UUID sessionId = getSessionId(sessionInfoProto);
        SessionInfo sessionInfo = new SessionInfo(SessionType.ASYNC, sessionInfoProto.getNodeId());
        SubscriptionInfoProto subInfo = sessionSubscriptionInfoProto.getSubscriptionInfo();
        SessionInfoMetaData sessionMD = new SessionInfoMetaData(sessionInfo, subInfo.getLastActivityTime());
        sessions.put(sessionId, sessionMD);
        if (subInfo.getAttributeSubscription()) {
            attributeSubscriptions.put(sessionId, sessionInfo);
            sessionMD.setSubscribedToAttributes(true);
        }
        if (subInfo.getRpcSubscription()) {
            rpcSubscriptions.put(sessionId, sessionInfo);
            sessionMD.setSubscribedToRPC(true);
        }
        log.debug("[{}] Restored session: {}", deviceId, sessionMD);
    }
    log.debug("[{}] Restored sessions: {}, rpc subscriptions: {}, attribute subscriptions: {}", deviceId, sessions.size(), rpcSubscriptions.size(), attributeSubscriptions.size());
}
Also used : SessionSubscriptionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionSubscriptionInfoProto) SessionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto) SessionSubscriptionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionSubscriptionInfoProto) SubscriptionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DeviceSessionsCacheEntry(org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry) UUID(java.util.UUID)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 UUID (java.util.UUID)1 DeviceSessionsCacheEntry (org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry)1 SessionInfoProto (org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto)1 SessionSubscriptionInfoProto (org.thingsboard.server.gen.transport.TransportProtos.SessionSubscriptionInfoProto)1 SubscriptionInfoProto (org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto)1