org.drools.common
Class DefaultAgenda

java.lang.Object
  extended by org.drools.common.DefaultAgenda
All Implemented Interfaces:
Externalizable, Serializable, InternalAgenda, org.drools.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
 int activeActivations
           
 int dormantActivations
           
protected  AtomicBoolean halt
           
 
Constructor Summary
DefaultAgenda()
           
DefaultAgenda(InternalRuleBase rb)
          Construct.
DefaultAgenda(InternalRuleBase rb, boolean initMain)
          Construct.
 
Method Summary
 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 addAgendaGroup(AgendaGroup agendaGroup)
           
 void addRuleFlowGroupListener(String ruleFlowGroup, RuleFlowGroupListener listener)
          Adds a RuleFlowGroupListerner to the named RuleFlowGroup
 int agendaSize()
          Iterates all the modules in the focus stack returning the total number of Activations
 void clear()
           
 void clearAndCancel()
          (non-Javadoc)
 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)
           
 AgendaItem createAgendaItem(LeftTuple tuple, int salience, PropagationContext context, RuleTerminalNode rtn)
           
 ScheduledAgendaItem createScheduledAgendaItem(LeftTuple tuple, PropagationContext context, RuleTerminalNode rtn)
           
 void deactivateRuleFlowGroup(String name)
          Deactivates the RuleFlowGroup with the given name.
 void decreaseActiveActivations()
           
 void decreaseDormantActivations()
           
 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.
 boolean fireNextItem(AgendaFilter filter)
          Fire the next scheduled Agenda item, skipping items that are not allowed by the agenda filter.
 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()
           
 int getActiveActivations()
           
 AgendaGroup getAgendaGroup(String name)
           
 AgendaGroup[] getAgendaGroups()
           
 Map<String,InternalAgendaGroup> getAgendaGroupsMap()
           
 ConsequenceExceptionHandler getConsequenceExceptionHandler()
           
 AgendaGroup getCurrentAgendaGroup()
           
 int getDormantActivations()
           
 AgendaGroup getFocus()
           
 String getFocusName()
          Returns the name of the agenda group that currently has the focus
 InternalAgendaGroup getMainAgendaGroup()
           
 AgendaGroup getNextFocus()
           
 RuleFlowGroup getRuleFlowGroup(String name)
           
 Map<String,RuleFlowGroup> getRuleFlowGroupsMap()
           
 Activation[] getScheduledActivations()
           
 LinkedList getScheduledActivationsLinkedList()
           
 AgendaGroup[] getStack()
           
 LinkedList<AgendaGroup> getStackList()
           
 WorkingMemory getWorkingMemory()
          Returns the WorkignMemory for this Agenda
 void halt()
          Stop agenda from firing any other rule.
 void increaseActiveActivations()
           
 void increaseDormantActivations()
           
 boolean isRuleActiveInRuleFlowGroup(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 notifyHalt()
           
 void readExternal(ObjectInput in)
           
 void removeRuleFlowGroupListener(String ruleFlowGroup, RuleFlowGroupListener listener)
          Removes the given RuleFlowGroupListener from the list of listeners of the named RuleFlowGroup
 void removeScheduleItem(ScheduledAgendaItem item)
           
 void scheduleItem(ScheduledAgendaItem item, InternalWorkingMemory wm)
          Schedule an agenda item for delayed firing.
 void setCurrentAgendaGroup(InternalAgendaGroup agendaGroup)
           
 boolean setFocus(AgendaGroup agendaGroup)
           
 void setFocus(String name)
          Sets the Agenda's focus to the specified AgendaGroup
 void setWorkingMemory(InternalWorkingMemory workingMemory)
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeActivations

public int activeActivations

dormantActivations

public int dormantActivations

halt

protected volatile AtomicBoolean halt
Constructor Detail

DefaultAgenda

public DefaultAgenda()

DefaultAgenda

public DefaultAgenda(InternalRuleBase rb)
Construct.

Parameters:
workingMemory - The WorkingMemory of this agenda.
conflictResolver - The conflict resolver.

DefaultAgenda

public DefaultAgenda(InternalRuleBase rb,
                     boolean initMain)
Construct.

Parameters:
workingMemory - The WorkingMemory of this agenda.
conflictResolver - The conflict resolver.
Method Detail

createAgendaItem

public AgendaItem createAgendaItem(LeftTuple tuple,
                                   int salience,
                                   PropagationContext context,
                                   RuleTerminalNode rtn)
Specified by:
createAgendaItem in interface InternalAgenda

createScheduledAgendaItem

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

setWorkingMemory

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

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

getWorkingMemory

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

Returns:
The WorkingMemory

scheduleItem

public void scheduleItem(ScheduledAgendaItem item,
                         InternalWorkingMemory wm)
Schedule an agenda item for delayed firing.

Specified by:
scheduleItem in interface InternalAgenda
Parameters:
item - The item to schedule.

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

removeScheduleItem

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

addAgendaGroup

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

setFocus

public boolean setFocus(AgendaGroup agendaGroup)

setFocus

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


getFocus

public AgendaGroup getFocus()

getNextFocus

public AgendaGroup getNextFocus()

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.drools.runtime.rule.Agenda

getAgendaGroups

public AgendaGroup[] getAgendaGroups()

getAgendaGroupsMap

public Map<String,InternalAgendaGroup> getAgendaGroupsMap()

getMainAgendaGroup

public InternalAgendaGroup getMainAgendaGroup()

getStack

public AgendaGroup[] getStack()

getStackList

public LinkedList<AgendaGroup> getStackList()

getRuleFlowGroupsMap

public Map<String,RuleFlowGroup> getRuleFlowGroupsMap()

getActivationGroupsMap

public Map<String,ActivationGroup> getActivationGroupsMap()

getActivationGroup

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

getRuleFlowGroup

public RuleFlowGroup getRuleFlowGroup(String name)
Specified by:
getRuleFlowGroup in interface InternalAgenda
Specified by:
getRuleFlowGroup in interface org.drools.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.


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


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 getScheduledActivationsLinkedList()
Specified by:
getScheduledActivationsLinkedList in interface InternalAgenda

clear

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

clearAndCancel

public void clearAndCancel()
(non-Javadoc)

See Also:
org.drools.common.AgendaI#clearAgenda()

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 boolean fireNextItem(AgendaFilter filter)
                     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.

fireActivation

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

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

increaseActiveActivations

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

decreaseActiveActivations

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

increaseDormantActivations

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

decreaseDormantActivations

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

getActiveActivations

public int getActiveActivations()
Specified by:
getActiveActivations in interface InternalAgenda

getDormantActivations

public int getDormantActivations()
Specified by:
getDormantActivations in interface InternalAgenda

isRuleActiveInRuleFlowGroup

public boolean isRuleActiveInRuleFlowGroup(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:
isRuleActiveInRuleFlowGroup in interface InternalAgenda
Returns:

addRuleFlowGroupListener

public void addRuleFlowGroupListener(String ruleFlowGroup,
                                     RuleFlowGroupListener listener)
Description copied from interface: InternalAgenda
Adds a RuleFlowGroupListerner to the named RuleFlowGroup

Specified by:
addRuleFlowGroupListener in interface InternalAgenda

removeRuleFlowGroupListener

public void removeRuleFlowGroupListener(String ruleFlowGroup,
                                        RuleFlowGroupListener listener)
Description copied from interface: InternalAgenda
Removes the given RuleFlowGroupListener from the list of listeners of the named RuleFlowGroup

Specified by:
removeRuleFlowGroupListener in interface InternalAgenda

getFocusName

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

Returns:

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

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


Copyright © 2001-2013 JBoss Inc.. All Rights Reserved.