Drools :: Core 6.1.0.Beta1

org.drools.core.common
Class DefaultAgenda

java.lang.Object
  extended by org.drools.core.common.DefaultAgenda
All Implemented Interfaces:
Externalizable, Serializable, InternalAgenda, org.kie.api.runtime.rule.Agenda

public class DefaultAgenda
extends Object
implements Externalizable, InternalAgenda

Rule-firing Agenda.

Since many rules may be matched by a single assertObject(...) all scheduled actions are placed into the Agenda.

While processing a scheduled action, it may update or retract objects in other scheduled actions, which must then be removed from the agenda. Non-invalidated actions are left on the agenda, and are executed in turn.

See Also:
Serialized Form

Field Summary
protected  int activationCounter
           
protected  boolean fireUntilHalt
           
protected  AtomicBoolean halt
           
protected  KnowledgeHelper knowledgeHelper
           
protected static org.slf4j.Logger log
           
protected  InternalWorkingMemory workingMemory
          Working memory of this Agenda.
 
Constructor Summary
DefaultAgenda()
           
DefaultAgenda(InternalRuleBase rb)
          Construct.
DefaultAgenda(InternalRuleBase rb, boolean initMain)
          Construct.
 
Method Summary
 void activateRuleFlowGroup(InternalRuleFlowGroup group, long processInstanceId, String nodeInstanceId)
           
 void activateRuleFlowGroup(String name)
          Activates the RuleFlowGroup with the given name.
 void activateRuleFlowGroup(String name, long processInstanceId, String nodeInstanceId)
          Activates the RuleFlowGroup with the given name.
 boolean addActivation(AgendaItem activation)
          Adds the activation to the agenda.
 void addActivation(AgendaItem item, boolean notify)
           
 void addAgendaGroup(AgendaGroup agendaGroup)
           
 void addAgendaGroupOnStack(AgendaGroup agendaGroup)
           
 void addAgendaItemToGroup(AgendaItem item)
           
 void addEagerRuleAgendaItem(RuleAgendaItem item)
           
 void addItemToActivationGroup(AgendaItem item)
          If the item belongs to an activation group, add it
 int agendaSize()
          Iterates all the modules in the focus stack returning the total number of Activations
 void cancelActivation(LeftTuple leftTuple, PropagationContext context, InternalWorkingMemory workingMemory, Activation activation, TerminalNode rtn)
           
 void clear()
           
 void clearAndCancel()
          Clears all Activations from the Agenda
 void clearAndCancelActivationGroup(ActivationGroup activationGroup)
          Clears all Activations from an Activation Group.
 void clearAndCancelActivationGroup(String name)
          Clears all Activations from an Activation-Group.
 void clearAndCancelAgendaGroup(AgendaGroup agendaGroup)
          Clears all Activations from an Agenda Group.
 void clearAndCancelAgendaGroup(String name)
          Clears all Activations from an Agenda Group.
 void clearAndCancelAndCancel(RuleFlowGroup ruleFlowGroup)
           
 void clearAndCancelRuleFlowGroup(String name)
           
 void clearAndCancelStagedActivations()
           
 boolean continueFiring(int fireLimit)
           
 boolean createActivation(LeftTuple tuple, PropagationContext context, InternalWorkingMemory workingMemory, TerminalNode rtn)
           
 AgendaItem createAgendaItem(LeftTuple tuple, int salience, PropagationContext context, TerminalNode rtn, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)
           
 boolean createPostponedActivation(LeftTuple tuple, PropagationContext context, InternalWorkingMemory workingMemory, TerminalNode rtn)
           
 RuleAgendaItem createRuleAgendaItem(int salience, PathMemory rs, TerminalNode rtn)
           
 ScheduledAgendaItem createScheduledAgendaItem(LeftTuple tuple, PropagationContext context, TerminalNode rtn, InternalAgendaGroup agendaGroup)
           
 void deactivateRuleFlowGroup(InternalRuleFlowGroup group)
           
 void deactivateRuleFlowGroup(String name)
          Deactivates the RuleFlowGroup with the given name.
 void evaluateEagerList()
           
 void fireActivation(Activation activation)
          Fire this item.
 int fireAllRules(AgendaFilter agendaFilter, int fireLimit)
          Fires all activations currently in agenda that match the given agendaFilter until the fireLimit is reached or no more activations exist.
 int fireNextItem(AgendaFilter filter, int fireCount, int fireLimit)
          Fire the next scheduled Agenda item, skipping items that are not allowed by the agenda filter.
 boolean fireTimedActivation(Activation activation, boolean saveForLater)
           
 void fireUntilHalt()
          Keeps firing activations until a halt is called.
 void fireUntilHalt(AgendaFilter agendaFilter)
          Keeps firing activations until a halt is called.
 int focusStackSize()
          Iterates all the AgendGroups in the focus stack returning the total number of Activations
 ActivationGroup getActivationGroup(String name)
           
 Map<String,ActivationGroup> getActivationGroupsMap()
           
 Activation[] getActivations()
           
 ActivationsFilter getActivationsFilter()
          Returns the current activations filter or null if none is set
 AgendaGroup getAgendaGroup(String name)
           
 AgendaGroup getAgendaGroup(String name, InternalRuleBase ruleBase)
           
 AgendaGroup[] getAgendaGroups()
           
 Map<String,InternalAgendaGroup> getAgendaGroupsMap()
           
 ConsequenceExceptionHandler getConsequenceExceptionHandler()
           
 AgendaGroup getCurrentAgendaGroup()
           
 AgendaGroup getFocus()
           
 String getFocusName()
          Returns the name of the agenda group that currently has the focus
 KnowledgeHelper getKnowledgeHelper()
           
 InternalAgendaGroup getMainAgendaGroup()
           
 long getNextActivationCounter()
           
 InternalAgendaGroup getNextFocus()
           
 RuleFlowGroup getRuleFlowGroup(String name)
           
 Activation[] getScheduledActivations()
           
 LinkedList<ScheduledAgendaItem> getScheduledActivationsLinkedList()
           
 AgendaGroup[] getStack()
           
 LinkedList<AgendaGroup> getStackList()
           
 ActivationGroup getStageActivationsGroup()
           
 WorkingMemory getWorkingMemory()
          Returns the WorkignMemory for this Agenda
 void halt()
          Stop agenda from firing any other rule.
 void insertAndStageActivation(AgendaItem activation)
           
 boolean isDeclarativeAgenda()
           
 boolean isFireUntilHalt()
           
 boolean isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, long processInstanceId)
          Returns true if there is at least one activation of the given rule name in the given ruleflow group name
 void modifyActivation(AgendaItem activation, boolean previouslyActive)
           
 void notifyHalt()
           
 RuleAgendaItem peekNextRule()
           
 void readExternal(ObjectInput in)
           
 void removeActivation(AgendaItem activation)
           
 void removeEagerRuleAgendaItem(RuleAgendaItem item)
           
 void removeScheduleItem(ScheduledAgendaItem item)
           
 void scheduleItem(ScheduledAgendaItem item, InternalWorkingMemory wm)
           
 void setActivationsFilter(ActivationsFilter filter)
          Sets a filter that prevents activations from being added to the agenda.
 void setCurrentAgendaGroup(InternalAgendaGroup agendaGroup)
           
 boolean setFocus(AgendaGroup agendaGroup)
           
 void setFocus(PropagationContext ctx, String name)
           
 void setFocus(String name)
          Sets the Agenda's focus to the specified AgendaGroup
 void setWorkingMemory(InternalWorkingMemory workingMemory)
           
 int sizeOfRuleFlowGroup(String name)
           
 void stageLeftTuple(RuleAgendaItem ruleAgendaItem, AgendaItem justified)
           
 int unstageActivations()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static transient org.slf4j.Logger log

