Search in sources :

Example 1 with SubscriptionInfoProto

use of org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto 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)

Example 2 with SubscriptionInfoProto

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

the class DeviceActorMessageProcessor method dumpSessions.

private void dumpSessions() {
    if (systemContext.isLocalCacheType()) {
        return;
    }
    log.debug("[{}] Dumping sessions: {}, rpc subscriptions: {}, attribute subscriptions: {} to cache", deviceId, sessions.size(), rpcSubscriptions.size(), attributeSubscriptions.size());
    List<SessionSubscriptionInfoProto> sessionsList = new ArrayList<>(sessions.size());
    sessions.forEach((uuid, sessionMD) -> {
        if (sessionMD.getSessionInfo().getType() == SessionType.SYNC) {
            return;
        }
        SessionInfo sessionInfo = sessionMD.getSessionInfo();
        SubscriptionInfoProto subscriptionInfoProto = SubscriptionInfoProto.newBuilder().setLastActivityTime(sessionMD.getLastActivityTime()).setAttributeSubscription(sessionMD.isSubscribedToAttributes()).setRpcSubscription(sessionMD.isSubscribedToRPC()).build();
        SessionInfoProto sessionInfoProto = SessionInfoProto.newBuilder().setSessionIdMSB(uuid.getMostSignificantBits()).setSessionIdLSB(uuid.getLeastSignificantBits()).setNodeId(sessionInfo.getNodeId()).build();
        sessionsList.add(SessionSubscriptionInfoProto.newBuilder().setSessionInfo(sessionInfoProto).setSubscriptionInfo(subscriptionInfoProto).build());
        log.debug("[{}] Dumping session: {}", deviceId, sessionMD);
    });
    systemContext.getDeviceSessionCacheService().put(deviceId, DeviceSessionsCacheEntry.newBuilder().addAllSessions(sessionsList).build().toByteArray());
}
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) ArrayList(java.util.ArrayList)

Aggregations

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