Search in sources :

Example 1 with AttributeKey

use of org.thingsboard.server.common.data.kv.AttributeKey in project thingsboard by thingsboard.

the class DeviceActorMessageProcessor method processAttributesUpdate.

void processAttributesUpdate(ActorContext context, DeviceAttributesEventNotificationMsg msg) {
    refreshAttributes(msg);
    if (attributeSubscriptions.size() > 0) {
        ToDeviceMsg notification = null;
        if (msg.isDeleted()) {
            List<AttributeKey> sharedKeys = msg.getDeletedKeys().stream().filter(key -> DataConstants.SHARED_SCOPE.equals(key.getScope())).collect(Collectors.toList());
            notification = new AttributesUpdateNotification(BasicAttributeKVMsg.fromDeleted(sharedKeys));
        } else {
            if (DataConstants.SHARED_SCOPE.equals(msg.getScope())) {
                List<AttributeKvEntry> attributes = new ArrayList<>(msg.getValues());
                if (attributes.size() > 0) {
                    notification = new AttributesUpdateNotification(BasicAttributeKVMsg.fromShared(attributes));
                } else {
                    logger.debug("[{}] No public server side attributes changed!", deviceId);
                }
            }
        }
        if (notification != null) {
            ToDeviceMsg finalNotification = notification;
            attributeSubscriptions.entrySet().forEach(sub -> {
                ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(finalNotification, sub.getKey());
                sendMsgToSessionActor(response, sub.getValue().getServer());
            });
        }
    } else {
        logger.debug("[{}] No registered attributes subscriptions to process!", deviceId);
    }
}
Also used : AttributeKey(org.thingsboard.server.common.data.kv.AttributeKey) java.util(java.util) Device(org.thingsboard.server.common.data.Device) TimeoutException(java.util.concurrent.TimeoutException) MsgType(org.thingsboard.server.common.msg.session.MsgType) TimeoutMsg(org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg) BasicAttributeKVMsg(org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg) FromDeviceMsg(org.thingsboard.server.common.msg.session.FromDeviceMsg) ToDeviceRpcRequestBody(org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestBody) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) FromDeviceRpcResponse(org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse) ActorRef(akka.actor.ActorRef) ActorSystemContext(org.thingsboard.server.actors.ActorSystemContext) AbstractContextAwareMsgProcessor(org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor) RuleChainDeviceMsg(org.thingsboard.server.actors.tenant.RuleChainDeviceMsg) ClusterEventMsg(org.thingsboard.server.common.msg.cluster.ClusterEventMsg) ToPluginRpcResponseDeviceMsg(org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg) ToDeviceMsg(org.thingsboard.server.common.msg.session.ToDeviceMsg) AttributeKey(org.thingsboard.server.common.data.kv.AttributeKey) DeviceId(org.thingsboard.server.common.data.id.DeviceId) TimeoutIntMsg(org.thingsboard.server.extensions.api.plugins.msg.TimeoutIntMsg) DataConstants(org.thingsboard.server.common.data.DataConstants) ActorContext(akka.actor.ActorContext) ToDeviceRpcRequestPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg) SessionId(org.thingsboard.server.common.data.id.SessionId) org.thingsboard.server.common.msg.core(org.thingsboard.server.common.msg.core) Predicate(java.util.function.Predicate) LoggingAdapter(akka.event.LoggingAdapter) RpcError(org.thingsboard.server.extensions.api.plugins.msg.RpcError) org.thingsboard.server.actors.rule(org.thingsboard.server.actors.rule) ToDeviceRpcRequest(org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequest) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) org.thingsboard.server.extensions.api.device(org.thingsboard.server.extensions.api.device) ToDeviceActorMsg(org.thingsboard.server.common.msg.device.ToDeviceActorMsg) SessionType(org.thingsboard.server.common.msg.session.SessionType) ServerAddress(org.thingsboard.server.common.msg.cluster.ServerAddress) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) ToDeviceMsg(org.thingsboard.server.common.msg.session.ToDeviceMsg)

Aggregations

ActorContext (akka.actor.ActorContext)1 ActorRef (akka.actor.ActorRef)1 LoggingAdapter (akka.event.LoggingAdapter)1 java.util (java.util)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 ActorSystemContext (org.thingsboard.server.actors.ActorSystemContext)1 org.thingsboard.server.actors.rule (org.thingsboard.server.actors.rule)1 AbstractContextAwareMsgProcessor (org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor)1 RuleChainDeviceMsg (org.thingsboard.server.actors.tenant.RuleChainDeviceMsg)1 DataConstants (org.thingsboard.server.common.data.DataConstants)1 Device (org.thingsboard.server.common.data.Device)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 SessionId (org.thingsboard.server.common.data.id.SessionId)1 AttributeKey (org.thingsboard.server.common.data.kv.AttributeKey)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 ClusterEventMsg (org.thingsboard.server.common.msg.cluster.ClusterEventMsg)1