workingMemory

protected InternalWorkingMemory workingMemory
Working memory of this Agenda.


knowledgeHelper

protected KnowledgeHelper knowledgeHelper

halt

protected AtomicBoolean halt

fireUntilHalt

protected volatile boolean fireUntilHalt

activationCounter

protected int activationCounter
Constructor Detail

DefaultAgenda

public DefaultAgenda()

DefaultAgenda

public DefaultAgenda(InternalRuleBase rb)
Construct.

Parameters:
rb - The InternalRuleBase of this agenda.

DefaultAgenda

public DefaultAgenda(InternalRuleBase rb,
                     boolean initMain)
Construct.

Parameters:
rb - The InternalRuleBase of this agenda.
initMain - Flag to initialize the MAIN agenda group
Method Detail

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

createRuleAgendaItem

public RuleAgendaItem createRuleAgendaItem(int salience,
                                           PathMemory rs,
                                           TerminalNode rtn)
Specified by:
createRuleAgendaItem in interface InternalAgenda

getNextActivationCounter

public long getNextActivationCounter()
Specified by:
getNextActivationCounter in interface InternalAgenda

createAgendaItem

public AgendaItem createAgendaItem(LeftTuple tuple,
                                   int salience,
                                   PropagationContext context,
                                   TerminalNode rtn,
                                   RuleAgendaItem ruleAgendaItem,
                                   InternalAgendaGroup agendaGroup)
