Package org.drools.common

Examples of org.drools.common.InternalAgenda


    }
   
    public void testRuleFlowGroup() {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

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

        final List list = new ArrayList();

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

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                list.add( knowledgeHelper.getRule() );
            }
        };

        // create a rule for each rule flow groups
        final Rule rule0 = new Rule( "test-rule0" );
        rule0.setRuleFlowGroup( "rule-flow-group-0" );
        rule0.setConsequence( consequence );

        final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                             new MockTupleSource( 2 ),
                                                             rule0,
                                                             rule0.getLhs(),
                                                             buildContext);

        final Rule rule1 = new Rule( "test-rule1" );
        rule1.setRuleFlowGroup( "rule-flow-group-1" );
        rule1.setConsequence( consequence );

        final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                             new MockTupleSource( 2 ),
                                                             rule1,
                                                             rule1.getLhs(),
                                                             buildContext );

        final Rule rule2 = new Rule( "test-rule2" );
        rule2.setRuleFlowGroup( "rule-flow-group-2" );
        rule2.setConsequence( consequence );
        rule2.setSalience( new SalienceInteger( 10 ) );

        final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                             new MockTupleSource( 2 ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             buildContext );

        final Rule rule3 = new Rule( "test-rule3" );
        rule3.setRuleFlowGroup( "rule-flow-group-3" );
        rule3.setConsequence( consequence );

        final RuleTerminalNode node3 = new RuleTerminalNode( 6,
                                                             new MockTupleSource( 2 ),
                                                             rule3,
                                                             rule3.getLhs(),
                                                             buildContext );

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

        // nodes
        final StartNode start = new StartNodeImpl();
        final RuleSetNode ruleSet0 = new RuleSetNodeImpl();
        ruleSet0.setRuleFlowGroup( "rule-flow-group-0" );
        final RuleSetNode ruleSet1 = new RuleSetNodeImpl();
        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_AND );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_AND );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
                        ruleSet0,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet0,
                        split,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( split,
                        ruleSet1,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( split,
                        ruleSet2,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet1,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet2,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( join,
                        ruleSet3,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet3,
                        end,
                        Connection.TYPE_NORMAL );

        // process
        final RuleFlowProcess process = new RuleFlowProcessImpl();
        process.addNode( start );
        process.addNode( ruleSet0 );
        process.addNode( ruleSet1 );
        process.addNode( ruleSet2 );
        process.addNode( ruleSet3 );
        process.addNode( split );
        process.addNode( join );
        process.addNode( end );

        // proces instance
        final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstanceImpl();
        processInstance.setWorkingMemory( workingMemory );
        processInstance.setProcess( process );
        assertEquals( ProcessInstance.STATE_PENDING,
                      processInstance.getState() );

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

        final ReteTuple tuple0 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node0.assertTuple( tuple0,
                           context0,
                           workingMemory );

        final ReteTuple tuple1 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node0.assertTuple( tuple1,
                           context0,
                           workingMemory );

        final ReteTuple tuple2 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node1.assertTuple( tuple2,
                           context0,
                           workingMemory );

        final ReteTuple tuple3 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node2.assertTuple( tuple3,
                           context0,
                           workingMemory );

        final ReteTuple tuple4 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node3.assertTuple( tuple4,
                           context0,
                           workingMemory );

        // RuleFlowGroups should be populated, but the agenda shouldn't
        assertEquals( 2,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                      ruleFlowGroup2.size() );
        assertEquals( 1,
                      ruleFlowGroup3.size() );
        assertEquals( 0,
                      agenda.agendaSize() );

        // Activate process instance, the activations stay in the group,
        // but should now also be in the Agenda
        processInstance.start();
        assertEquals( ProcessInstance.STATE_ACTIVE,
                      processInstance.getState() );
        assertEquals( 2,
                      ruleFlowGroup0.size() );
        assertEquals( 2,
                      agenda.agendaSize() );

        // As we fire each rule they are removed from both the Agenda and the RuleFlowGroup
        agenda.fireNextItem( null );
        assertEquals( 1,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // on firing the last activation the child rule flow groups should
        // activate and thus repopulate the agenda
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                      ruleFlowGroup2.size() );
        assertEquals( 2,
                      agenda.agendaSize() );

        // we set the salience higher on rule2, so it sould fire first and empty ruleFlowGroup2
        agenda.fireNextItem( null );
        assertEquals( 1,
                      ruleFlowGroup1.size() );
        assertEquals( 0,
                      ruleFlowGroup2.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // executing rule1, which should activate AND-join and thus group 3
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup0.size() );
        assertEquals( 0,
                      ruleFlowGroup1.size() );
        assertEquals( 0,
                      ruleFlowGroup2.size() );
        assertEquals( 1,
                      ruleFlowGroup3.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // executing rule3, and finishing execution
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup0.size() );
        assertEquals( 0,
                      ruleFlowGroup1.size() );
        assertEquals( 0,
                      ruleFlowGroup2.size() );
        assertEquals( 0,
                      ruleFlowGroup3.size() );
        assertEquals( 0,
                      agenda.agendaSize() );
        assertEquals( ProcessInstance.STATE_COMPLETED,
                      processInstance.getState() );
    }
View Full Code Here


   
    /** XOR split and join */
    public void testRuleFlowGroup2() {
        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();

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

        final List list = new ArrayList();

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

            public void evaluate(KnowledgeHelper knowledgeHelper,
                                 WorkingMemory workingMemory) {
                list.add( knowledgeHelper.getRule() );
            }
        };

        // create a rule for each rule flow groups
        final Rule rule0 = new Rule( "test-rule0" );
        rule0.setRuleFlowGroup( "rule-flow-group-0" );
        rule0.setConsequence( consequence );

        final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                             new MockTupleSource( 2 ),
                                                             rule0,
                                                             rule0.getLhs(),
                                                             buildContext );

        final Rule rule1 = new Rule( "test-rule1" );
        rule1.setRuleFlowGroup( "rule-flow-group-1" );
        rule1.setConsequence( consequence );

        final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                             new MockTupleSource( 2 ),
                                                             rule1,
                                                             rule1.getLhs(),
                                                             buildContext );

        final Rule rule2 = new Rule( "test-rule2" );
        rule2.setRuleFlowGroup( "rule-flow-group-2" );
        rule2.setConsequence( consequence );
        rule2.setSalience( new SalienceInteger( 10 ) );

        final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                             new MockTupleSource( 2 ),
                                                             rule2,
                                                             rule2.getLhs(),
                                                             buildContext );

        final Rule rule3 = new Rule( "test-rule3" );
        rule3.setRuleFlowGroup( "rule-flow-group-3" );
        rule3.setConsequence( consequence );

        final RuleTerminalNode node3 = new RuleTerminalNode( 6,
                                                             new MockTupleSource( 2 ),
                                                             rule3,
                                                             rule3.getLhs(),
                                                             buildContext );

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

        // nodes
        final StartNode start = new StartNodeImpl();
        final RuleSetNode ruleSet0 = new RuleSetNodeImpl();
        ruleSet0.setRuleFlowGroup( "rule-flow-group-0" );
        final RuleSetNode ruleSet1 = new RuleSetNodeImpl();
        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_XOR );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_XOR );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
                        ruleSet0,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet0,
                        split,
                        Connection.TYPE_NORMAL );
        Connection out1 = new ConnectionImpl( split,
                        ruleSet1,
                        Connection.TYPE_NORMAL );
        Connection out2 = new ConnectionImpl( split,
                        ruleSet2,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet1,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet2,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( join,
                        ruleSet3,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet3,
                        end,
                        Connection.TYPE_NORMAL );
        Constraint constraint1 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint1.setPriority(1);
        split.setConstraint(out1, constraint1);
        Constraint constraint2 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint2.setPriority(2);
        split.setConstraint(out2, constraint2);

        // process
        final RuleFlowProcess process = new RuleFlowProcessImpl();
        process.setId( "1" );
        process.addNode( start );
        process.addNode( ruleSet0 );
        process.addNode( ruleSet1 );
        process.addNode( ruleSet2 );
        process.addNode( ruleSet3 );
        process.addNode( split );
        process.addNode( join );
        process.addNode( end );

        // rules for split
        final Rule splitRule1 = new Rule( "RuleFlow-Split-1-" + split.getId() + "-" + ruleSet1.getId());
        splitRule1.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule1.setConsequence( consequence );

        final RuleTerminalNode splitNode1 = new RuleTerminalNode( 7,
                                                                 new MockTupleSource( 2 ),
                                                                 splitRule1,
                                                                 splitRule1.getLhs(),
                                                                  buildContext );

        final Rule splitRule2 = new Rule( "RuleFlow-Split-1-" + split.getId() + "-" + ruleSet2.getId());
        splitRule2.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule2.setConsequence( consequence );

        final RuleTerminalNode splitNode2 = new RuleTerminalNode( 8,
                                                                 new MockTupleSource( 2 ),
                                                                 splitRule2,
                                                                 splitRule2.getLhs(),
                                                                  buildContext );

        // proces instance
        final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstanceImpl();
        processInstance.setWorkingMemory( workingMemory );
        processInstance.setProcess( process );
        assertEquals( ProcessInstance.STATE_PENDING,
                      processInstance.getState() );

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

        final ReteTuple tuple0 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node0.assertTuple( tuple0,
                           context0,
                           workingMemory );

        final ReteTuple tuple1 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node0.assertTuple( tuple1,
                           context0,
                           workingMemory );

        final ReteTuple tuple2 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node1.assertTuple( tuple2,
                           context0,
                           workingMemory );

        final ReteTuple tuple3 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node2.assertTuple( tuple3,
                           context0,
                           workingMemory );

        final ReteTuple tuple4 = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
        node3.assertTuple( tuple4,
                           context0,
                           workingMemory );

        final ReteTuple splitTuple1 = new ReteTuple( new DefaultFactHandle( 1,
                                               "cheese" ) );
    splitNode1.assertTuple( splitTuple1,
                  context0,
                  workingMemory );

        final ReteTuple splitTuple2 = new ReteTuple( new DefaultFactHandle( 1,
                                             "cheese" ) );
      splitNode2.assertTuple( splitTuple2,
                  context0,
                workingMemory );

        final RuleFlowGroupImpl systemRuleFlowGroup = (RuleFlowGroupImpl) agenda.getRuleFlowGroup( "DROOLS_SYSTEM" );
       
       

        // RuleFlowGroups should be populated, but the agenda shouldn't
        assertEquals( 2,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                      ruleFlowGroup2.size() );
        assertEquals( 1,
                      ruleFlowGroup3.size() );
        assertEquals( 2,
                      systemRuleFlowGroup.size() );
        assertEquals( 0,
                      agenda.agendaSize() );

        // Activate process instance, the activations stay in the group,
        // but should now also be in the Agenda
        processInstance.start();
        assertEquals( ProcessInstance.STATE_ACTIVE,
                      processInstance.getState() );
        assertEquals( 2,
                      ruleFlowGroup0.size() );
        assertEquals( 2,
                      agenda.agendaSize() );

        // As we fire each rule they are removed from both the Agenda and the RuleFlowGroup
        agenda.fireNextItem( null );
        assertEquals( 1,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // XOR split should activate group1
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup0.size() );
        assertEquals( 1,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                      ruleFlowGroup2.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // executing group1, XOR join should activate group3
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                    ruleFlowGroup2.size() );
        assertEquals( 1,
                    ruleFlowGroup3.size() );
        assertEquals( 1,
                      agenda.agendaSize() );

        // executing rule3, and finishing execution
        agenda.fireNextItem( null );
        workingMemory.executeQueuedActions();
        assertEquals( 0,
                      ruleFlowGroup0.size() );
        assertEquals( 0,
                      ruleFlowGroup1.size() );
        assertEquals( 1,
                      ruleFlowGroup2.size() );
        assertEquals( 0,
                      ruleFlowGroup3.size() );
        assertEquals( 0,
                      agenda.agendaSize() );
        assertEquals( ProcessInstance.STATE_COMPLETED,
                      processInstance.getState() );
    }
