|
|
|
@ -17,37 +17,33 @@ package org.thingsboard.server.actors.ruleChain; |
|
|
|
|
|
|
|
import akka.actor.ActorContext; |
|
|
|
import akka.actor.ActorRef; |
|
|
|
import org.thingsboard.rule.engine.api.TbContext; |
|
|
|
import org.thingsboard.rule.engine.api.TbNode; |
|
|
|
import org.thingsboard.rule.engine.api.TbNodeConfiguration; |
|
|
|
import org.thingsboard.server.actors.ActorSystemContext; |
|
|
|
import org.thingsboard.server.actors.shared.ComponentMsgProcessor; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
import org.thingsboard.server.common.data.id.RuleNodeId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
|
import org.thingsboard.server.common.msg.queue.PartitionChangeMsg; |
|
|
|
import org.thingsboard.server.dao.rule.RuleChainService; |
|
|
|
import org.thingsboard.server.common.msg.queue.RuleNodeException; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author Andrew Shvayka |
|
|
|
*/ |
|
|
|
public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNodeId> { |
|
|
|
|
|
|
|
private final ActorRef parent; |
|
|
|
private final String ruleChainName; |
|
|
|
private final ActorRef self; |
|
|
|
private final RuleChainService service; |
|
|
|
private RuleNode ruleNode; |
|
|
|
private TbNode tbNode; |
|
|
|
private DefaultTbContext defaultCtx; |
|
|
|
|
|
|
|
RuleNodeActorMessageProcessor(TenantId tenantId, RuleChainId ruleChainId, RuleNodeId ruleNodeId, ActorSystemContext systemContext |
|
|
|
RuleNodeActorMessageProcessor(TenantId tenantId, String ruleChainName, RuleNodeId ruleNodeId, ActorSystemContext systemContext |
|
|
|
, ActorRef parent, ActorRef self) { |
|
|
|
super(systemContext, tenantId, ruleNodeId); |
|
|
|
this.parent = parent; |
|
|
|
this.ruleChainName = ruleChainName; |
|
|
|
this.self = self; |
|
|
|
this.service = systemContext.getRuleChainService(); |
|
|
|
this.ruleNode = systemContext.getRuleChainService().findRuleNodeById(tenantId, entityId); |
|
|
|
this.defaultCtx = new DefaultTbContext(systemContext, new RuleNodeCtx(tenantId, parent, self, ruleNode)); |
|
|
|
} |
|
|
|
@ -63,8 +59,8 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod |
|
|
|
@Override |
|
|
|
public void onUpdate(ActorContext context) throws Exception { |
|
|
|
RuleNode newRuleNode = systemContext.getRuleChainService().findRuleNodeById(tenantId, entityId); |
|
|
|
boolean restartRequired = !(ruleNode.getType().equals(newRuleNode.getType()) |
|
|
|
&& ruleNode.getConfiguration().equals(newRuleNode.getConfiguration())); |
|
|
|
boolean restartRequired = state != ComponentLifecycleState.ACTIVE || |
|
|
|
!(ruleNode.getType().equals(newRuleNode.getType()) && ruleNode.getConfiguration().equals(newRuleNode.getConfiguration())); |
|
|
|
this.ruleNode = newRuleNode; |
|
|
|
this.defaultCtx.updateSelf(newRuleNode); |
|
|
|
if (restartRequired) { |
|
|
|
@ -91,7 +87,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod |
|
|
|
} |
|
|
|
|
|
|
|
public void onRuleToSelfMsg(RuleNodeToSelfMsg msg) throws Exception { |
|
|
|
checkActive(); |
|
|
|
checkActive(msg.getMsg()); |
|
|
|
if (ruleNode.isDebugMode()) { |
|
|
|
systemContext.persistDebugInput(tenantId, entityId, msg.getMsg(), "Self"); |
|
|
|
} |
|
|
|
@ -103,7 +99,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod |
|
|
|
} |
|
|
|
|
|
|
|
void onRuleChainToRuleNodeMsg(RuleChainToRuleNodeMsg msg) throws Exception { |
|
|
|
checkActive(); |
|
|
|
checkActive(msg.getMsg()); |
|
|
|
if (ruleNode.isDebugMode()) { |
|
|
|
systemContext.persistDebugInput(tenantId, entityId, msg.getMsg(), msg.getFromRelationType()); |
|
|
|
} |
|
|
|
@ -129,4 +125,8 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod |
|
|
|
return tbNode; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected RuleNodeException getInactiveException() { |
|
|
|
return new RuleNodeException("Rule Node is not active! Failed to initialize.", ruleChainName, ruleNode); |
|
|
|
} |
|
|
|
} |
|
|
|
|