Package org.drools.common

Examples of org.drools.common.AgendaItem


            // set the focus if rule autoFocus is true
            if ( this.rule.getAutoFocus() ) {
                agenda.setFocus( agendaGroup );
            }

            final AgendaItem item = new AgendaItem( context.getPropagationNumber(),
                                                    cloned,
                                                    rule.getSalience().getValue( tuple, workingMemory ),
                                                    context,
                                                    this.rule,
                                                    this.subrule );
           
            if ( this.tupleMemoryEnabled ) {
                item.setSequenence( this.sequence );
            }

            if ( this.rule.getActivationGroup() != null ) {
                // Lazy cache activationGroup
                if ( memory.getActivationGroup() == null ) {
                    memory.setActivationGroup( workingMemory.getAgenda().getActivationGroup( this.rule.getActivationGroup() ) );
                }
                memory.getActivationGroup().addActivation( item );
            }

            item.setAgendaGroup( agendaGroup );
            if ( this.rule.getRuleFlowGroup() == null ) {
                // No RuleFlowNode so add  it directly to  the Agenda

                // do not add the activation if the rule is "lock-on-active" and the AgendaGroup is active
                // we must check the context to determine if its a new tuple or an exist re-activated tuple as part of the retract               
                if ( context.getType() == PropagationContext.MODIFICATION ) {
                    if ( this.rule.isLockOnActive() && agendaGroup.isActive() ) {
                        Activation justifier = context.removeRetractedTuple( this.rule,
                                                                             tuple );
                        if ( justifier == null ) {
                            // This rule is locked and active, do not allow new tuples to activate
                            return;
                        } else if ( this.rule.hasLogicalDependency() ) {
                            copyLogicalDependencies( context,
                                                     workingMemory,
                                                     item,
                                                     justifier );
                        }
                    } else if ( this.rule.hasLogicalDependency() ) {
                        Activation justifier = context.removeRetractedTuple( this.rule,
                                                                             tuple );
                        copyLogicalDependencies( context,
                                                 workingMemory,
                                                 item,
                                                 justifier );
                    }
                } else if ( this.rule.isLockOnActive() && agendaGroup.isActive() ) {
                    return;
                }

                agendaGroup.add( item );
            } else {
                //There is  a RuleFlowNode so add it there, instead  of the Agenda
                RuleFlowGroup rfg = memory.getRuleFlowGroup();
                // Lazy cache ruleFlowGroup
                if ( rfg == null ) {
                    rfg = workingMemory.getAgenda().getRuleFlowGroup( this.rule.getRuleFlowGroup() );
                    memory.setRuleFlowGroup( rfg );
                }

                // do not add the activation if the rule is "lock-on-active" and the RuleFlowGroup is active
                // we must check the context to determine if its a new tuple or an exist re-activated tuple as part of the retract               
                if ( context.getType() == PropagationContext.MODIFICATION ) {
                    if ( this.rule.isLockOnActive() && rfg.isActive() ) {
                        Activation justifier = context.removeRetractedTuple( this.rule,
                                                                             tuple );
                        if ( justifier == null ) {
                            // This rule is locked and active, do not allow new tuples to activate
                            return;
                        } else if ( this.rule.hasLogicalDependency() ) {
                            copyLogicalDependencies( context,
                                                     workingMemory,
                                                     item,
                                                     justifier );
                        }
                    } else if ( this.rule.hasLogicalDependency() ) {
                        Activation justifier = context.removeRetractedTuple( this.rule,
                                                                             tuple );
                        copyLogicalDependencies( context,
                                                 workingMemory,
                                                 item,
                                                 justifier );
                    }
                } else if ( this.rule.isLockOnActive() && rfg.isActive() ) {
                    return;
                }

                ((InternalRuleFlowGroup) memory.getRuleFlowGroup()).addActivation( item );

            }

            tuple.setActivation( item );
            memory.getTupleMemory().add( tuple );

            item.setActivated( true );

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


    public LinkedList<LogicalDependency> getpreviousJustified() {
        return previousJustified;
    }
   
    public void blockMatch(Match act) {
        AgendaItem targetMatch = ( AgendaItem ) act;
        // iterate to find previous equal logical insertion
        LogicalDependency dep = null;
        if ( this.previousJustified != null ) {
            for ( dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext() ) {
                if ( targetMatch ==  dep.getJustified() ) {
                    this.previousJustified.remove( dep );
                    break;
                }
            }
        }
       
        if ( dep == null ) {
            dep = new SimpleLogicalDependency( activation, targetMatch );
        }
        this.activation.addBlockeddep );
       
        if ( targetMatch.getBlockers().size() == 1 && targetMatch.isActive()  ) {
            // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed.
            targetMatch.remove();

            if ( targetMatch.getActivationGroupNode() != null ) {
                targetMatch.getActivationGroupNode().getActivationGroup().removeActivation( targetMatch );
            }

            if ( targetMatch.getActivationNode() != null ) {
                final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer();
                ruleFlowGroup.removeActivation( targetMatch );
            }
        }
    }