View Full Code Here

                                     tuple,
                                     workingMemory ) ) {
            return;
        }

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

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

        final Timer timer = this.rule.getTimer();

        if ( timer != null ) {
            final ScheduledAgendaItem item = agenda.createScheduledAgendaItem( tuple,
                                                                               context,
                                                                               this.rule,
                                                                               this.subrule );

            agenda.scheduleItem( item,
                                 workingMemory );
            tuple.setObject( item );

            item.setActivated( true );
            ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                          workingMemory );
        } else {
            if ( this.rule.getCalendars() != null ) {
                // for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
                long timestamp = workingMemory.getSessionClock().getCurrentTime();
                for ( String cal : this.rule.getCalendars() ) {
                    if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
                        return;
                    }
                }
            }
            // -----------------
            // Lazy instantiation and addition to the Agenda of AgendGroup
            // implementations
            // ----------------
            final AgendaItem item = agenda.createAgendaItem( tuple,
                                                             rule.getSalience().getValue( tuple,
                                                                                          workingMemory ),
                                                             context,
                                                             this.rule,
                                                             this.subrule );
            item.setSequenence( this.sequence );

            tuple.setObject( item );

            boolean added = agenda.addActivation( item );

            if ( added ) {
                item.setActivated( true );
                ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                              workingMemory );
            }
        }

        agenda.increaseActiveActivations();
    }
