Package org.drools.common

Examples of org.drools.common.BinaryHeapQueueAgendaGroup


                                                                        new DefaultFactHandle() );

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

        // create the AgendaGroups
        final AgendaGroup agendaGroup1 = new BinaryHeapQueueAgendaGroup( "agendaGroup1",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup1 );

        final AgendaGroup agendaGroup2 = new BinaryHeapQueueAgendaGroup( "agendaGroup2",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup2 );

        final AgendaGroup agendaGroup3 = new BinaryHeapQueueAgendaGroup( "agendaGroup3",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup3 );

        // focus at this point is MAIN
        assertEquals( 0,
View Full Code Here


    public void testAutoFocus() throws ConsequenceException {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

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

        // create the consequence
        final Consequence consequence = new Consequence() {
            private static final long serialVersionUID = 510l;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                // do nothing
            }

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

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }

            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 );

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();

        // check activation as added to the agendaGroup
        assertEquals( 1,
                      agendaGroup.size() );

        // fire next item, agendaGroup should not fire as its not on the focus stack
        // and thus should retain its sinle activation
        agenda.fireNextItem( null );
        assertEquals( 1,
                      agendaGroup.size() );

        // Clear the agenda we we can test again
        agenda.clearAndCancel();
        assertEquals( 0,
                      agendaGroup.size() );

        // Now test that autoFocus=true works. Here the rule should fire as its
        // agendaGroup gets the focus when the activation is created.
        rule.setAutoFocus( true );

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();

        assertEquals( 1,
                      agendaGroup.size() );
        agenda.fireNextItem( null );
        assertEquals( 0,
                      agendaGroup.size() );
    }
View Full Code Here

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

        // 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,
                              context,
                              workingMemory );
        // activation should be ignored
        assertEquals( 0,
                      agendaGroup.size() );

        // lock-on-active is now false so activation should propagate
        rule.setLockOnActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();
       
        assertEquals( 1,
                      agendaGroup.size() );

        // even if lock-on-active is true, unless the agenda group is active the activation will still propagate
        rule.setLockOnActive( true );
        agendaGroup.setActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
        agenda.unstageActivations();
        assertEquals( 2,
                      agendaGroup.size() );
    }
View Full Code Here

                                                                        null );

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

        // create the AgendaGroups
        final AgendaGroup agendaGroup1 = new BinaryHeapQueueAgendaGroup( "agendaGroup1",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup1 );

        final AgendaGroup agendaGroup2 = new BinaryHeapQueueAgendaGroup( "agendaGroup2",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup2 );

        final AgendaGroup agendaGroup3 = new BinaryHeapQueueAgendaGroup( "agendaGroup3",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup3 );

        // focus at this point is MAIN
        assertEquals( 0,
View Full Code Here

    public void testAutoFocus() throws ConsequenceException {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

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

        // create the consequence
        final Consequence consequence = new Consequence() {
            /**
             *
             */
            private static final long serialVersionUID = 400L;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                // do nothing
            }

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

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }
        };

        final LeftTuple tuple = new LeftTuple( 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(),
                                                            buildContext );
        rule.setConsequence( consequence );
        final PropagationContext context = new PropagationContextImpl( 0,
                                                                       PropagationContext.ASSERTION,
                                                                       rule,
                                                                       null,
                                                                       null );

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

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );

        // check activation as added to the agendaGroup
        assertEquals( 1,
                      agendaGroup.size() );

        // fire next item, agendaGroup should not fire as its not on the focus stack
        // and thus should retain its sinle activation
        agenda.fireNextItem( null );
        assertEquals( 1,
                      agendaGroup.size() );

        // Clear the agenda we we can test again
        agenda.clearAndCancel();
        assertEquals( 0,
                      agendaGroup.size() );

        // Now test that autoFocus=true works. Here the rule should fire as its
        // agendaGroup gets the focus when the activation is created.
        rule.setAutoFocus( true );

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );

        assertEquals( 1,
                      agendaGroup.size() );
        agenda.fireNextItem( null );
        assertEquals( 0,
                      agendaGroup.size() );
    }
