|
|
|
@ -27,9 +27,11 @@ import org.springframework.util.StringUtils; |
|
|
|
import org.thingsboard.rule.engine.api.util.DonAsynchron; |
|
|
|
import org.thingsboard.server.common.data.DataConstants; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.EntityView; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|
|
|
import org.thingsboard.server.common.data.id.EntityViewId; |
|
|
|
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.BaseTsKvQuery; |
|
|
|
@ -44,6 +46,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvQuery; |
|
|
|
import org.thingsboard.server.common.msg.cluster.ServerAddress; |
|
|
|
import org.thingsboard.server.dao.attributes.AttributesService; |
|
|
|
import org.thingsboard.server.dao.entityview.EntityViewService; |
|
|
|
import org.thingsboard.server.dao.model.ModelConstants; |
|
|
|
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|
|
|
import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
|
|
|
import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; |
|
|
|
@ -97,6 +101,9 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio |
|
|
|
@Autowired |
|
|
|
private ClusterRpcService rpcService; |
|
|
|
|
|
|
|
/*@Autowired |
|
|
|
private EntityViewService entityViewService;*/ |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Lazy |
|
|
|
private DeviceStateService stateService; |
|
|
|
@ -125,17 +132,29 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addLocalWsSubscription(String sessionId, EntityId entityId, SubscriptionState sub) { |
|
|
|
String familyName = ModelConstants.DEVICE_FAMILY_NAME; |
|
|
|
|
|
|
|
//To do
|
|
|
|
if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { |
|
|
|
familyName = ModelConstants.ENTITY_VIEW_FAMILY_NAME; |
|
|
|
//EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId)
|
|
|
|
} |
|
|
|
|
|
|
|
Optional<ServerAddress> server = routingService.resolveById(entityId); |
|
|
|
Subscription subscription; |
|
|
|
if (server.isPresent()) { |
|
|
|
ServerAddress address = server.get(); |
|
|
|
log.trace("[{}] Forwarding subscription [{}] for device [{}] to [{}]", sessionId, sub.getSubscriptionId(), entityId, address); |
|
|
|
log.trace("[{}] Forwarding subscription [{}] for " + familyName + " [{}] to [{}]", sessionId, sub.getSubscriptionId(), entityId, address); |
|
|
|
subscription = new Subscription(sub, true, address); |
|
|
|
tellNewSubscription(address, sessionId, subscription); |
|
|
|
} else { |
|
|
|
log.trace("[{}] Registering local subscription [{}] for device [{}]", sessionId, sub.getSubscriptionId(), entityId); |
|
|
|
log.trace("[{}] Registering local subscription [{}] for " + familyName + " [{}]", sessionId, sub.getSubscriptionId(), entityId); |
|
|
|
subscription = new Subscription(sub, true); |
|
|
|
} |
|
|
|
|
|
|
|
/*if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { |
|
|
|
registerSubscription(sessionId, entityId, subscription); |
|
|
|
}*/ |
|
|
|
registerSubscription(sessionId, entityId, subscription); |
|
|
|
} |
|
|
|
|
|
|
|
|