View Full Code Here

        if ( item != null && item.isActivated() ) {
            // already activated, do nothing
            return;
        }

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

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

        final Timer timer = this.rule.getTimer();

        if ( timer != null ) {
            if ( item == null ) {
                item = agenda.createScheduledAgendaItem( leftTuple,
                                                         context,
                                                         this.rule,
                                                         this.subrule );
            }
            agenda.scheduleItem( (ScheduledAgendaItem) item,
                                 workingMemory );
            item.setActivated( true );
            //            workingMemory.removeLogicalDependencies( item,
            //                                                     context,
            //                                                     this.rule );

            ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                          workingMemory );
        } else {
            if ( this.rule.getCalendars() != null ) {
                // for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
                long timestamp = workingMemory.getSessionClock().getCurrentTime();
                for ( String cal : this.rule.getCalendars() ) {
                    if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
                        return;
                    }
                }
            }

            if ( item == null ) {
                // -----------------
                // Lazy instantiation and addition to the Agenda of AgendGroup
                // implementations
                // ----------------
                item = agenda.createAgendaItem( leftTuple,
                                                rule.getSalience().getValue( leftTuple,
                                                                             workingMemory ),
                                                context,
                                                this.rule,
                                                this.subrule );
                item.setSequenence( this.sequence );
            } else {
                item.setSalience( rule.getSalience().getValue( leftTuple,
                                                               workingMemory ) ); // need to re-evaluate salience, as used fields may have changed
                item.setPropagationContext( context ); // update the Propagation Context
            }

            boolean added = agenda.addActivation( item );

            item.setActivated( added );

            if ( added ) {
                ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                              workingMemory );
            }
        }

        agenda.increaseActiveActivations();
    }