Specified by:
createAgendaItem in interface InternalAgenda

createScheduledAgendaItem

public ScheduledAgendaItem createScheduledAgendaItem(LeftTuple tuple,
                                                     PropagationContext context,
                                                     TerminalNode rtn,
                                                     InternalAgendaGroup agendaGroup)
Specified by:
createScheduledAgendaItem in interface InternalAgenda

setWorkingMemory

public void setWorkingMemory(InternalWorkingMemory workingMemory)
Specified by:
setWorkingMemory in interface InternalAgenda

getWorkingMemory

public WorkingMemory getWorkingMemory()
Description copied from interface: Agenda
Returns the WorkignMemory for this Agenda

Returns:
The WorkingMemory

addEagerRuleAgendaItem

public void addEagerRuleAgendaItem(RuleAgendaItem item)
Specified by:
addEagerRuleAgendaItem in interface InternalAgenda

removeEagerRuleAgendaItem

public void removeEagerRuleAgendaItem(RuleAgendaItem item)
Specified by:
removeEagerRuleAgendaItem in interface InternalAgenda

scheduleItem

public void scheduleItem(ScheduledAgendaItem item,
                         InternalWorkingMemory wm)
Specified by:
scheduleItem in interface InternalAgenda

addItemToActivationGroup

public void addItemToActivationGroup(AgendaItem item)
If the item belongs to an activation group, add it

Specified by:
addItemToActivationGroup in interface InternalAgenda
Parameters:
item -

getStageActivationsGroup

public ActivationGroup getStageActivationsGroup()

insertAndStageActivation

public void insertAndStageActivation(AgendaItem activation)
Specified by:
insertAndStageActivation in interface InternalAgenda

addActivation

public boolean addActivation(AgendaItem activation)
Description copied from interface: InternalAgenda
Adds the activation to the agenda. Depending on the mode the agenda is running, the activation may be added to the agenda priority queue (synchronously or asynchronously) or be executed immediately.

Specified by:
addActivation in interface InternalAgenda
Returns:
true if the activation was really added, and not ignored in cases of lock-on-active or no-loop

isDeclarativeAgenda

public boolean isDeclarativeAgenda()
Specified by:
isDeclarativeAgenda in interface InternalAgenda

removeActivation

public void removeActivation(AgendaItem activation)
Specified by:
removeActivation in interface InternalAgenda

modifyActivation

public void modifyActivation(AgendaItem activation,
                             boolean previouslyActive)
