Search in sources :

Example 1 with AlarmSubscriptionUpdate

use of org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate in project thingsboard by thingsboard.

the class DefaultSubscriptionManagerService method onLocalAlarmSubUpdate.

private void onLocalAlarmSubUpdate(EntityId entityId, Function<TbSubscription, TbAlarmsSubscription> castFunction, Predicate<TbAlarmsSubscription> filterFunction, Function<TbAlarmsSubscription, Alarm> processFunction, boolean deleted) {
    Set<TbSubscription> entitySubscriptions = subscriptionsByEntityId.get(entityId);
    if (entitySubscriptions != null) {
        entitySubscriptions.stream().map(castFunction).filter(Objects::nonNull).filter(filterFunction).forEach(s -> {
            Alarm alarm = processFunction.apply(s);
            if (alarm != null) {
                if (serviceId.equals(s.getServiceId())) {
                    AlarmSubscriptionUpdate update = new AlarmSubscriptionUpdate(s.getSubscriptionId(), alarm, deleted);
                    localSubscriptionService.onSubscriptionUpdate(s.getSessionId(), update, TbCallback.EMPTY);
                } else {
                    TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_CORE, s.getServiceId());
                    toCoreNotificationsProducer.send(tpi, toProto(s, alarm, deleted), null);
                }
            }
        });
    } else {
        log.debug("[{}] No device subscriptions to process!", entityId);
    }
}
Also used : TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) AlarmSubscriptionUpdate(org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate) Alarm(org.thingsboard.server.common.data.alarm.Alarm) Objects(java.util.Objects)

Aggregations

Objects (java.util.Objects)1 Alarm (org.thingsboard.server.common.data.alarm.Alarm)1 TopicPartitionInfo (org.thingsboard.server.common.msg.queue.TopicPartitionInfo)1 AlarmSubscriptionUpdate (org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate)1