Package org.drools.core.common

Examples of org.drools.core.common.InternalAgenda


            final AgendaFilter filter,
            int fireCount,
            int fireLimit) {
        LinkedList<StackEntry> outerStack = new LinkedList<StackEntry>();

        InternalAgenda agenda = (InternalAgenda) wm.getAgenda();
        boolean fireUntilHalt = agenda.isFireUntilHalt();

        reEvaluateNetwork(wm, outerStack, fireUntilHalt);
        wm.executeQueuedActions();

        return fire(wm, filter, fireCount, fireLimit, outerStack, agenda, fireUntilHalt);
View Full Code Here


        return fire(wm, filter, fireCount, fireLimit, outerStack, agenda, fireUntilHalt);
    }

    public synchronized void fire(InternalWorkingMemory wm, LinkedList<StackEntry> outerStack) {
        InternalAgenda agenda = (InternalAgenda) wm.getAgenda();
        boolean fireUntilHalt = agenda.isFireUntilHalt();
        fire(wm, null, 0, Integer.MAX_VALUE, outerStack, agenda, fireUntilHalt);
    }
View Full Code Here

    public void doLeftInserts(TerminalNode rtnNode,
                              InternalWorkingMemory wm,
                              LeftTupleSets srcLeftTuples,
                              RuleExecutor executor) {
        InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();
        RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();

        int salienceInt = 0;
        Salience salience = ruleAgendaItem.getRule().getSalience();
        if ( !salience.isDynamic() ) {
View Full Code Here

    public void doLeftUpdates(TerminalNode rtnNode,
                              InternalWorkingMemory wm,
                              LeftTupleSets srcLeftTuples,
                              RuleExecutor executor) {
        InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();

        RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();
        if ( rtnNode.getRule().getAutoFocus() && !ruleAgendaItem.getAgendaGroup().isActive() ) {
            ((DefaultAgenda)wm.getAgenda()).setFocus(ruleAgendaItem.getAgendaGroup());
        }
View Full Code Here

             (this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() )) ) {
            leftTuple.setObject( Boolean.TRUE );
            return;
        }

        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();       

        boolean fire = agenda.createActivation( leftTuple,  context,
                                                workingMemory,  this );
        if( fire && !fireDirect ) {
            agenda.addActivation( (AgendaItem) leftTuple.getObject() );
        }
    }
View Full Code Here

        if( unlinkingEnabled ) {
            context = findMostRecentPropagationContext( leftTuple,
                                                        context );
        }
       
      InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
     
        // we need the inserted facthandle so we can update the network with new Activation
      Object o = leftTuple.getObject();
      if ( o != Boolean.TRUE) {  // would be true due to lock-on-active blocking activation creation
        AgendaItem match = (AgendaItem) o;      
          if ( match != null && match.isQueued() ) {
              // already activated, do nothing
              // although we need to notify the inserted Activation, as it's declarations may have changed.
              agenda.modifyActivation( match, true );
              return;
          }
      }

        // if the current Rule is no-loop and the origin rule is the same then return
        if ( (!this.rule.isEffective( leftTuple,
                                      this,
                                      workingMemory )) ||
             (this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() )) ) {
            return;
        }

        // o (AgendaItem) could be null, if this was staged as an insert but not processed, then pushed as a update
        if ( o == null || o  == Boolean.TRUE ) {
          // set to Boolean.TRUE when lock-on-active stops an Activation being created
          leftTuple.setObject( null );
        }
        boolean fire = agenda.createActivation( leftTuple, context, workingMemory, this );
        if ( fire && !isFireDirect() ) {
            agenda.modifyActivation( (AgendaItem) leftTuple.getObject(), false );
        }
    }
View Full Code Here

        }

        Activation activation = (Activation) obj;
        activation.setMatched( false );
       
        InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

        agenda.cancelActivation( leftTuple,
                                 context,
                                 workingMemory,
                                 activation,
                                 this );