Specified by:
modifyActivation in interface InternalAgenda

clearAndCancelStagedActivations

public void clearAndCancelStagedActivations()

unstageActivations

public int unstageActivations()

addActivation

public void addActivation(AgendaItem item,
                          boolean notify)

addAgendaItemToGroup

public void addAgendaItemToGroup(AgendaItem item)
Specified by:
addAgendaItemToGroup in interface InternalAgenda

removeScheduleItem

public void removeScheduleItem(ScheduledAgendaItem item)
Specified by:
removeScheduleItem in interface InternalAgenda

addAgendaGroup

public void addAgendaGroup(AgendaGroup agendaGroup)
Specified by:
addAgendaGroup in interface InternalAgenda

createActivation

public boolean createActivation(LeftTuple tuple,
                                PropagationContext context,
                                InternalWorkingMemory workingMemory,
                                TerminalNode rtn)
Specified by:
createActivation in interface InternalAgenda

createPostponedActivation

public boolean createPostponedActivation(LeftTuple tuple,
                                         PropagationContext context,
                                         InternalWorkingMemory workingMemory,
                                         TerminalNode rtn)
Specified by:
createPostponedActivation in interface InternalAgenda

cancelActivation

public void cancelActivation(LeftTuple leftTuple,
                             PropagationContext context,
                             InternalWorkingMemory workingMemory,
                             Activation activation,
                             TerminalNode rtn)
Specified by:
cancelActivation in interface InternalAgenda

setFocus

public boolean setFocus(AgendaGroup agendaGroup)
Specified by:
setFocus in interface InternalAgenda

setFocus

public void setFocus(String name)
Description copied from interface: Agenda
Sets the Agenda's focus to the specified AgendaGroup


setFocus

public void setFocus(PropagationContext ctx,
                     String name)

getFocus

public AgendaGroup getFocus()
Specified by:
getFocus in interface InternalAgenda

getNextFocus

public InternalAgendaGroup getNextFocus()
Specified by:
getNextFocus in interface InternalAgenda

peekNextRule

public RuleAgendaItem peekNextRule()
Specified by:
peekNextRule in interface InternalAgenda

setCurrentAgendaGroup

public void setCurrentAgendaGroup(InternalAgendaGroup agendaGroup)

getCurrentAgendaGroup

public AgendaGroup getCurrentAgendaGroup()

getAgendaGroup

public AgendaGroup getAgendaGroup(String name)
Specified by:
getAgendaGroup in interface InternalAgenda
Specified by:
getAgendaGroup in interface org.kie.api.runtime.rule.Agenda

getAgendaGroup

public AgendaGroup getAgendaGroup(String name,
                                  InternalRuleBase ruleBase)
Specified by:
getAgendaGroup in interface InternalAgenda

getAgendaGroups

public AgendaGroup[] getAgendaGroups()

getAgendaGroupsMap

public Map<String,InternalAgendaGroup> getAgendaGroupsMap()
Specified by:
getAgendaGroupsMap in interface InternalAgenda

getMainAgendaGroup

public InternalAgendaGroup getMainAgendaGroup()

getStack

public AgendaGroup[] getStack()

getStackList

public LinkedList<AgendaGroup> getStackList()
Specified by:
getStackList in interface InternalAgenda

addAgendaGroupOnStack

public void addAgendaGroupOnStack(AgendaGroup agendaGroup)
Specified by:
addAgendaGroupOnStack in interface InternalAgenda

getActivationGroupsMap

public Map<String,ActivationGroup> getActivationGroupsMap()
Specified by:
getActivationGroupsMap in interface InternalAgenda

getActivationGroup

public ActivationGroup getActivationGroup(String name)
Specified by:
getActivationGroup in interface InternalAgenda
Specified by:
getActivationGroup in interface org.kie.api.runtime.rule.Agenda

getRuleFlowGroup

