Search in sources :

Example 1 with RuleActorMetaData

use of org.thingsboard.server.actors.rule.RuleActorMetaData in project thingsboard by thingsboard.

the class RuleManager method refreshRuleChain.

private void refreshRuleChain() {
    Set<RuleActorMetaData> activeRuleSet = new HashSet<>();
    for (Map.Entry<RuleMetaData, RuleActorMetaData> rule : ruleMap.entrySet()) {
        if (rule.getKey().getState() == ComponentLifecycleState.ACTIVE) {
            activeRuleSet.add(rule.getValue());
        }
    }
    ruleChain = new SimpleRuleActorChain(activeRuleSet);
}
Also used : RuleActorMetaData(org.thingsboard.server.actors.rule.RuleActorMetaData) SimpleRuleActorChain(org.thingsboard.server.actors.rule.SimpleRuleActorChain) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 2 with RuleActorMetaData

use of org.thingsboard.server.actors.rule.RuleActorMetaData in project thingsboard by thingsboard.

the class RuleManager method update.

public Optional<ActorRef> update(ActorContext context, RuleId ruleId, ComponentLifecycleEvent event) {
    if (ruleMap == null) {
        doInit(context);
    }
    RuleMetaData rule;
    if (event != ComponentLifecycleEvent.DELETED) {
        rule = systemContext.getRuleService().findRuleById(ruleId);
    } else {
        rule = ruleMap.keySet().stream().filter(r -> r.getId().equals(ruleId)).peek(r -> r.setState(ComponentLifecycleState.SUSPENDED)).findFirst().orElse(null);
        if (rule != null) {
            ruleMap.remove(rule);
            ruleActors.remove(ruleId);
        }
    }
    if (rule != null) {
        RuleActorMetaData actorMd = ruleMap.get(rule);
        if (actorMd == null) {
            ActorRef ref = getOrCreateRuleActor(context, rule.getId());
            actorMd = RuleActorMetaData.systemRule(rule.getId(), rule.getWeight(), ref);
            ruleMap.put(rule, actorMd);
        }
        refreshRuleChain();
        return Optional.of(actorMd.getActorRef());
    } else {
        log.warn("[{}] Can't process unknown rule!", ruleId);
        return Optional.empty();
    }
}
Also used : RuleId(org.thingsboard.server.common.data.id.RuleId) RuleService(org.thingsboard.server.dao.rule.RuleService) java.util(java.util) ActorContext(akka.actor.ActorContext) SimpleRuleActorChain(org.thingsboard.server.actors.rule.SimpleRuleActorChain) ContextAwareActor(org.thingsboard.server.actors.service.ContextAwareActor) FetchFunction(org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction) TenantId(org.thingsboard.server.common.data.id.TenantId) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent) Slf4j(lombok.extern.slf4j.Slf4j) RuleActor(org.thingsboard.server.actors.rule.RuleActor) RuleActorChain(org.thingsboard.server.actors.rule.RuleActorChain) PageDataIterable(org.thingsboard.server.common.data.page.PageDataIterable) ComponentLifecycleState(org.thingsboard.server.common.data.plugin.ComponentLifecycleState) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) ActorRef(akka.actor.ActorRef) ActorSystemContext(org.thingsboard.server.actors.ActorSystemContext) Props(akka.actor.Props) RuleActorMetaData(org.thingsboard.server.actors.rule.RuleActorMetaData) RuleActorMetaData(org.thingsboard.server.actors.rule.RuleActorMetaData) ActorRef(akka.actor.ActorRef) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Aggregations

RuleActorMetaData (org.thingsboard.server.actors.rule.RuleActorMetaData)2 SimpleRuleActorChain (org.thingsboard.server.actors.rule.SimpleRuleActorChain)2 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)2 ActorContext (akka.actor.ActorContext)1 ActorRef (akka.actor.ActorRef)1 Props (akka.actor.Props)1 java.util (java.util)1 Slf4j (lombok.extern.slf4j.Slf4j)1 ActorSystemContext (org.thingsboard.server.actors.ActorSystemContext)1 RuleActor (org.thingsboard.server.actors.rule.RuleActor)1 RuleActorChain (org.thingsboard.server.actors.rule.RuleActorChain)1 ContextAwareActor (org.thingsboard.server.actors.service.ContextAwareActor)1 RuleId (org.thingsboard.server.common.data.id.RuleId)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 PageDataIterable (org.thingsboard.server.common.data.page.PageDataIterable)1 FetchFunction (org.thingsboard.server.common.data.page.PageDataIterable.FetchFunction)1 ComponentLifecycleEvent (org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent)1 ComponentLifecycleState (org.thingsboard.server.common.data.plugin.ComponentLifecycleState)1 RuleService (org.thingsboard.server.dao.rule.RuleService)1