|
|
@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.context.annotation.Lazy; |
|
|
import org.springframework.context.annotation.Lazy; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.web.socket.CloseStatus; |
|
|
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|
|
import org.thingsboard.common.util.ThingsBoardThreadFactory; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
@ -205,21 +206,30 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc |
|
|
ListenableFuture<TbEntityDataSubCtx> historyFuture; |
|
|
ListenableFuture<TbEntityDataSubCtx> historyFuture; |
|
|
if (cmd.getHistoryCmd() != null) { |
|
|
if (cmd.getHistoryCmd() != null) { |
|
|
log.trace("[{}][{}] Going to process history command: {}", session.getSessionId(), cmd.getCmdId(), cmd.getHistoryCmd()); |
|
|
log.trace("[{}][{}] Going to process history command: {}", session.getSessionId(), cmd.getCmdId(), cmd.getHistoryCmd()); |
|
|
historyFuture = handleHistoryCmd(ctx, cmd.getHistoryCmd()); |
|
|
try { |
|
|
|
|
|
historyFuture = handleHistoryCmd(ctx, cmd.getHistoryCmd()); |
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
handleWsCmdRuntimeException(ctx.getSessionId(), e, cmd); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
historyFuture = Futures.immediateFuture(ctx); |
|
|
historyFuture = Futures.immediateFuture(ctx); |
|
|
} |
|
|
} |
|
|
Futures.addCallback(historyFuture, new FutureCallback<>() { |
|
|
Futures.addCallback(historyFuture, new FutureCallback<>() { |
|
|
@Override |
|
|
@Override |
|
|
public void onSuccess(@Nullable TbEntityDataSubCtx theCtx) { |
|
|
public void onSuccess(@Nullable TbEntityDataSubCtx theCtx) { |
|
|
if (cmd.getLatestCmd() != null) { |
|
|
try { |
|
|
handleLatestCmd(theCtx, cmd.getLatestCmd()); |
|
|
if (cmd.getLatestCmd() != null) { |
|
|
} else if (cmd.getTsCmd() != null) { |
|
|
handleLatestCmd(theCtx, cmd.getLatestCmd()); |
|
|
handleTimeSeriesCmd(theCtx, cmd.getTsCmd()); |
|
|
} else if (cmd.getTsCmd() != null) { |
|
|
} else if (!theCtx.isInitialDataSent()) { |
|
|
handleTimeSeriesCmd(theCtx, cmd.getTsCmd()); |
|
|
EntityDataUpdate update = new EntityDataUpdate(theCtx.getCmdId(), theCtx.getData(), null, theCtx.getMaxEntitiesPerDataSubscription()); |
|
|
} else if (!theCtx.isInitialDataSent()) { |
|
|
wsService.sendWsMsg(theCtx.getSessionId(), update); |
|
|
EntityDataUpdate update = new EntityDataUpdate(theCtx.getCmdId(), theCtx.getData(), null, theCtx.getMaxEntitiesPerDataSubscription()); |
|
|
theCtx.setInitialDataSent(true); |
|
|
wsService.sendWsMsg(theCtx.getSessionId(), update); |
|
|
|
|
|
theCtx.setInitialDataSent(true); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
handleWsCmdRuntimeException(theCtx.getSessionId(), e, cmd); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -230,6 +240,11 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc |
|
|
}, wsCallBackExecutor); |
|
|
}, wsCallBackExecutor); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleWsCmdRuntimeException(String sessionId, RuntimeException e, EntityDataCmd cmd) { |
|
|
|
|
|
log.debug("[{}] Failed to process ws cmd: {}", sessionId, cmd, e); |
|
|
|
|
|
wsService.close(sessionId, CloseStatus.SERVICE_RESTARTED); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void handleCmd(TelemetryWebSocketSessionRef session, EntityCountCmd cmd) { |
|
|
public void handleCmd(TelemetryWebSocketSessionRef session, EntityCountCmd cmd) { |
|
|
TbEntityCountSubCtx ctx = getSubCtx(session.getSessionId(), cmd.getCmdId()); |
|
|
TbEntityCountSubCtx ctx = getSubCtx(session.getSessionId(), cmd.getCmdId()); |
|
|
|