Examples of InternalAgenda


Examples of org.drools.common.InternalAgenda

    }

    //
    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

Examples of org.drools.common.InternalAgenda

    public void testAgendaGroupLockOnActive() {
        final InternalRuleBase ruleBase = (InternalRuleBase) RuleBaseFactory.newRuleBase();

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

Examples of org.drools.common.InternalAgenda

        //we only have to clone the head fact to make sure the graph is not affected during consequence reads after a modify
        // @FIXME
        final LeftTuple cloned = tuple;//new LeftTuple( tuple );

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

        final Duration dur = this.rule.getDuration();

        if ( dur != null && dur.getDuration( tuple ) > 0 ) {
            final ScheduledAgendaItem item = new ScheduledAgendaItem( context.getPropagationNumber(),
                                                                      cloned,
                                                                      agenda,
                                                                      context,
                                                                      this.rule,
                                                                      this.subrule );
            final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );

            agenda.scheduleItem( item );
            tuple.setActivation( item );

            if ( this.tupleMemoryEnabled ) {
                memory.getTupleMemory().add( tuple );
            }

            item.setActivated( true );
            ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                          workingMemory );
        } else {
            // -----------------
            // Lazy instantiation and addition to the Agenda of AgendGroup
            // implementations
            // ----------------
            final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );

            final AgendaItem item = new AgendaItem( context.getPropagationNumber(),
                                                    cloned,
                                                    rule.getSalience().getValue( tuple,
                                                                                 workingMemory ),
                                                    context,
                                                    this.rule,
                                                    this.subrule );

            item.setSequenence( this.sequence );

            tuple.setActivation( item );
            memory.getTupleMemory().add( tuple );
           
            boolean added = agenda.addActivation( item );

            item.setActivated( added );

            // We only want to fire an event on a truly new Activation and not on an Activation as a result of a modify
            if ( added && fireActivationCreated ) {
                ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                              workingMemory );
            }
        }

        agenda.increaseActiveActivations();
    }
View Full Code Here

Examples of org.drools.common.InternalAgenda

                                                            rule1.getLhs(),
                                                            0,
                                                            buildContext );
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

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

        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";
            }
        };

        rule1.setConsequence( consequence );

        final DefaultFactHandle handle1 = (DefaultFactHandle) workingMemory.insert( "o1" );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( handle1,
                                                null,
                                                true );

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

        // Test single activation for a single logical assertions
        node.assertLeftTuple( tuple1,
                              context1,
                              workingMemory );

        final String logicalString = new String( "logical" );
        InternalFactHandle logicalHandle = (InternalFactHandle) workingMemory.insert( logicalString,
                                                                                      false,
                                                                                      true,
                                                                                      rule1,
                                                                                      (Activation)tuple1.getObject() );
        new RightTuple( logicalHandle,
                        sink );
        // Retract the tuple and test the logically asserted fact was also retracted
        node.retractLeftTuple( tuple1,
                               context1,
                               workingMemory );

        workingMemory.executeQueuedActions();

        assertLength( 1,
                      sink.getRetracted() );

        Object[] values = (Object[]) sink.getRetracted().get( 0 );

        assertSame( logicalHandle,
                    ((RightTuple) values[0]).getFactHandle() );

        // Test single activation for a single logical assertions. This also
        // tests that logical assertions live on after the related Activation
        // has fired.
        node.assertLeftTuple( tuple1,
                              context1,
                              workingMemory );
        logicalHandle = (InternalFactHandle) workingMemory.insert( logicalString,
                                                                   false,
                                                                   true,
                                                                   rule1,
                                                                   (Activation)tuple1.getObject() );

        new RightTuple( logicalHandle,
                        sink );

        agenda.fireNextItem( null );

        node.retractLeftTuple( tuple1,
                               context1,
                               workingMemory );
View Full Code Here

Examples of org.drools.common.InternalAgenda

    //
    @Test
    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

Examples of org.drools.common.InternalAgenda

    @Test
    public void testAgendaGroupLockOnActive() {
        final InternalRuleBase ruleBase = (InternalRuleBase) RuleBaseFactory.newRuleBase();

        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

Examples of org.drools.common.InternalAgenda

   
    public boolean evaluate(SplitInstance instance,
                            Connection connection,
                            Constraint constraint) {
        WorkflowProcessInstance processInstance = instance.getProcessInstance();
        InternalAgenda agenda = (InternalAgenda) ((ProcessInstance) processInstance).getAgenda();
        String rule = "RuleFlow-Split-" + processInstance.getProcessId() + "-" + instance.getNode().getId() + "-" + connection.getTo().getId();

        boolean isActive = agenda.isRuleActiveInRuleFlowGroup( "DROOLS_SYSTEM", rule, processInstance.getId() );
        return isActive;
    }
View Full Code Here

Examples of org.drools.common.InternalAgenda

             (this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() )) ||
             ( context.getReaderContext() == null && leftTuple.isExpired()) ) {
            return;
        }

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

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

Examples of org.drools.common.InternalAgenda

    }

    public void modifyLeftTuple(LeftTuple leftTuple,
                                PropagationContext context,
                                InternalWorkingMemory workingMemory) {
        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;
            }
        }

        // if the current Rule is no-loop and the origin rule is the same then return
        if ( this.rule.isNoLoop() && this.rule.equals( context.getRuleOrigin() ) ) {
            agenda.increaseDormantActivations();
            return;
        }

        boolean reuseActivation = true;
        if ( o  == Boolean.TRUE ) {
            // set to Boolean.TRUE when lock-on-active stops an Activation being created
            // We set this instead of doing a null check, as it's a little safer due to intent.
            reuseActivation = false;
            leftTuple.setObject( null );
        }
        boolean fire = agenda.createActivation( leftTuple, context, workingMemory, this, reuseActivation );
        if ( fire && !isFireDirect() ) {
            // This activation is currently dormant and about to reactivated, so decrease the dormant count.
            agenda.decreaseDormantActivations();

            agenda.modifyActivation( (AgendaItem) leftTuple.getObject(), false );
        }
    }
View Full Code Here

Examples of org.drools.common.InternalAgenda

            return;
        }

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

        agenda.cancelActivation( leftTuple,
                                 context,
                                 workingMemory,
                                 activation,
                                 this );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.