Package org.drools.common

Examples of org.drools.common.DefaultFactHandle


        liaNode.addTupleSink( sink );
       
        final Object string1 = "cheese";

        // assert object
        final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert( string1 );
        liaNode.assertObject( f0,
                              pcontext,
                              workingMemory );

        final List asserted = sink.getAsserted();
View Full Code Here


        ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                     (ReteooRuleBase) RuleBaseFactory.newRuleBase() );

        BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( join1 );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0,
                                                            0 );
        final LeftTupleImpl tuple0 = new LeftTupleImpl( f0,
                                                join1,
                                                true );

        // assert tuple, should add one to left memory
        join1.assertLeftTuple( tuple0,
                               context,
                               workingMemory );
        // check memories, left memory is populated, right memory is emptys
        assertEquals( 1,
                      memory.getLeftTupleMemory().size() );
        assertEquals( 0,
                      memory.getRightTupleMemory().size() );

        // assert tuple, should add left memory should be 2
        final DefaultFactHandle f1 = new DefaultFactHandle( 1,
                                                            0 );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( f1,
                                                join1,
                                                true );
        join1.assertLeftTuple( tuple1,
View Full Code Here

                                                             rule2,
                                                             rule2.getLhs(),
                                                             0,
                                                             buildContext );

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               null,
                                               true );

        final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule1,
                                                                        null,
                                                                        new DefaultFactHandle() );

        // Add consequence. Notice here the context here for the add to ageyunda
        // is itself
        rule1.setConsequence( new org.drools.spi.Consequence() {
            private static final long serialVersionUID = 510l;
View Full Code Here

                                                             0,
                                                             buildContext );

        Cheese cheese = new Cheese();
        cheese.setPrice( 50 );
        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1, cheese),null,true );

        final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule1,
                                                                        null,
                                                                        new DefaultFactHandle() );

        // Add consequence. Notice here the context here for the add to ageyunda
        // is itself
        rule1.setConsequence( new org.drools.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.runtime.rule.Session wm,
                                        Match activation) {
                        cheese.setPrice( oldPrice );
                    }
                } );
            }

            public void readExternal(ObjectInput in) throws IOException,
                                                    ClassNotFoundException {

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }

            public String getName() {
                return "default";
            }
        } );

        assertEquals( 50, cheese.getPrice() );
       
        node1.assertLeftTuple( tuple,
                               context1,
                               workingMemory );
  
       
        agenda.unstageActivations();
        agenda.fireNextItem( null );
        assertEquals( 100, cheese.getPrice() );
       
        final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                        PropagationContext.DELETION,
                                                                        rule1,
                                                                        null,
                                                                        new DefaultFactHandle() );

        node1.retractLeftTuple( tuple, context0, workingMemory );
       
        assertEquals( 50, cheese.getPrice() );
    }
View Full Code Here

            public String getName() {
                return "default";
            }
        } );

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               node,
                                               true );
        final PropagationContext context = new PropagationContextImpl( 0,
                                                                       PropagationContext.INSERTION,
                                                                       rule,
                                                                       null,
                                                                       new DefaultFactHandle() );

        // test agenda is empty
        assertEquals( 0,
                      agenda.getFocus().size() );
View Full Code Here

            public String getName() {
                return "default";
            }
        };

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               null,
                                               true );

        // create a rule for each agendaGroup
        final Rule rule0 = new Rule( "test-rule0" );
        final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                             new MockTupleSource( 2 ),
                                                             rule0,
                                                             rule0.getLhs(),
                                                             0,
                                                             buildContext );
        rule0.setConsequence( consequence );
        final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule0,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule1 = new Rule( "test-rule1",
                                     "agendaGroup1" );
        final RuleTerminalNode node1 = new RuleTerminalNode( 5,
                                                             new MockTupleSource( 4 ),
                                                             rule1,
                                                             rule1.getLhs(),
                                                             0,
                                                             buildContext );
        rule1.setConsequence( consequence );
        final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule1,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule2 = new Rule( "test-rule2",
                                     "agendaGroup2" );
        final RuleTerminalNode node2 = new RuleTerminalNode( 7,
                                                             new MockTupleSource( 6 ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             0,
                                                             buildContext );
        rule2.setConsequence( consequence );
        final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule2,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule3 = new Rule( "test-rule3",
                                     "agendaGroup3" );
        final RuleTerminalNode node3 = new RuleTerminalNode( 9,
                                                             new MockTupleSource( 8 ),
                                                             rule3,
                                                             rule3.getLhs(),
                                                             0,
                                                             buildContext );
        rule3.setConsequence( consequence );
        final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule3,
                                                                        null,
                                                                        new DefaultFactHandle() );

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

        // create the AgendaGroups
        final AgendaGroup agendaGroup1 = new BinaryHeapQueueAgendaGroup( "agendaGroup1",
View Full Code Here

            public String getName() {
                return "default";
            }
        };

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               null,
                                               true );

        // create a rule for the agendaGroup
        final Rule rule = new Rule( "test-rule",
                                    "agendaGroup" );
        final RuleTerminalNode node = new RuleTerminalNode( 2,
                                                            new MockTupleSource( 2 ),
                                                            rule,
                                                            rule.getLhs(),
                                                            0,
                                                            buildContext );
        rule.setConsequence( consequence );
        final PropagationContext context = new PropagationContextImpl( 0,
                                                                       PropagationContext.INSERTION,
                                                                       rule,
                                                                       null,
                                                                       new DefaultFactHandle() );

        // first test that autoFocus=false works. Here the rule should not fire
        // as its agendaGroup does not have focus.
        rule.setAutoFocus( false );
