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);
}
};
}
Aggregations