View Full Code Here

                                      final AgendaFilter filter,
                                      int fireCount,
                                      int fireLimit) {
        LinkedList<StackEntry> outerStack = new LinkedList<StackEntry>();

        InternalAgenda agenda = (InternalAgenda) wm.getAgenda();
        boolean fireUntilHalt = agenda.isFireUntilHalt();

        reEvaluateNetwork(wm, outerStack, fireUntilHalt);
        wm.executeQueuedActions();

        //int fireCount = 0;
        int localFireCount = 0;
        if (!tupleList.isEmpty()) {
            RuleTerminalNode rtn = (RuleTerminalNode) pmem.getNetworkNode();


            int salience = ruleAgendaItem.getSalience();

            if (isDeclarativeAgendaEnabled()) {
                // Network Evaluation can notify meta rules, which should be given a chance to fire first
                RuleAgendaItem nextRule = agenda.peekNextRule();
                if (!isHighestSalience(nextRule, salience)) {
                    return localFireCount;
                }
            }

            while (!tupleList.isEmpty()) {
                LeftTuple leftTuple;
                if (queue != null) {
                    leftTuple = (LeftTuple) queue.dequeue();
                    tupleList.remove(leftTuple);
                } else {
                    leftTuple = tupleList.removeFirst();
                    ((Activation)leftTuple).setQueued( false );
                }

                rtn = (RuleTerminalNode) leftTuple.getSink(); // branches result in multiple RTN's for a given rule, so unwrap per LeftTuple
                Rule rule = rtn.getRule();

                PropagationContext pctx = leftTuple.getPropagationContext();
                pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple,
                                                                         pctx);

                //check if the rule is not effective or
                // if the current Rule is no-loop and the origin rule is the same then return
                if (cancelAndContinue(wm, rtn, rule, leftTuple, pctx, filter)) {
                    continue;

                }

                AgendaItem item = (AgendaItem) leftTuple;
                if (agenda.getActivationsFilter() != null && !agenda.getActivationsFilter().accept(item, wm, rtn)) {
                    // only relevant for seralization, to not refire Matches already fired
                    continue;
                }

                agenda.fireActivation(item);
                localFireCount++;

                salience = ruleAgendaItem.getSalience(); // dyanmic salience may have updated it, so get again.
                if (queue != null && !queue.isEmpty() && salience != queue.peek().getSalience()) {
                    ruleAgendaItem.dequeue();
                    ruleAgendaItem.setSalience(queue.peek().getSalience());
                    ruleAgendaItem.getAgendaGroup().add(ruleAgendaItem);
                    salience = ruleAgendaItem.getSalience();
                }

                RuleAgendaItem nextRule = agenda.peekNextRule();
                if (haltRuleFiring(nextRule, fireCount, fireLimit, localFireCount, agenda, salience)) {
                    break; // another rule has high priority and is on the agenda, so evaluate it first
                }
                reEvaluateNetwork(wm, outerStack, fireUntilHalt);
                wm.executeQueuedActions();
View Full Code Here

        ksession.setGlobal( "list", list );

        // AgendaGroup "group1" is not active, so should receive activation
        final Cheese brie12 = new Cheese( "brie", 12 );
        ksession.insert( brie12 );
        InternalAgenda agenda = ((AgendaImpl) ksession.getAgenda()).getAgenda();
        final AgendaGroup group1 = agenda.getAgendaGroup( "group1" );
        assertEquals( 1, group1.size() );

        ksession.getAgenda().getAgendaGroup("group1").setFocus( );
        // AgendaqGroup "group1" is now active, so should not receive activations
        final Cheese brie10 = new Cheese( "brie", 10 );
        ksession.insert( brie10 );
        assertEquals( 1, group1.size() );

        final Cheese cheddar20 = new Cheese( "cheddar", 20 );
        ksession.insert( cheddar20 );
        final AgendaGroup group2 = agenda.getAgendaGroup( "group1" );
        assertEquals( 1, group2.size() );

        agenda.setFocus(group2);
        final Cheese cheddar17 = new Cheese( "cheddar", 17 );
        ksession.insert( cheddar17 );
        assertEquals( 1, group2.size() );
    }
View Full Code Here

        ksession.insert( mic );
        ksession.insert( mark );

        InternalWorkingMemory wm = ( InternalWorkingMemory )((StatefulKnowledgeSessionImpl) ksession).getInternalWorkingMemory();

        final InternalAgenda agenda = (InternalAgenda) ((AgendaImpl)ksession.getAgenda()).getAgenda();
        final AgendaGroup group1 = agenda.getAgendaGroup( "group1" );
        if ( phreak == RuleEngineOption.RETEOO ) {
            agenda.setFocus( group1 );
            assertEquals( 3, group1.size() );
            agenda.fireNextItem( null, 0, 0 );
            assertEquals( 2, group1.size() );
            ksession.update( brieHandle, brie );
            assertEquals( 2, group1.size() );

            AgendaGroup group2 = agenda.getAgendaGroup( "group2" );
            assertEquals( 3, group2.size() );
            agenda.setFocus( group2 );

            agenda.activateRuleFlowGroup( "ruleflow2" );
            agenda.fireNextItem( null, 0, 0 );
            assertEquals( 2, group2.size() );
            ksession.update( brieHandle, brie );
            assertEquals( 2, group2.size() );
        } else {
            agenda.setFocus( group1 );
            assertEquals( 1, group1.size() );
            RuleAgendaItem ruleItem1 = (RuleAgendaItem) group1.getActivations()[0];
            ruleItem1.getRuleExecutor().evaluateNetwork(wm);
            assertEquals(3, ruleItem1.getRuleExecutor().getLeftTupleList().size());

            agenda.fireNextItem( null, 0, 0 );
            assertEquals( 1, group1.size() );
            assertEquals( 2, ruleItem1.getRuleExecutor().getLeftTupleList().size() );

            ksession.update( brieHandle, brie );
            assertEquals( 1, group1.size() );
            ruleItem1.getRuleExecutor().evaluateNetwork(wm);
            assertEquals(2, ruleItem1.getRuleExecutor().getLeftTupleList().size());

            AgendaGroup group2 = agenda.getAgendaGroup( "group2" );
            agenda.setFocus( group2);
            assertEquals( 1, group2.size() );
            RuleAgendaItem ruleItem2 = (RuleAgendaItem) group2.getActivations()[0];
            ruleItem2.getRuleExecutor().evaluateNetwork(wm);
            assertEquals(3, ruleItem2.getRuleExecutor().getLeftTupleList().size());

            agenda.fireNextItem( null, 0, 0 );
            assertEquals( 1, group2.size() );
            assertEquals( 2, ruleItem2.getRuleExecutor().getLeftTupleList().size() );

            ksession.update( brieHandle, brie );
            assertEquals( 1, group2.size() );
View Full Code Here

TOP

Related Classes of org.drools.core.common.InternalAgenda

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.