Package org.drools.core.common

Examples of org.drools.core.common.AgendaGroupQueueImpl


                                                                               true);

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

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

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

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

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


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

        // create the agendaGroup
        final AgendaGroup agendaGroup = new AgendaGroupQueueImpl("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";
            }
        };


        // 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 RuleTerminalNodeLeftTuple tuple = new RuleTerminalNodeLeftTuple(new DefaultFactHandle(1,
                                                                                                    "cheese"),
                                                                              node,
                                                                              true);
        rule.setConsequence(consequence);
        final PropagationContext context = pctxFactory.createPropagationContext(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, 0, -1);
        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, 0, -1);
        assertEquals(0,
                     agendaGroup.size());
    }
View Full Code Here

    public void testAgendaGroupLockOnActive() {
        final AbstractWorkingMemory workingMemory = (AbstractWorkingMemory) ruleBase.newStatefulSession();
        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();

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

        // 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 RuleTerminalNodeLeftTuple tuple = new RuleTerminalNodeLeftTuple(new DefaultFactHandle(1,
                                                                                                    "cheese"),
                                                                              node,
                                                                              true);

        final PropagationContext context = pctxFactory.createPropagationContext(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);
        ((InternalRuleFlowGroup) agendaGroup).setAutoDeactivate(false);
        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

        AgendaGroup[] agendaGroups = (AgendaGroup[]) agenda.getAgendaGroupsMap().values().toArray( new AgendaGroup[agenda.getAgendaGroupsMap().size()] );
        Arrays.sort( agendaGroups,
                     AgendaGroupSorter.instance );
        for ( AgendaGroup ag : agendaGroups ) {
            AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) ag;
            org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.Builder _agb = ProtobufMessages.Agenda.AgendaGroup.newBuilder();
            _agb.setName( group.getName() )
                    .setIsActive( group.isActive() )
                    .setIsAutoDeactivate( group.isAutoDeactivate() )
                    .setClearedForRecency( group.getClearedForRecency() )
                    .setHasRuleFlowLister( group.isRuleFlowListener() )
                    .setActivatedForRecency( group.getActivatedForRecency() );

            Map<Long, String> nodeInstances = group.getNodeInstances();
            for ( Map.Entry<Long, String> entry : nodeInstances.entrySet() ) {
                org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.NodeInstance.Builder _nib = ProtobufMessages.Agenda.AgendaGroup.NodeInstance.newBuilder();
                _nib.setProcessInstanceId( entry.getKey() );
                _nib.setNodeInstanceId( entry.getValue() );
                _agb.addNodeInstance( _nib.build() );
            }

            _ab.addAgendaGroup( _agb.build() );

        }

        org.drools.core.marshalling.impl.ProtobufMessages.Agenda.FocusStack.Builder _fsb = ProtobufMessages.Agenda.FocusStack.newBuilder();
        LinkedList<AgendaGroup> focusStack = agenda.getStackList();
        for ( Iterator<AgendaGroup> it = focusStack.iterator(); it.hasNext(); ) {
            AgendaGroup group = it.next();
            _fsb.addGroupName( group.getName() );
        }
        _ab.setFocusStack( _fsb.build() );

        // serialize all dormant activations
        org.drools.core.util.Iterator it = ActivationIterator.iterator( wm );
View Full Code Here

                                                                               true);

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

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

        final AgendaGroup agendaGroup2 = new AgendaGroupQueueImpl("agendaGroup2",
                                                                  kBase);
        agenda.addAgendaGroup(agendaGroup2);

        final AgendaGroup agendaGroup3 = new AgendaGroupQueueImpl("agendaGroup3",
                                                                  kBase);
        agenda.addAgendaGroup(agendaGroup3);

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

    public void testAutoFocus() throws ConsequenceException {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();
        final InternalAgenda agenda = (InternalAgenda) ksession.getAgenda();

        // create the agendaGroup
        final AgendaGroup agendaGroup = new AgendaGroupQueueImpl("agendaGroup",
                                                                 kBase);
        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";
            }
        };


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

        final RuleTerminalNodeLeftTuple tuple = new RuleTerminalNodeLeftTuple(new DefaultFactHandle(1,
                                                                                                    "cheese"),
                                                                              node,
                                                                              true);
        rule.setConsequence(consequence);
        final PropagationContext context = pctxFactory.createPropagationContext(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,
                             ksession);

        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, 0, -1);
        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,
                             ksession);

        agenda.unstageActivations();

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

    public void testAgendaGroupLockOnActive() {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();
        final InternalAgenda agenda = (InternalAgenda) ksession.getAgenda();

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

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

        final RuleTerminalNodeLeftTuple tuple = new RuleTerminalNodeLeftTuple(new DefaultFactHandle(1,
                                                                                                    "cheese"),
                                                                              node,
                                                                              true);

        final PropagationContext context = pctxFactory.createPropagationContext(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);
        ((InternalRuleFlowGroup) agendaGroup).setAutoDeactivate(false);
        agendaGroup.setActive(true);
        node.assertLeftTuple(tuple,
                             context,
                             ksession);
        // 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,
                             ksession);

        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,
                             ksession);
        agenda.unstageActivations();
        assertEquals(2,
                     agendaGroup.size());
    }