public RuleFlowGroup getRuleFlowGroup(String name)
Specified by:
getRuleFlowGroup in interface InternalAgenda
Specified by:
getRuleFlowGroup in interface org.kie.api.runtime.rule.Agenda

activateRuleFlowGroup

public void activateRuleFlowGroup(String name)
Description copied from interface: Agenda
Activates the RuleFlowGroup with the given name. All activations in the given RuleFlowGroup are added to the agenda. As long as the RuleFlowGroup remains active, its activations are automatically added to the agenda.


activateRuleFlowGroup

public void activateRuleFlowGroup(String name,
                                  long processInstanceId,
                                  String nodeInstanceId)
Description copied from interface: Agenda
Activates the RuleFlowGroup with the given name. All activations in the given RuleFlowGroup are added to the agenda. As long as the RuleFlowGroup remains active, its activations are automatically added to the agenda. The given processInstanceId and nodeInstanceId define the process context in which this RuleFlowGroup is used.


activateRuleFlowGroup

public void activateRuleFlowGroup(InternalRuleFlowGroup group,
                                  long processInstanceId,
                                  String nodeInstanceId)

deactivateRuleFlowGroup

public void deactivateRuleFlowGroup(String name)
Description copied from interface: Agenda
Deactivates the RuleFlowGroup with the given name. All activations in the given RuleFlowGroup are removed from the agenda. As long as the RuleFlowGroup remains deactive, its activations are not added to the agenda


deactivateRuleFlowGroup

public void deactivateRuleFlowGroup(InternalRuleFlowGroup group)

focusStackSize

public int focusStackSize()
Description copied from interface: Agenda
Iterates all the AgendGroups in the focus stack returning the total number of Activations

Returns:
total number of Activations on the focus stack

agendaSize

public int agendaSize()
Description copied from interface: Agenda
Iterates all the modules in the focus stack returning the total number of Activations

Returns:
total number of activations on the focus stack

getActivations

public Activation[] getActivations()

getScheduledActivations

public Activation[] getScheduledActivations()

getScheduledActivationsLinkedList

public LinkedList<ScheduledAgendaItem> getScheduledActivationsLinkedList()
Specified by:
getScheduledActivationsLinkedList in interface InternalAgenda

clear

public void clear()
Specified by:
clear in interface InternalAgenda
Specified by:
clear in interface org.kie.api.runtime.rule.Agenda

clearAndCancel

public void clearAndCancel()
Description copied from interface: Agenda
Clears all Activations from the Agenda


clearAndCancelAgendaGroup

public void clearAndCancelAgendaGroup(String name)
Description copied from interface: Agenda
Clears all Activations from an Agenda Group. Any Activations that are also in an Xor Group are removed the the Xor Group.


clearAndCancelAgendaGroup

public void clearAndCancelAgendaGroup(AgendaGroup agendaGroup)
Description copied from interface: Agenda
Clears all Activations from an Agenda Group. Any Activations that are also in an Xor Group are removed the the Xor Group.


clearAndCancelActivationGroup

public void clearAndCancelActivationGroup(String name)
Description copied from interface: Agenda
Clears all Activations from an Activation-Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.


clearAndCancelActivationGroup

public void clearAndCancelActivationGroup(ActivationGroup activationGroup)
Description copied from interface: Agenda
Clears all Activations from an Activation Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.


clearAndCancelRuleFlowGroup

public void clearAndCancelRuleFlowGroup(String name)

clearAndCancelAndCancel

public void clearAndCancelAndCancel(RuleFlowGroup ruleFlowGroup)

fireNextItem

public int fireNextItem(AgendaFilter filter,
                        int fireCount,
                        int fireLimit)
                 throws ConsequenceException
Fire the next scheduled Agenda item, skipping items that are not allowed by the agenda filter.

Specified by:
fireNextItem in interface InternalAgenda
Returns:
true if an activation was fired. false if no more activations to fire
Throws:
ConsequenceException - If an error occurs while firing an agenda item.

evaluateEagerList

