Search in sources :

Example 1 with TenantRateLimitException

use of org.thingsboard.server.dao.util.TenantRateLimitException in project thingsboard by thingsboard.

the class DefaultTelemetryWebSocketService method getSubscriptionCallback.

private FutureCallback<List<TsKvEntry>> getSubscriptionCallback(final TelemetryWebSocketSessionRef sessionRef, final TimeseriesSubscriptionCmd cmd, final String sessionId, final EntityId entityId, final long startTs, final List<String> keys) {
    return new FutureCallback<List<TsKvEntry>>() {

        @Override
        public void onSuccess(List<TsKvEntry> data) {
            sendWsMsg(sessionRef, new TelemetrySubscriptionUpdate(cmd.getCmdId(), data));
            Map<String, Long> subState = new HashMap<>(keys.size());
            keys.forEach(key -> subState.put(key, startTs));
            data.forEach(v -> subState.put(v.getKey(), v.getTs()));
            TbTimeseriesSubscription sub = TbTimeseriesSubscription.builder().serviceId(serviceId).sessionId(sessionId).subscriptionId(cmd.getCmdId()).tenantId(sessionRef.getSecurityCtx().getTenantId()).entityId(entityId).updateConsumer(DefaultTelemetryWebSocketService.this::sendWsMsg).allKeys(false).keyStates(subState).build();
            oldSubService.addSubscription(sub);
        }

        @Override
        public void onFailure(Throwable e) {
            if (e instanceof TenantRateLimitException || e.getCause() instanceof TenantRateLimitException) {
                log.trace("[{}] Tenant rate limit detected for subscription: [{}]:{}", sessionRef.getSecurityCtx().getTenantId(), entityId, cmd);
            } else {
                log.info(FAILED_TO_FETCH_DATA, e);
            }
            TelemetrySubscriptionUpdate update = new TelemetrySubscriptionUpdate(cmd.getCmdId(), SubscriptionErrorCode.INTERNAL_ERROR, FAILED_TO_FETCH_DATA);
            sendWsMsg(sessionRef, update);
        }
    };
}
Also used : TenantRateLimitException(org.thingsboard.server.dao.util.TenantRateLimitException) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) TbTimeseriesSubscription(org.thingsboard.server.service.subscription.TbTimeseriesSubscription) TelemetrySubscriptionUpdate(org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 TenantRateLimitException (org.thingsboard.server.dao.util.TenantRateLimitException)1 TbTimeseriesSubscription (org.thingsboard.server.service.subscription.TbTimeseriesSubscription)1 TelemetrySubscriptionUpdate (org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate)1