View Full Code Here

        AgendaGroup[] agendaGroups = (AgendaGroup[]) agenda.getAgendaGroupsMap().values().toArray( new AgendaGroup[agenda.getAgendaGroupsMap().size()] );
        Arrays.sort( agendaGroups,
                     AgendaGroupSorter.instance );
        for ( AgendaGroup ag : agendaGroups ) {
            AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) ag;
            org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.Builder _agb = ProtobufMessages.Agenda.AgendaGroup.newBuilder();
            _agb.setName( group.getName() )
                    .setIsActive( group.isActive() )
                    .setIsAutoDeactivate( group.isAutoDeactivate() )
                    .setClearedForRecency( group.getClearedForRecency() )
                    .setHasRuleFlowLister( group.isRuleFlowListener() )
                    .setActivatedForRecency( group.getActivatedForRecency() );

            Map<Long, String> nodeInstances = group.getNodeInstances();
            for ( Map.Entry<Long, String> entry : nodeInstances.entrySet() ) {
                org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.NodeInstance.Builder _nib = ProtobufMessages.Agenda.AgendaGroup.NodeInstance.newBuilder();
                _nib.setProcessInstanceId( entry.getKey() );
                _nib.setNodeInstanceId( entry.getValue() );
                _agb.addNodeInstance( _nib.build() );
            }

            _ab.addAgendaGroup( _agb.build() );

        }

        org.drools.core.marshalling.impl.ProtobufMessages.Agenda.FocusStack.Builder _fsb = ProtobufMessages.Agenda.FocusStack.newBuilder();
        LinkedList<AgendaGroup> focusStack = agenda.getStackList();
        for ( Iterator<AgendaGroup> it = focusStack.iterator(); it.hasNext(); ) {
            AgendaGroup group = it.next();
            _fsb.addGroupName( group.getName() );
        }
        _ab.setFocusStack( _fsb.build() );

        // serialize all dormant activations
        org.drools.core.util.Iterator it = ActivationIterator.iterator( wm );
View Full Code Here

                                  RuleData _ruleData,
                                  InternalAgenda agenda) {
        ProtobufMessages.Agenda _agenda = _ruleData.getAgenda();

        for ( org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup _agendaGroup : _agenda.getAgendaGroupList() ) {
            AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) agenda.getAgendaGroup( _agendaGroup.getName(), context.ruleBase );
            group.setActive( _agendaGroup.getIsActive() );
            group.setAutoDeactivate( _agendaGroup.getIsAutoDeactivate() );
            group.setClearedForRecency( _agendaGroup.getClearedForRecency() );
            group.hasRuleFlowListener( _agendaGroup.getHasRuleFlowLister() );
            group.setActivatedForRecency( _agendaGroup.getActivatedForRecency() );

            for ( org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.NodeInstance _nodeInstance : _agendaGroup.getNodeInstanceList() ) {
                group.addNodeInstance( _nodeInstance.getProcessInstanceId(),
                                       _nodeInstance.getNodeInstanceId() );
            }
            agenda.getAgendaGroupsMap().put( group.getName(),
                                             group );
        }

        for ( String _groupName : _agenda.getFocusStack().getGroupNameList() ) {
            agenda.addAgendaGroupOnStack( agenda.getAgendaGroup( _groupName ) );
View Full Code Here

    public static void readAgenda( MarshallerReaderContext context,
                                   InternalAgenda agenda ) throws IOException {
        ObjectInputStream stream = context.stream;

        while (stream.readShort() == PersisterEnums.AGENDA_GROUP) {
            AgendaGroupQueueImpl group = new AgendaGroupQueueImpl( stream.readUTF(),
                                                                               context.ruleBase );
            group.setActive( stream.readBoolean() );
            group.setActivatedForRecency( stream.readLong() );
            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.core.common.AgendaGroupQueueImpl

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.