public void evaluateEagerList()
Specified by:
evaluateEagerList in interface InternalAgenda

sizeOfRuleFlowGroup

public int sizeOfRuleFlowGroup(String name)
Specified by:
sizeOfRuleFlowGroup in interface InternalAgenda

fireActivation

public void fireActivation(Activation activation)
                    throws ConsequenceException
Fire this item.

Specified by:
fireActivation in interface InternalAgenda
Parameters:
activation - The activation to fire
Throws:
ConsequenceException - If an error occurs while attempting to fire the consequence.

fireTimedActivation

public boolean fireTimedActivation(Activation activation,
                                   boolean saveForLater)
                            throws ConsequenceException
Specified by:
fireTimedActivation in interface InternalAgenda
Throws:
ConsequenceException

isRuleInstanceAgendaItem

public boolean isRuleInstanceAgendaItem(String ruleflowGroupName,
                                        String ruleName,
                                        long processInstanceId)
Description copied from interface: InternalAgenda
Returns true if there is at least one activation of the given rule name in the given ruleflow group name

Specified by:
isRuleInstanceAgendaItem in interface InternalAgenda
Returns:

getFocusName

public String getFocusName()
Description copied from interface: Agenda
Returns the name of the agenda group that currently has the focus

Returns:

isFireUntilHalt

public boolean isFireUntilHalt()
Specified by:
isFireUntilHalt in interface InternalAgenda

stageLeftTuple

public void stageLeftTuple(RuleAgendaItem ruleAgendaItem,
                           AgendaItem justified)
Specified by:
stageLeftTuple in interface InternalAgenda

fireUntilHalt

public void fireUntilHalt()
Description copied from interface: InternalAgenda
Keeps firing activations until a halt is called. If in a given moment, there is no activation to fire, it will wait for an activation to be added to an active agenda group or rule flow group.

Specified by:
fireUntilHalt in interface InternalAgenda

fireUntilHalt

public void fireUntilHalt(AgendaFilter agendaFilter)
Description copied from interface: InternalAgenda
Keeps firing activations until a halt is called. If in a given moment, there is no activation to fire, it will wait for an activation to be added to an active agenda group or rule flow group.

Specified by:
fireUntilHalt in interface InternalAgenda
Parameters:
agendaFilter - filters the activations that may fire

fireAllRules

public int fireAllRules(AgendaFilter agendaFilter,
                        int fireLimit)
Description copied from interface: InternalAgenda
Fires all activations currently in agenda that match the given agendaFilter until the fireLimit is reached or no more activations exist.

Specified by:
fireAllRules in interface InternalAgenda
Parameters:
agendaFilter - the filter on which activations may fire.
fireLimit - the maximum number of activations that may fire. If -1, then it will fire until no more activations exist.
Returns:
the number of rules that were actually fired

continueFiring

public boolean continueFiring(int fireLimit)
Specified by:
continueFiring in interface InternalAgenda

notifyHalt

public void notifyHalt()
Specified by:
notifyHalt in interface InternalAgenda

halt

public void halt()
Description copied from interface: InternalAgenda
Stop agenda from firing any other rule. It will finish the current rule execution though.

Specified by:
halt in interface InternalAgenda

getConsequenceExceptionHandler

public ConsequenceExceptionHandler getConsequenceExceptionHandler()

setActivationsFilter

public void setActivationsFilter(ActivationsFilter filter)
Description copied from interface: InternalAgenda
Sets a filter that prevents activations from being added to the agenda.

Specified by:
setActivationsFilter in interface InternalAgenda

getActivationsFilter

public ActivationsFilter getActivationsFilter()
Description copied from interface: InternalAgenda
Returns the current activations filter or null if none is set

Specified by:
getActivationsFilter in interface InternalAgenda
Returns:

getKnowledgeHelper

public KnowledgeHelper getKnowledgeHelper()

Drools :: Core 6.1.0.Beta1

Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.