Package org.drools.core.common
Class DefaultAgenda
- java.lang.Object
-
- org.drools.core.common.DefaultAgenda
-
- All Implemented Interfaces:
Externalizable,Serializable,InternalAgenda,org.kie.api.runtime.rule.Agenda
- Direct Known Subclasses:
PartitionedDefaultAgenda
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
Fields Modifier and Type Field Description protected intactivationCounterprotected static org.slf4j.Loggerlogstatic StringON_AFTER_ALL_FIRES_CONSEQUENCE_NAMEstatic StringON_BEFORE_ALL_FIRES_CONSEQUENCE_NAMEstatic StringON_DELETE_MATCH_CONSEQUENCE_NAMEprotected InternalWorkingMemoryworkingMemoryWorking memory of this Agenda.
-
Constructor Summary
Constructors Constructor Description DefaultAgenda()DefaultAgenda(InternalKnowledgeBase kBase)DefaultAgenda(InternalKnowledgeBase kBase, boolean initMain)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate()voidactivateRuleFlowGroup(String name)Activates theRuleFlowGroupwith the given name.voidactivateRuleFlowGroup(String name, long processInstanceId, String nodeInstanceId)Activates theRuleFlowGroupwith the given name.voidactivateRuleFlowGroup(InternalRuleFlowGroup group, Object processInstanceId, String nodeInstanceId)voidaddAgendaGroupOnStack(AgendaGroup agendaGroup)voidaddEagerRuleAgendaItem(RuleAgendaItem item)voidaddItemToActivationGroup(AgendaItem item)If the item belongs to an activation group, add itvoidaddPropagation(PropagationEntry propagationEntry)voidaddQueryAgendaItem(RuleAgendaItem item)intagendaSize()Iterates all the modules in the focus stack returning the total number ofActivationsvoidcancelActivation(Activation activation)voidclear()voidclearAndCancel()Clears all Activations from the AgendavoidclearAndCancelActivationGroup(String name)Clears all Activations from an Activation-Group.voidclearAndCancelActivationGroup(InternalActivationGroup activationGroup)Clears all Activations from an Activation Group.voidclearAndCancelAgendaGroup(String name)Clears all Activations from an Agenda Group.voidclearAndCancelRuleFlowGroup(String name)AgendaItemcreateAgendaItem(RuleTerminalNodeLeftTuple rtnLeftTuple, int salience, PropagationContext context, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)RuleAgendaItemcreateRuleAgendaItem(int salience, PathMemory rs, TerminalNode rtn)voiddeactivate()voiddeactivateRuleFlowGroup(String name)Deactivates theRuleFlowGroupwith the given name.booleandispose(InternalWorkingMemory wm)protected voiddoRetract(PropagationContext ectx)voidevaluateEagerList()voidevaluateQueriesForRule(RuleAgendaItem item)voidexecuteFlush()voidexecuteTask(ExecutableEntry executable)intfireAllRules(org.kie.api.runtime.rule.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.intfireNextItem(org.kie.api.runtime.rule.AgendaFilter filter, int fireCount, int fireLimit)Fire the next scheduledAgendaitem, skipping items that are not allowed by the agenda filter.voidfireUntilHalt()Keeps firing activations until a halt is called.voidfireUntilHalt(org.kie.api.runtime.rule.AgendaFilter agendaFilter)Keeps firing activations until a halt is called.voidflushPropagations()intfocusStackSize()Iterates all theAgendGroups in the focus stack returning the total number ofActivationsIterator<PropagationEntry>getActionsIterator()InternalActivationGroupgetActivationGroup(String name)Map<String,InternalActivationGroup>getActivationGroupsMap()Activation[]getActivations()ActivationsFiltergetActivationsFilter()Returns the current activations filter or null if none is setAgendaGroupgetAgendaGroup(String name)AgendaGroupgetAgendaGroup(String name, InternalKnowledgeBase kBase)AgendaGroup[]getAgendaGroups()Map<String,InternalAgendaGroup>getAgendaGroupsMap()StringgetFocusName()Returns the name of the agenda group that currently has the focusCollection<String>getGroupsName()KnowledgeHelpergetKnowledgeHelper()InternalAgendaGroupgetNextFocus()PropagationListgetPropagationList()RuleFlowGroupgetRuleFlowGroup(String name)InternalWorkingMemorygetWorkingMemory()Returns the WorkignMemory for this Agendavoidhalt()Stop agenda from firing any other rule.voidhandleException(InternalWorkingMemory wm, Activation activation, Exception e)booleanhasPendingPropagations()voidinsertAndStageActivation(AgendaItem activation)voidinternalHalt()booleanisAlive()booleanisDeclarativeAgenda()booleanisFiring()booleanisParallelAgenda()booleanisRuleActiveInRuleFlowGroup(String ruleflowGroupName, String ruleName, long processInstanceId)booleanisRuleInstanceAgendaItem(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 nameprotected booleanisRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, Object processInstanceId)voidmodifyActivation(AgendaItem activation, boolean previouslyActive)Adds the activation to the agenda.voidnotifyWaitOnRest()RuleAgendaItempeekNextRule()voidputOnAgendaGroupsMap(String name, InternalAgendaGroup group)voidreadExternal(ObjectInput in)voidregisterExpiration(PropagationContext ectx)voidremoveAgendaGroup(String name)voidremoveEagerRuleAgendaItem(RuleAgendaItem item)voidremoveQueryAgendaItem(RuleAgendaItem item)voidreset()protected booleansameProcessInstance(Object processInstanceId, org.kie.api.runtime.process.ProcessInstance value)voidsetActivationsFilter(ActivationsFilter filter)Sets a filter that prevents activations from being added to the agenda.voidsetFocus(String name)Sets the Agenda's focus to the specified AgendaGroupbooleansetFocus(AgendaGroup agendaGroup)voidsetFocus(PropagationContext ctx, String name)voidsetWorkingMemory(InternalWorkingMemory workingMemory)intsizeOfRuleFlowGroup(String name)voidstageLeftTuple(RuleAgendaItem ruleAgendaItem, AgendaItem justified)booleantryDeactivate()voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
ON_BEFORE_ALL_FIRES_CONSEQUENCE_NAME
public static final String ON_BEFORE_ALL_FIRES_CONSEQUENCE_NAME
- See Also:
- Constant Field Values
-
ON_AFTER_ALL_FIRES_CONSEQUENCE_NAME
public static final String ON_AFTER_ALL_FIRES_CONSEQUENCE_NAME
- See Also:
- Constant Field Values
-
ON_DELETE_MATCH_CONSEQUENCE_NAME
public static final String ON_DELETE_MATCH_CONSEQUENCE_NAME
- See Also:
- Constant Field Values
-
log
protected static final transient org.slf4j.Logger log
-
workingMemory
protected InternalWorkingMemory workingMemory
Working memory of this Agenda.
-
activationCounter
protected int activationCounter
-
-
Constructor Detail
-
DefaultAgenda
public DefaultAgenda()
-
DefaultAgenda
public DefaultAgenda(InternalKnowledgeBase kBase)
-
DefaultAgenda
public DefaultAgenda(InternalKnowledgeBase kBase, boolean initMain)
-
-
Method Detail
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
createRuleAgendaItem
public RuleAgendaItem createRuleAgendaItem(int salience, PathMemory rs, TerminalNode rtn)
- Specified by:
createRuleAgendaItemin interfaceInternalAgenda
-
createAgendaItem
public AgendaItem createAgendaItem(RuleTerminalNodeLeftTuple rtnLeftTuple, int salience, PropagationContext context, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)
- Specified by:
createAgendaItemin interfaceInternalAgenda
-
setWorkingMemory
public void setWorkingMemory(InternalWorkingMemory workingMemory)
- Specified by:
setWorkingMemoryin interfaceInternalAgenda
-
getPropagationList
public PropagationList getPropagationList()
- Specified by:
getPropagationListin interfaceInternalAgenda
-
getWorkingMemory
public InternalWorkingMemory getWorkingMemory()
Description copied from interface:InternalAgendaReturns the WorkignMemory for this Agenda- Specified by:
getWorkingMemoryin interfaceInternalAgenda- Returns:
- The WorkingMemory
-
addEagerRuleAgendaItem
public void addEagerRuleAgendaItem(RuleAgendaItem item)
- Specified by:
addEagerRuleAgendaItemin interfaceInternalAgenda
-
removeEagerRuleAgendaItem
public void removeEagerRuleAgendaItem(RuleAgendaItem item)
- Specified by:
removeEagerRuleAgendaItemin interfaceInternalAgenda
-
addQueryAgendaItem
public void addQueryAgendaItem(RuleAgendaItem item)
- Specified by:
addQueryAgendaItemin interfaceInternalAgenda
-
removeQueryAgendaItem
public void removeQueryAgendaItem(RuleAgendaItem item)
- Specified by:
removeQueryAgendaItemin interfaceInternalAgenda
-
addItemToActivationGroup
public void addItemToActivationGroup(AgendaItem item)
If the item belongs to an activation group, add it- Specified by:
addItemToActivationGroupin interfaceInternalAgenda- Parameters:
item-
-
insertAndStageActivation
public void insertAndStageActivation(AgendaItem activation)
- Specified by:
insertAndStageActivationin interfaceInternalAgenda
-
isDeclarativeAgenda
public boolean isDeclarativeAgenda()
- Specified by:
isDeclarativeAgendain interfaceInternalAgenda
-
modifyActivation
public void modifyActivation(AgendaItem activation, boolean previouslyActive)
Description copied from interface:InternalAgendaAdds 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:
modifyActivationin interfaceInternalAgenda
-
isRuleActiveInRuleFlowGroup
public boolean isRuleActiveInRuleFlowGroup(String ruleflowGroupName, String ruleName, long processInstanceId)
- Specified by:
isRuleActiveInRuleFlowGroupin interfaceInternalAgenda
-
cancelActivation
public void cancelActivation(Activation activation)
- Specified by:
cancelActivationin interfaceInternalAgenda
-
setFocus
public boolean setFocus(AgendaGroup agendaGroup)
- Specified by:
setFocusin interfaceInternalAgenda
-
setFocus
public void setFocus(String name)
Description copied from interface:InternalAgendaSets the Agenda's focus to the specified AgendaGroup- Specified by:
setFocusin interfaceInternalAgenda
-
setFocus
public void setFocus(PropagationContext ctx, String name)
-
getNextFocus
public InternalAgendaGroup getNextFocus()
- Specified by:
getNextFocusin interfaceInternalAgenda
-
peekNextRule
public RuleAgendaItem peekNextRule()
- Specified by:
peekNextRulein interfaceInternalAgenda
-
getAgendaGroup
public AgendaGroup getAgendaGroup(String name)
- Specified by:
getAgendaGroupin interfaceorg.kie.api.runtime.rule.Agenda- Specified by:
getAgendaGroupin interfaceInternalAgenda
-
removeAgendaGroup
public void removeAgendaGroup(String name)
- Specified by:
removeAgendaGroupin interfaceInternalAgenda
-
getAgendaGroup
public AgendaGroup getAgendaGroup(String name, InternalKnowledgeBase kBase)
- Specified by:
getAgendaGroupin interfaceInternalAgenda
-
getAgendaGroups
public AgendaGroup[] getAgendaGroups()
- Specified by:
getAgendaGroupsin interfaceInternalAgenda
-
getAgendaGroupsMap
public Map<String,InternalAgendaGroup> getAgendaGroupsMap()
- Specified by:
getAgendaGroupsMapin interfaceInternalAgenda
-
putOnAgendaGroupsMap
public void putOnAgendaGroupsMap(String name, InternalAgendaGroup group)
- Specified by:
putOnAgendaGroupsMapin interfaceInternalAgenda
-
getGroupsName
public Collection<String> getGroupsName()
- Specified by:
getGroupsNamein interfaceInternalAgenda
-
addAgendaGroupOnStack
public void addAgendaGroupOnStack(AgendaGroup agendaGroup)
- Specified by:
addAgendaGroupOnStackin interfaceInternalAgenda
-
getActivationGroupsMap
public Map<String,InternalActivationGroup> getActivationGroupsMap()
- Specified by:
getActivationGroupsMapin interfaceInternalAgenda
-
getActivationGroup
public InternalActivationGroup getActivationGroup(String name)
- Specified by:
getActivationGroupin interfaceorg.kie.api.runtime.rule.Agenda- Specified by:
getActivationGroupin interfaceInternalAgenda
-
getRuleFlowGroup
public RuleFlowGroup getRuleFlowGroup(String name)
- Specified by:
getRuleFlowGroupin interfaceorg.kie.api.runtime.rule.Agenda- Specified by:
getRuleFlowGroupin interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(String name)
Description copied from interface:InternalAgendaActivates theRuleFlowGroupwith the given name. All activations in the givenRuleFlowGroupare added to the agenda. As long as theRuleFlowGroupremains active, its activations are automatically added to the agenda.- Specified by:
activateRuleFlowGroupin interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(String name, long processInstanceId, String nodeInstanceId)
Description copied from interface:InternalAgendaActivates theRuleFlowGroupwith the given name. All activations in the givenRuleFlowGroupare added to the agenda. As long as theRuleFlowGroupremains active, its activations are automatically added to the agenda. The given processInstanceId and nodeInstanceId define the process context in which thisRuleFlowGroupis used.- Specified by:
activateRuleFlowGroupin interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(InternalRuleFlowGroup group, Object processInstanceId, String nodeInstanceId)
-
deactivateRuleFlowGroup
public void deactivateRuleFlowGroup(String name)
Description copied from interface:InternalAgendaDeactivates theRuleFlowGroupwith the given name. All activations in the givenRuleFlowGroupare removed from the agenda. As long as theRuleFlowGroupremains deactive, its activations are not added to the agenda- Specified by:
deactivateRuleFlowGroupin interfaceInternalAgenda
-
focusStackSize
public int focusStackSize()
Description copied from interface:InternalAgendaIterates all theAgendGroups in the focus stack returning the total number ofActivations- Specified by:
focusStackSizein interfaceInternalAgenda- Returns:
- total number of
Activations on the focus stack
-
agendaSize
public int agendaSize()
Description copied from interface:InternalAgendaIterates all the modules in the focus stack returning the total number ofActivations- Specified by:
agendaSizein interfaceInternalAgenda- Returns:
- total number of activations on the focus stack
-
getActivations
public Activation[] getActivations()
- Specified by:
getActivationsin interfaceInternalAgenda
-
clear
public void clear()
- Specified by:
clearin interfaceorg.kie.api.runtime.rule.Agenda
-
reset
public void reset()
- Specified by:
resetin interfaceInternalAgenda
-
clearAndCancel
public void clearAndCancel()
Description copied from interface:InternalAgendaClears all Activations from the Agenda- Specified by:
clearAndCancelin interfaceInternalAgenda
-
clearAndCancelAgendaGroup
public void clearAndCancelAgendaGroup(String name)
Description copied from interface:InternalAgendaClears all Activations from an Agenda Group. Any Activations that are also in an Xor Group are removed the the Xor Group.- Specified by:
clearAndCancelAgendaGroupin interfaceInternalAgenda
-
clearAndCancelActivationGroup
public void clearAndCancelActivationGroup(String name)
Description copied from interface:InternalAgendaClears all Activations from an Activation-Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.- Specified by:
clearAndCancelActivationGroupin interfaceInternalAgenda
-
clearAndCancelActivationGroup
public void clearAndCancelActivationGroup(InternalActivationGroup activationGroup)
Description copied from interface:InternalAgendaClears all Activations from an Activation Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.- Specified by:
clearAndCancelActivationGroupin interfaceInternalAgenda
-
clearAndCancelRuleFlowGroup
public void clearAndCancelRuleFlowGroup(String name)
- Specified by:
clearAndCancelRuleFlowGroupin interfaceInternalAgenda
-
fireNextItem
public int fireNextItem(org.kie.api.runtime.rule.AgendaFilter filter, int fireCount, int fireLimit)Fire the next scheduledAgendaitem, skipping items that are not allowed by the agenda filter.- Specified by:
fireNextItemin interfaceInternalAgenda- 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:
evaluateEagerListin interfaceInternalAgenda
-
evaluateQueriesForRule
public void evaluateQueriesForRule(RuleAgendaItem item)
-
sizeOfRuleFlowGroup
public int sizeOfRuleFlowGroup(String name)
- Specified by:
sizeOfRuleFlowGroupin interfaceInternalAgenda
-
isRuleInstanceAgendaItem
public boolean isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, long processInstanceId)
Description copied from interface:InternalAgendaReturns true if there is at least one activation of the given rule name in the given ruleflow group name- Specified by:
isRuleInstanceAgendaItemin interfaceInternalAgenda
-
isRuleInstanceAgendaItem
protected boolean isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, Object processInstanceId)
-
sameProcessInstance
protected boolean sameProcessInstance(Object processInstanceId, org.kie.api.runtime.process.ProcessInstance value)
-
getFocusName
public String getFocusName()
Description copied from interface:InternalAgendaReturns the name of the agenda group that currently has the focus- Specified by:
getFocusNamein interfaceInternalAgenda
-
stageLeftTuple
public void stageLeftTuple(RuleAgendaItem ruleAgendaItem, AgendaItem justified)
- Specified by:
stageLeftTuplein interfaceInternalAgenda
-
fireUntilHalt
public void fireUntilHalt()
Description copied from interface:InternalAgendaKeeps 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:
fireUntilHaltin interfaceInternalAgenda
-
fireUntilHalt
public void fireUntilHalt(org.kie.api.runtime.rule.AgendaFilter agendaFilter)
Description copied from interface:InternalAgendaKeeps 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:
fireUntilHaltin interfaceInternalAgenda- Parameters:
agendaFilter- filters the activations that may fire
-
fireAllRules
public int fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter, int fireLimit)Description copied from interface:InternalAgendaFires all activations currently in agenda that match the given agendaFilter until the fireLimit is reached or no more activations exist.- Specified by:
fireAllRulesin interfaceInternalAgenda- 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
-
isFiring
public boolean isFiring()
- Specified by:
isFiringin interfaceInternalAgenda
-
executeTask
public void executeTask(ExecutableEntry executable)
- Specified by:
executeTaskin interfaceInternalAgenda
-
executeFlush
public void executeFlush()
- Specified by:
executeFlushin interfaceInternalAgenda
-
activate
public void activate()
- Specified by:
activatein interfaceInternalAgenda
-
deactivate
public void deactivate()
- Specified by:
deactivatein interfaceInternalAgenda
-
tryDeactivate
public boolean tryDeactivate()
- Specified by:
tryDeactivatein interfaceInternalAgenda
-
halt
public void halt()
Description copied from interface:InternalAgendaStop agenda from firing any other rule. It will finish the current rule execution though.- Specified by:
haltin interfaceInternalAgenda
-
dispose
public boolean dispose(InternalWorkingMemory wm)
- Specified by:
disposein interfaceInternalAgenda
-
isAlive
public boolean isAlive()
- Specified by:
isAlivein interfaceInternalAgenda
-
internalHalt
public void internalHalt()
-
setActivationsFilter
public void setActivationsFilter(ActivationsFilter filter)
Description copied from interface:InternalAgendaSets a filter that prevents activations from being added to the agenda.- Specified by:
setActivationsFilterin interfaceInternalAgenda
-
getActivationsFilter
public ActivationsFilter getActivationsFilter()
Description copied from interface:InternalAgendaReturns the current activations filter or null if none is set- Specified by:
getActivationsFilterin interfaceInternalAgenda
-
handleException
public void handleException(InternalWorkingMemory wm, Activation activation, Exception e)
- Specified by:
handleExceptionin interfaceInternalAgenda
-
getKnowledgeHelper
public KnowledgeHelper getKnowledgeHelper()
- Specified by:
getKnowledgeHelperin interfaceInternalAgenda
-
addPropagation
public void addPropagation(PropagationEntry propagationEntry)
- Specified by:
addPropagationin interfaceInternalAgenda
-
flushPropagations
public void flushPropagations()
- Specified by:
flushPropagationsin interfaceInternalAgenda
-
notifyWaitOnRest
public void notifyWaitOnRest()
- Specified by:
notifyWaitOnRestin interfaceInternalAgenda
-
getActionsIterator
public Iterator<PropagationEntry> getActionsIterator()
- Specified by:
getActionsIteratorin interfaceInternalAgenda
-
hasPendingPropagations
public boolean hasPendingPropagations()
- Specified by:
hasPendingPropagationsin interfaceInternalAgenda
-
registerExpiration
public void registerExpiration(PropagationContext ectx)
- Specified by:
registerExpirationin interfaceInternalAgenda
-
doRetract
protected void doRetract(PropagationContext ectx)
-
isParallelAgenda
public boolean isParallelAgenda()
- Specified by:
isParallelAgendain interfaceInternalAgenda
-
-