View Full Code Here

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

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

        final LeftTuple tuple = new LeftTuple( 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(),
                                                            buildContext );

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

        // 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,
                              context,
                              workingMemory );
        // activation should be ignored
        assertEquals( 0,
                      agendaGroup.size() );

        // lock-on-active is now false so activation should propagate
        rule.setLockOnActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
        assertEquals( 1,
                      agendaGroup.size() );

        // even if lock-on-active is true, unless the agenda group is active the activation will still propagate
        rule.setLockOnActive( true );
        agendaGroup.setActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
        assertEquals( 2,
                      agendaGroup.size() );
    }
View Full Code Here

                                                                        null );

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

        // create the AgendaGroups
        final AgendaGroup agendaGroup1 = new BinaryHeapQueueAgendaGroup( "agendaGroup1",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup1 );

        final AgendaGroup agendaGroup2 = new BinaryHeapQueueAgendaGroup( "agendaGroup2",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup2 );

        final AgendaGroup agendaGroup3 = new BinaryHeapQueueAgendaGroup( "agendaGroup3",
                                                                         ruleBase );
        agenda.addAgendaGroup( agendaGroup3 );

        // focus at this point is MAIN
        assertEquals( 0,
View Full Code Here

    public void testAutoFocus() throws ConsequenceException {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

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

        // create the consequence
        final Consequence consequence = new Consequence() {
            private static final long serialVersionUID = 510l;

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                // do nothing
            }

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

            }

            public void writeExternal(ObjectOutput out) throws IOException {

            }

            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.ASSERTION,
                                                                       rule,
                                                                       null,
                                                                       null );

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

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();

        // check activation as added to the agendaGroup
        assertEquals( 1,
                      agendaGroup.size() );

        // fire next item, agendaGroup should not fire as its not on the focus stack
        // and thus should retain its sinle activation
        agenda.fireNextItem( null );
        assertEquals( 1,
                      agendaGroup.size() );

        // Clear the agenda we we can test again
        agenda.clearAndCancel();
        assertEquals( 0,
                      agendaGroup.size() );

        // Now test that autoFocus=true works. Here the rule should fire as its
        // agendaGroup gets the focus when the activation is created.
        rule.setAutoFocus( true );

        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();

        assertEquals( 1,
                      agendaGroup.size() );
        agenda.fireNextItem( null );
        assertEquals( 0,
                      agendaGroup.size() );
    }
View Full Code Here

        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

        // 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.ASSERTION,
                                                                       rule,
                                                                       null,
                                                                       null );

        // 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,
                              context,
                              workingMemory );
        // activation should be ignored
        assertEquals( 0,
                      agendaGroup.size() );

        // lock-on-active is now false so activation should propagate
        rule.setLockOnActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
       
        agenda.unstageActivations();
       
        assertEquals( 1,
                      agendaGroup.size() );

        // even if lock-on-active is true, unless the agenda group is active the activation will still propagate
        rule.setLockOnActive( true );
        agendaGroup.setActive( false );
        node.assertLeftTuple( tuple,
                              context,
                              workingMemory );
        agenda.unstageActivations();
        assertEquals( 2,
                      agendaGroup.size() );
    }
View Full Code Here

    public static void readAgenda(MarshallerReaderContext context,
                                  DefaultAgenda agenda) throws IOException {
        ObjectInputStream stream = context.stream;
        while ( stream.readShort() == PersisterEnums.AGENDA_GROUP ) {
            BinaryHeapQueueAgendaGroup group = new BinaryHeapQueueAgendaGroup( stream.readUTF(),
                                                                               context.ruleBase );
            group.setActive( stream.readBoolean() );
            agenda.getAgendaGroupsMap().put( group.getName(),
                                             group );
        }

        while ( stream.readShort() == PersisterEnums.AGENDA_GROUP ) {
            String agendaGroupName = stream.readUTF();
View Full Code Here

TOP

Related Classes of org.drools.common.BinaryHeapQueueAgendaGroup

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.