Package org.drools.core.common

Examples of org.drools.core.common.AgendaItem


        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase(conf);
        StatefulSession wm = rbase.newStatefulSession();

        InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();
        AgendaItem item1 = new RuleTerminalNodeLeftTuple();
        AgendaItem item2 = new RuleTerminalNodeLeftTuple();
        AgendaItem item3 = new RuleTerminalNodeLeftTuple();
        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( wm );
        kcontext.setActivation( item1 );
       
        // set blockers
        kcontext.blockMatch( item2 );
        kcontext.blockMatch( item3 );
       
         // set blocked
        kcontext.reset();
        kcontext.setActivation( item2 );
        kcontext.blockMatch( item3 );
       
        // Check all references are updated correctly when item1 is retracted
        item1.removeAllBlockersAndBlocked(agenda);
        assertEquals( 0, item2.getBlockers().size() );       
        assertEquals( 1, item2.getBlocked().size() );
        assertEquals(1, item3.getBlockers().size());
        assertNull(item3.getBlocked());
        assertSame( item2, ((LogicalDependency)item2.getBlocked().getFirst()).getJustifier() );
        assertSame( item3, ((LogicalDependency)item2.getBlocked().getFirst()).getJustified() );
       
        // now retract item2
        item2.removeAllBlockersAndBlocked(agenda);
        assertEquals( 0, item3.getBlockers().size() );
        assertNull( item3.getBlocked() );
         
        assertNull( item2.getBlocked() );
        assertNull( item2.getBlocked() );
         
        assertNull( item1.getBlocked() );
        assertNull( item1.getBlocked() );
       
        // reblock with item2, so that we can retract item3
        kcontext.blockMatch( item3 );
        assertNull( item2.getBlockers() );       
        assertEquals( 1, item2.getBlocked().size() );
        assertEquals(1, item3.getBlockers().size());
        assertNull(item3.getBlocked());
        assertSame( item2, ((LogicalDependency)item2.getBlocked().getFirst()).getJustifier() );
        assertSame( item3, ((LogicalDependency)item2.getBlocked().getFirst()).getJustified() );       
       
        item3.removeAllBlockersAndBlocked(agenda);
        assertNull(item3.getBlockers() );
        assertNull( item3.getBlocked() );
         
        assertEquals( 0, item2.getBlocked().size() );
        assertNull( item2.getBlockers() );
         
        assertNull( item1.getBlocked() );
View Full Code Here


        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase(conf);
        StatefulSession wm = rbase.newStatefulSession();

        InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();
        AgendaItem item1 = new RuleTerminalNodeLeftTuple();
        AgendaItem item2 = new RuleTerminalNodeLeftTuple();
        AgendaItem item3 = new RuleTerminalNodeLeftTuple();
        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( wm );
        kcontext.setActivation( item1 );
        kcontext.blockMatch( item3 );
       
        kcontext.reset();
        kcontext.setActivation( item2 );
        kcontext.blockMatch( item3 );

        kcontext.unblockAllMatches( item3 );
           
        assertEquals( 0, item3.getBlockers().size() );
        assertNull( item3.getBlocked() );
         
        assertEquals( 0, item2.getBlocked().size() );
        assertNull( item2.getBlockers() );
         
        assertEquals( 0, item1.getBlocked().size() );
View Full Code Here

        ReteooRuleBase rbase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase(conf);
        StatefulSession wm = rbase.newStatefulSession();

        InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();
        AgendaItem item1 = new RuleTerminalNodeLeftTuple();
        AgendaItem item2 = new RuleTerminalNodeLeftTuple();
        AgendaItem item3 = new RuleTerminalNodeLeftTuple();
        AgendaItem item4 = new RuleTerminalNodeLeftTuple();
        agenda.createAgendaItem((LeftTuple)item1, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item2, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item3, 0, null, null, null, null);
        agenda.createAgendaItem((LeftTuple)item4, 0, null, null, null, null);
       
        // use same data structure as testAddition
        DefaultKnowledgeHelper kcontext = new DefaultKnowledgeHelper( wm );
        kcontext.setActivation( item1 );
       
        // set blockers
        kcontext.blockMatch( item2 );
        kcontext.blockMatch( item3 );
       
         // set blocked
        kcontext.reset();
        kcontext.setActivation( item1 );
        kcontext.blockMatch( item4 );
        kcontext.cancelRemainingPreviousLogicalDependencies();
       
        // check only item4 is blocked
        assertEquals( 1, item1.getBlocked().size() );
        assertEquals( item4, ((LogicalDependency)item1.getBlocked().getFirst()).getJustified() );
       
        assertEquals( 0, item2.getBlockers().size() );
        assertEquals( 0, item3.getBlockers().size() );
       
        assertEquals( 1, item4.getBlockers().size() );
               
    }
