Search in sources :

Example 1 with UpdateContext

use of org.drools.core.common.UpdateContext in project drools by kiegroup.

the class ConditionalBranchBuilder method buildConditionalBranchEvaluator.

private ConditionalBranchEvaluator buildConditionalBranchEvaluator(BuildContext context, ConditionalBranch conditionalBranch) {
    RuleTerminalNode terminalNode = buildTerminalNodeForNamedConsequence(context, conditionalBranch.getNamedConsequence());
    terminalNode.networkUpdated(new UpdateContext());
    // adds the terminal node to the list of nodes created/added by this sub-rule
    context.getNodes().add(terminalNode);
    return new ConditionalBranchEvaluator(conditionalBranch.getEvalCondition(), context.getTupleSource().getPartitionId(), terminalNode, conditionalBranch.getNamedConsequence().isBreaking(), conditionalBranch.getElseBranch() != null ? buildConditionalBranchEvaluator(context, conditionalBranch.getElseBranch()) : null);
}
Also used : ConditionalBranchEvaluator(org.drools.core.reteoo.ConditionalBranchEvaluator) UpdateContext(org.drools.core.common.UpdateContext) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 2 with UpdateContext

use of org.drools.core.common.UpdateContext in project drools by kiegroup.

the class NamedConsequenceBuilder method build.

public void build(BuildContext context, BuildUtils utils, RuleConditionElement rce) {
    NamedConsequence namedConsequence = (NamedConsequence) rce;
    Timer timer = context.getRule().getTimer();
    if (timer != null) {
        ReteooComponentBuilder builder = utils.getBuilderFor(Timer.class);
        builder.build(context, utils, context.getRule().getTimer());
    }
    RuleTerminalNode terminalNode = buildTerminalNodeForNamedConsequence(context, namedConsequence);
    terminalNode.attach(context);
    terminalNode.networkUpdated(new UpdateContext());
    // adds the terminal node to the list of nodes created/added by this sub-rule
    context.getNodes().add(terminalNode);
    if (timer != null) {
        context.setTupleSource(context.getTupleSource().getLeftTupleSource());
    }
    context.setTerminated(namedConsequence.isTerminal());
}
Also used : Timer(org.drools.core.time.impl.Timer) UpdateContext(org.drools.core.common.UpdateContext) NamedConsequence(org.drools.core.rule.NamedConsequence) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 3 with UpdateContext

use of org.drools.core.common.UpdateContext in project drools by kiegroup.

the class ReteooRuleBuilder method addSubRule.

private TerminalNode addSubRule(final BuildContext context, final GroupElement subrule, final int subruleIndex, final RuleImpl rule) throws InvalidPatternException {
    context.setSubRule(subrule);
    // gets the appropriate builder
    ReteooComponentBuilder builder = this.utils.getBuilderFor(subrule);
    // checks if an initial-fact is needed
    if (builder.requiresLeftActivation(this.utils, subrule)) {
        this.addInitialFactPattern(subrule);
    }
    // builds and attach
    builder.build(context, this.utils, subrule);
    if (context.isTerminated()) {
        context.setTerminated(false);
        return ((TerminalNode) context.getLastNode());
    }
    if (rule.getTimer() != null) {
        builder = this.utils.getBuilderFor(Timer.class);
        builder.build(context, this.utils, rule.getTimer());
    }
    ActivationListenerFactory factory = context.getKnowledgeBase().getConfiguration().getActivationListenerFactory(rule.getActivationListener());
    TerminalNode terminal = factory.createActivationListener(context.getNextId(), context.getTupleSource(), rule, subrule, subruleIndex, context);
    BaseNode baseTerminalNode = (BaseNode) terminal;
    baseTerminalNode.networkUpdated(new UpdateContext());
    baseTerminalNode.attach(context);
    setPathEndNodes(context);
    AddRemoveRule.addRule(terminal, context.getWorkingMemories(), context.getKnowledgeBase());
    // adds the terminal node to the list of nodes created/added by this sub-rule
    context.getNodes().add(baseTerminalNode);
    return terminal;
}
Also used : Timer(org.drools.core.time.impl.Timer) BaseNode(org.drools.core.common.BaseNode) UpdateContext(org.drools.core.common.UpdateContext) ActivationListenerFactory(org.drools.core.ActivationListenerFactory) TerminalNode(org.drools.core.reteoo.TerminalNode)

Aggregations

UpdateContext (org.drools.core.common.UpdateContext)3 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)2 Timer (org.drools.core.time.impl.Timer)2 ActivationListenerFactory (org.drools.core.ActivationListenerFactory)1 BaseNode (org.drools.core.common.BaseNode)1 ConditionalBranchEvaluator (org.drools.core.reteoo.ConditionalBranchEvaluator)1 TerminalNode (org.drools.core.reteoo.TerminalNode)1 NamedConsequence (org.drools.core.rule.NamedConsequence)1