View Full Code Here

            }
        }
    }
   
    public void unblockAllMatches(Match act) {
        AgendaItem targetMatch = ( AgendaItem ) act;
        boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty() );
       
        for ( LinkedListEntry entry = ( LinkedListEntry ) targetMatch.getBlockers().getFirst(); entry != null) {
            LinkedListEntry tmp = ( LinkedListEntry ) entry.getNext();
            LogicalDependency dep = ( LogicalDependency ) entry.getObject();
            ((AgendaItem)dep.getJustifier()).removeBlocked( dep );
            entry = tmp;
        }
View Full Code Here

        if ( this.previousBlocked != null ) {
            for ( LogicalDependency dep = this.previousBlocked.getFirst(); dep != null; ) {
                LogicalDependency tmp = dep.getNext();
                this.previousBlocked.remove( dep );
               
                AgendaItem justified = ( AgendaItem ) dep.getJustified();
                justified.getBlockers().remove( dep.getJustifierEntry() );
                if (justified.getBlockers().isEmpty() ) {
                    // the match is no longer blocked, so stage it
                    ((DefaultAgenda)workingMemory.getAgenda()).getStageActivationsGroup().addActivation( justified );
                }
                dep = tmp;
            }
View Full Code Here

            }
        }       
    }
   
    public void cancelMatch(Match act) {
        AgendaItem match = ( AgendaItem ) act;
        match.cancel();
        if ( match.isActive() ) {
            LeftTuple leftTuple = match.getTuple();
            leftTuple.getLeftTupleSink().retractLeftTuple( leftTuple, (PropagationContext) act.getPropagationContext(), workingMemory );
        }
    }
View Full Code Here

    protected <T> T doInsertTrait( T thing, boolean logical ) {
        FactHandle fh = insert( thing );
       
        if ( logical ) {
            AgendaItem agendaItem = ( AgendaItem ) activation;
           
            RetractTrait newUnMatch = new RetractTrait(fh);
            ActivationUnMatchListener unmatch = agendaItem.getActivationUnMatchListener();
            if ( unmatch != null ) {
                newUnMatch.setNext( ( RetractTrait ) unmatch );
            }
            agendaItem.setActivationUnMatchListener( newUnMatch );
        }
        return thing;
    }
View Full Code Here

            }
            // -----------------
            // 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 );
                ((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCreated( item,
                                                                                              workingMemory );
            }
        }
View Full Code Here

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

        AgendaItem item = (AgendaItem) leftTuple.getObject();
        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 );
            }
            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,
                                                                             this.rule,
                                                                             workingMemory ),
                                                context,
                                                this  );
                item.setSequenence( this.sequence );
            } else {
                item.setSalience( rule.getSalience().getValue( leftTuple,
                                                               this.rule,
                                                               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 );
            }
View Full Code Here

        RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) leftTuple.getLeftTupleSink();

        PropagationContext pc = context.propagationContexts.get( stream.readLong() );

        AgendaItem activation = new AgendaItem( activationNumber,
                                                leftTuple,
                                                salience,
                                                pc,
                                                ruleTerminalNode );

        leftTuple.setObject( activation );

        if ( stream.readBoolean() ) {
            String activationGroupName = stream.readUTF();
            ((DefaultAgenda) wm.getAgenda()).getActivationGroup( activationGroupName ).addActivation( activation );
        }

        boolean activated = stream.readBoolean();
        activation.setActivated( activated );

        InternalAgendaGroup agendaGroup;
        if ( rule.getAgendaGroup() == null || rule.getAgendaGroup().equals( "" ) || rule.getAgendaGroup().equals( AgendaGroup.MAIN ) ) {
            // Is the Rule AgendaGroup undefined? If it is use MAIN,
            // which is added to the Agenda by default
            agendaGroup = (InternalAgendaGroup) ((DefaultAgenda) wm.getAgenda()).getAgendaGroup( AgendaGroup.MAIN );
        } else {
            // AgendaGroup is defined, so try and get the AgendaGroup
            // from the Agenda
            agendaGroup = (InternalAgendaGroup) ((DefaultAgenda) wm.getAgenda()).getAgendaGroup( rule.getAgendaGroup() );
        }

        activation.setAgendaGroup( agendaGroup );

        if ( activated ) {
            if ( rule.getRuleFlowGroup() == null ) {
                agendaGroup.add( activation );
            } else {
View Full Code Here

        final LeftTupleImpl tuple = new LeftTupleImpl( f0,
                                               sink,
                                               true );
       

        final AgendaItem item = new AgendaItem( 0,
                                                tuple,
                                                10,
                                                new PropagationContextImpl( 1,
                                                                            1,
                                                                            null,
View Full Code Here

TOP

Related Classes of org.drools.common.AgendaItem

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.