Search in sources :

Example 1 with ActivationListenerFactory

use of org.drools.core.ActivationListenerFactory in project drools by kiegroup.

the class NamedConsequenceBuilder method buildTerminalNodeForNamedConsequence.

static RuleTerminalNode buildTerminalNodeForNamedConsequence(BuildContext context, NamedConsequence namedConsequence) {
    RuleImpl rule = context.getRule();
    GroupElement subrule = (GroupElement) context.peek();
    ActivationListenerFactory factory = context.getKnowledgeBase().getConfiguration().getActivationListenerFactory(rule.getActivationListener());
    context.setConsequenceName(namedConsequence.getConsequenceName());
    TerminalNode terminal = factory.createActivationListener(context.getNextId(), context.getTupleSource(), rule, subrule, // subruleIndex,
    0, context);
    context.setConsequenceName(null);
    return (RuleTerminalNode) terminal;
}
Also used : GroupElement(org.drools.core.rule.GroupElement) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ActivationListenerFactory(org.drools.core.ActivationListenerFactory) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) TerminalNode(org.drools.core.reteoo.TerminalNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 2 with ActivationListenerFactory

use of org.drools.core.ActivationListenerFactory 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

ActivationListenerFactory (org.drools.core.ActivationListenerFactory)2 TerminalNode (org.drools.core.reteoo.TerminalNode)2 BaseNode (org.drools.core.common.BaseNode)1 UpdateContext (org.drools.core.common.UpdateContext)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)1 GroupElement (org.drools.core.rule.GroupElement)1 Timer (org.drools.core.time.impl.Timer)1