View Full Code Here

        rule1.setConsequence(new org.drools.core.spi.Consequence() {
            private static final long serialVersionUID = 510l;

            public void evaluate(final KnowledgeHelper knowledgeHelper,
                                 final WorkingMemory workingMemory) {
                AgendaItem item = (AgendaItem) knowledgeHelper.getMatch();
                final Cheese cheese = (Cheese) item.getTuple().getHandle().getObject();
                final int oldPrice = cheese.getPrice();
                cheese.setPrice(100);

                item.setActivationUnMatchListener(new ActivationUnMatchListener() {

                    public void unMatch(org.kie.api.runtime.rule.RuleRuntime wm,
                                        Match activation) {
                        cheese.setPrice(oldPrice);
                    }
View Full Code Here

            }
        }
    }
   
    public void unblockAllMatches(Match act) {
        AgendaItem targetMatch = ( AgendaItem ) act;
        boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty() );
       
        for ( LinkedListEntry entry = ( LinkedListEntry ) targetMatch.getBlockers().getFirst(); entry != null) {
            LinkedListEntry tmp = ( LinkedListEntry ) entry.getNext();
            LogicalDependency dep = ( LogicalDependency ) entry.getObject();
            ((AgendaItem)dep.getJustifier()).removeBlocked( dep );
            entry = tmp;
        }
       
        if ( wasBlocked ) {
            RuleAgendaItem ruleAgendaItem = targetMatch.getRuleAgendaItem();
            InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
            agenda.stageLeftTuple(ruleAgendaItem, targetMatch);
        }
    }
View Full Code Here

        if ( this.previousBlocked != null ) {
            for ( LogicalDependency dep = this.previousBlocked.getFirst(); dep != null; ) {
                LogicalDependency tmp = dep.getNext();
                this.previousBlocked.remove( dep );

                AgendaItem justified = ( AgendaItem ) dep.getJustified();
                justified.getBlockers().remove( dep.getJustifierEntry() );
                if (justified.getBlockers().isEmpty() ) {
                    RuleAgendaItem ruleAgendaItem = justified.getRuleAgendaItem();
                    ((InternalAgenda) workingMemory.getAgenda()).stageLeftTuple(ruleAgendaItem, justified);
                }
                dep = tmp;
            }
        }       
View Full Code Here

            }
        }       
    }
   
    public void cancelMatch(Match act) {
        AgendaItem match = ( AgendaItem ) act;
        ((RuleTerminalNode)match.getTerminalNode()).cancelMatch( match,  workingMemory);
    }
View Full Code Here

    public LinkedList<LogicalDependency> getpreviousJustified() {
        return previousJustified;
    }
   
    public void blockMatch(Match act) {
        AgendaItem targetMatch = ( AgendaItem ) act;
        // iterate to find previous equal logical insertion
        LogicalDependency dep = null;
        if ( this.previousJustified != null ) {
            for ( dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext() ) {
                if ( targetMatch ==  dep.getJustified() ) {
                    this.previousJustified.remove( dep );
                    break;
                }
            }
        }
       
        if ( dep == null ) {
            dep = new SimpleLogicalDependency( activation, targetMatch );
        }
        this.activation.addBlockeddep );

        if ( targetMatch.getBlockers().size() == 1 && targetMatch.isQueued()  ) {
            if ( targetMatch.getRuleAgendaItem() == null ) {
                // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed.
                targetMatch.remove();
            } else {
                targetMatch.getRuleAgendaItem().getRuleExecutor().removeLeftTuple(targetMatch.getTuple());
            }

            if ( targetMatch.getActivationGroupNode() != null ) {
                targetMatch.getActivationGroupNode().getActivationGroup().removeActivation( targetMatch );
            }

            if ( targetMatch.getActivationNode() != null ) {
                final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer();
                ruleFlowGroup.remove( targetMatch );
            }
        }
    }
View Full Code Here

                // 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;
                }
View Full Code Here

      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.isActivated() ) {
              // already activated, do nothing
              // although we need to notify the inserted Activation, as it's declarations may have changed.
              agenda.modifyActivation( match, true );
              return;
          }
View Full Code Here

TOP

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

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.