View Full Code Here

        // create the agendaGroup
        final InternalAgendaGroup agendaGroup = new BinaryHeapQueueAgendaGroup( "agendaGroup",
                                                                                ruleBase );
        agenda.addAgendaGroup( agendaGroup );

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               null,
                                               true );

        // create a rule for the agendaGroup
        final Rule rule = new Rule( "test-rule",
                                    "agendaGroup" );
        final RuleTerminalNode node = new RuleTerminalNode( 2,
                                                            new MockTupleSource( 2 ),
                                                            rule,
                                                            rule.getLhs(),
                                                            0,
                                                            buildContext );

        final PropagationContext context = new PropagationContextImpl( 0,
                                                                       PropagationContext.INSERTION,
                                                                       rule,
                                                                       null,
                                                                       new DefaultFactHandle() );

        // When both the rule is lock-on-active and the agenda group is active, activations should be ignored
        rule.setLockOnActive( true );
        agendaGroup.setActive( true );
        node.assertLeftTuple( tuple,
View Full Code Here

            public String getName() {
                return "default";
            }
        };

        final LeftTupleImpl tuple = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                      "cheese" ),
                                               null,
                                               true );

        // create a rule for each agendaGroup
        final Rule rule0 = new Rule( "test-rule0" );
        rule0.setActivationGroup( "activation-group-0" );
        final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                             new MockTupleSource( 2 ),
                                                             rule0,
                                                             rule0.getLhs(),
                                                             0,
                                                             buildContext );
        rule0.setConsequence( consequence );
        final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule0,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule1 = new Rule( "test-rule1" );
        rule1.setActivationGroup( "activation-group-0" );
        rule1.setSalience( new SalienceInteger(10) );
        final RuleTerminalNode node1 = new RuleTerminalNode( 5,
                                                             new MockTupleSource( 4 ),
                                                             rule1,
                                                             rule1.getLhs(),
                                                             0,
                                                             buildContext );
        rule1.setConsequence( consequence );
        final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule1,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule2 = new Rule( "test-rule2" );
        rule2.setSalience( new SalienceInteger( -5 ) );
        final RuleTerminalNode node2 = new RuleTerminalNode( 7,
                                                             new MockTupleSource( 6 ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             0,
                                                             buildContext );
        rule2.setConsequence( consequence );
        final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule2,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final Rule rule3 = new Rule( "test-rule3",
                                     "agendaGroup3" );
        rule3.setSalience( new SalienceInteger( -10 ) );
        rule3.setActivationGroup( "activation-group-3" );
        final RuleTerminalNode node3 = new RuleTerminalNode( 9,
                                                             new MockTupleSource( 8 ),
                                                             rule3,
                                                             rule3.getLhs(),
                                                             0,
                                                             buildContext );
        rule3.setConsequence( consequence );
        final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule3,
                                                                        null,
                                                                        new DefaultFactHandle() );

        // Assert the tuple and check it was added to activation-group-0
        node0.assertLeftTuple( tuple,
                               context0,
                               workingMemory );
View Full Code Here

        final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                        PropagationContext.INSERTION,
                                                                        rule0,
                                                                        null,
                                                                        new DefaultFactHandle() );

        final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
        final RuleFlowGroup ruleFlowGroup1 = agenda.getRuleFlowGroup( "rule-flow-group-1" );
        final RuleFlowGroup ruleFlowGroup2 = agenda.getRuleFlowGroup( "rule-flow-group-2" );

        final LeftTupleImpl tuple0 = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                       "cheese" ),
                                                null,
                                                true );
        node0.assertLeftTuple( tuple0,
                               context0,
                               workingMemory );

        final LeftTupleImpl tuple1 = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                       "cheese" ),
                                                null,
                                                true );
        node0.assertLeftTuple( tuple1,
                               context0,
                               workingMemory );

        final LeftTupleImpl tuple2 = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                       "cheese" ),
                                                null,
                                                true );
        node1.assertLeftTuple( tuple2,
                               context0,
                               workingMemory );

        final LeftTupleImpl tuple3 = new LeftTupleImpl( new DefaultFactHandle( 1,
                                                                       "cheese" ),
                                                null,
                                                true );
        node2.assertLeftTuple( tuple3,
                               context0,
View Full Code Here

TOP

Related Classes of org.drools.common.DefaultFactHandle

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.