View Full Code Here

  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() + "-" +
          ((Node) instance.getNode()).getUniqueId() + "-" +
          ((Node) connection.getTo()).getId() + "-" + connection.getToType();

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

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

        final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
      
        boolean fire = ((DefaultAgenda)agenda).createActivation( leftTuple,
                                                                 context,
                                                                 workingMemory,
                                                                 this,
                                                                 false );
       
        // Can be null if no Activation was created, only add it to the agenda if it's not a control rule.
        if ( fire && !fireDirect) {
            agenda.addActivation( (AgendaItem) leftTuple.getObject() );           
        }
    }
View Full Code Here

    }
   
    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 = ((DefaultAgenda)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

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

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

        return agenda.isRuleActiveInRuleFlowGroup( "DROOLS_SYSTEM", rule );
    }
View Full Code Here

        if ( !this.rule.isEffective( tuple,
                                     workingMemory ) ) {
            return;
        }

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

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

        final Timer timer = this.rule.getTimer();

        if ( timer != null ) {
            final ScheduledAgendaItem item = agenda.createScheduledAgendaItem( tuple,
                                                                               context,
                                                                               this );

            agenda.scheduleItem( item,
                                 workingMemory );
            tuple.setObject( item );

            item.setActivated( true );
            tuple.increaseActivationCountForEvents();
            ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                          workingMemory );
        } else {
            if ( this.rule.getCalendars() != null ) {
                // for normal activations check for Calendar inclusion here, scheduled activations check on each trigger point
                long timestamp = workingMemory.getSessionClock().getCurrentTime();
                for ( String cal : this.rule.getCalendars() ) {
                    if ( !workingMemory.getCalendars().get( cal ).isTimeIncluded( timestamp ) ) {
                        return;
                    }
                }
            }
            // -----------------
            // Lazy instantiation and addition to the Agenda of AgendGroup
            // implementations
            // ----------------
            final AgendaItem item = agenda.createAgendaItem( tuple,
                                                             rule.getSalience().getValue( tuple,
                                                                                          this.rule,
                                                                                          workingMemory ),
                                                             context,
                                                             this);
            item.setSequenence( this.sequence );

            tuple.setObject( item );

            boolean added = agenda.addActivation( item );

            if ( added ) {
                item.setActivated( true );
                tuple.increaseActivationCountForEvents();
                ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                              workingMemory );
            }
        }

        agenda.increaseActiveActivations();
    }
View Full Code Here

TOP

Related Classes of org.drools.common.InternalAgenda

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.