Search in sources :

Example 1 with ComponentLifecycleEvent

use of org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent 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)

Example 2 with ComponentLifecycleEvent

use of org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent in project thingsboard by thingsboard.

the class ActorSystemContext method persistLifecycleEvent.

public void persistLifecycleEvent(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent lcEvent, Exception e) {
    Event event = new Event();
    event.setTenantId(tenantId);
    event.setEntityId(entityId);
    event.setType(DataConstants.LC_EVENT);
    event.setBody(toBodyJson(discoveryService.getCurrentServer().getServerAddress(), lcEvent, Optional.ofNullable(e)));
    persistEvent(event);
}
Also used : Event(org.thingsboard.server.common.data.Event) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent)

Aggregations

ComponentLifecycleEvent (org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent)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 RuleActorMetaData (org.thingsboard.server.actors.rule.RuleActorMetaData)1 SimpleRuleActorChain (org.thingsboard.server.actors.rule.SimpleRuleActorChain)1 ContextAwareActor (org.thingsboard.server.actors.service.ContextAwareActor)1 Event (org.thingsboard.server.common.data.Event)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 ComponentLifecycleState (org.thingsboard.server.common.data.plugin.ComponentLifecycleState)1 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)1 RuleService (org.thingsboard.server.dao.rule.RuleService)1