Search in sources :

Example 1 with TbEntityActorId

use of org.thingsboard.server.actors.TbEntityActorId in project thingsboard by thingsboard.

the class AppActor method onComponentLifecycleMsg.

private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) {
    TbActorRef target = null;
    if (TenantId.SYS_TENANT_ID.equals(msg.getTenantId())) {
        if (!EntityType.TENANT_PROFILE.equals(msg.getEntityId().getEntityType())) {
            log.warn("Message has system tenant id: {}", msg);
        }
    } else {
        if (EntityType.TENANT.equals(msg.getEntityId().getEntityType())) {
            TenantId tenantId = TenantId.fromUUID(msg.getEntityId().getId());
            if (msg.getEvent() == ComponentLifecycleEvent.DELETED) {
                log.info("[{}] Handling tenant deleted notification: {}", msg.getTenantId(), msg);
                deletedTenants.add(tenantId);
                ctx.stop(new TbEntityActorId(tenantId));
            } else {
                target = getOrCreateTenantActor(msg.getTenantId());
            }
        } else {
            target = getOrCreateTenantActor(msg.getTenantId());
        }
    }
    if (target != null) {
        target.tellWithHighPriority(msg);
    } else {
        log.debug("[{}] Invalid component lifecycle msg: {}", msg.getTenantId(), msg);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TbEntityActorId(org.thingsboard.server.actors.TbEntityActorId) TbActorRef(org.thingsboard.server.actors.TbActorRef)

Example 2 with TbEntityActorId

use of org.thingsboard.server.actors.TbEntityActorId in project thingsboard by thingsboard.

the class TenantActor method onQueueToRuleEngineMsg.

private void onQueueToRuleEngineMsg(QueueToRuleEngineMsg msg) {
    if (!isRuleEngine) {
        log.warn("RECEIVED INVALID MESSAGE: {}", msg);
        return;
    }
    TbMsg tbMsg = msg.getMsg();
    if (getApiUsageState().isReExecEnabled()) {
        if (tbMsg.getRuleChainId() == null) {
            if (getRootChainActor() != null) {
                getRootChainActor().tell(msg);
            } else {
                tbMsg.getCallback().onFailure(new RuleEngineException("No Root Rule Chain available!"));
                log.info("[{}] No Root Chain: {}", tenantId, msg);
            }
        } else {
            try {
                ctx.tell(new TbEntityActorId(tbMsg.getRuleChainId()), msg);
            } catch (TbActorNotRegisteredException ex) {
                log.trace("Received message for non-existing rule chain: [{}]", tbMsg.getRuleChainId());
                // TODO: 3.1 Log it to dead letters queue;
                tbMsg.getCallback().onSuccess();
            }
        }
    } else {
        log.trace("[{}] Ack message because Rule Engine is disabled", tenantId);
        tbMsg.getCallback().onSuccess();
    }
}
Also used : TbActorNotRegisteredException(org.thingsboard.server.actors.TbActorNotRegisteredException) TbEntityActorId(org.thingsboard.server.actors.TbEntityActorId) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Aggregations

TbEntityActorId (org.thingsboard.server.actors.TbEntityActorId)2 TbActorNotRegisteredException (org.thingsboard.server.actors.TbActorNotRegisteredException)1 TbActorRef (org.thingsboard.server.actors.TbActorRef)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 TbMsg (org.thingsboard.server.common.msg.TbMsg)1 RuleEngineException (org.thingsboard.server.common.msg.queue.RuleEngineException)1