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 int
activationCounter
protected static org.slf4j.Logger
log
static String
ON_AFTER_ALL_FIRES_CONSEQUENCE_NAME
static String
ON_BEFORE_ALL_FIRES_CONSEQUENCE_NAME
static String
ON_DELETE_MATCH_CONSEQUENCE_NAME
protected InternalWorkingMemory
workingMemory
Working 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 void
activate()
void
activateRuleFlowGroup(String name)
Activates theRuleFlowGroup
with the given name.void
activateRuleFlowGroup(String name, long processInstanceId, String nodeInstanceId)
Activates theRuleFlowGroup
with the given name.void
activateRuleFlowGroup(InternalRuleFlowGroup group, Object processInstanceId, String nodeInstanceId)
void
addAgendaGroupOnStack(AgendaGroup agendaGroup)
void
addEagerRuleAgendaItem(RuleAgendaItem item)
void
addItemToActivationGroup(AgendaItem item)
If the item belongs to an activation group, add itvoid
addPropagation(PropagationEntry propagationEntry)
void
addQueryAgendaItem(RuleAgendaItem item)
int
agendaSize()
Iterates all the modules in the focus stack returning the total number ofActivation
svoid
cancelActivation(Activation activation)
void
clear()
void
clearAndCancel()
Clears all Activations from the Agendavoid
clearAndCancelActivationGroup(String name)
Clears all Activations from an Activation-Group.void
clearAndCancelActivationGroup(InternalActivationGroup activationGroup)
Clears all Activations from an Activation Group.void
clearAndCancelAgendaGroup(String name)
Clears all Activations from an Agenda Group.void
clearAndCancelRuleFlowGroup(String name)
AgendaItem
createAgendaItem(RuleTerminalNodeLeftTuple rtnLeftTuple, int salience, PropagationContext context, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)
RuleAgendaItem
createRuleAgendaItem(int salience, PathMemory rs, TerminalNode rtn)
void
deactivate()
void
deactivateRuleFlowGroup(String name)
Deactivates theRuleFlowGroup
with the given name.boolean
dispose(InternalWorkingMemory wm)
protected void
doRetract(PropagationContext ectx)
void
evaluateEagerList()
void
evaluateQueriesForRule(RuleAgendaItem item)
void
executeFlush()
void
executeTask(ExecutableEntry executable)
int
fireAllRules(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.int
fireNextItem(org.kie.api.runtime.rule.AgendaFilter filter, int fireCount, int fireLimit)
Fire the next scheduledAgenda
item, skipping items that are not allowed by the agenda filter.void
fireUntilHalt()
Keeps firing activations until a halt is called.void
fireUntilHalt(org.kie.api.runtime.rule.AgendaFilter agendaFilter)
Keeps firing activations until a halt is called.void
flushPropagations()
int
focusStackSize()
Iterates all theAgendGroup
s in the focus stack returning the total number of
Activation
sIterator<PropagationEntry>
getActionsIterator()
InternalActivationGroup
getActivationGroup(String name)
Map<String,InternalActivationGroup>
getActivationGroupsMap()
Activation[]
getActivations()
ActivationsFilter
getActivationsFilter()
Returns the current activations filter or null if none is setAgendaGroup
getAgendaGroup(String name)
AgendaGroup
getAgendaGroup(String name, InternalKnowledgeBase kBase)
AgendaGroup[]
getAgendaGroups()
Map<String,InternalAgendaGroup>
getAgendaGroupsMap()
String
getFocusName()
Returns the name of the agenda group that currently has the focusCollection<String>
getGroupsName()
KnowledgeHelper
getKnowledgeHelper()
InternalAgendaGroup
getNextFocus()
PropagationList
getPropagationList()
RuleFlowGroup
getRuleFlowGroup(String name)
InternalWorkingMemory
getWorkingMemory()
Returns the WorkignMemory for this Agendavoid
halt()
Stop agenda from firing any other rule.void
handleException(InternalWorkingMemory wm, Activation activation, Exception e)
boolean
hasPendingPropagations()
void
insertAndStageActivation(AgendaItem activation)
void
internalHalt()
boolean
isAlive()
boolean
isDeclarativeAgenda()
boolean
isFiring()
boolean
isParallelAgenda()
boolean
isRuleActiveInRuleFlowGroup(String ruleflowGroupName, String ruleName, long processInstanceId)
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 nameprotected boolean
isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, Object processInstanceId)
void
modifyActivation(AgendaItem activation, boolean previouslyActive)
Adds the activation to the agenda.void
notifyWaitOnRest()
RuleAgendaItem
peekNextRule()
void
putOnAgendaGroupsMap(String name, InternalAgendaGroup group)
void
readExternal(ObjectInput in)
void
registerExpiration(PropagationContext ectx)
void
removeAgendaGroup(String name)
void
removeEagerRuleAgendaItem(RuleAgendaItem item)
void
removeQueryAgendaItem(RuleAgendaItem item)
void
reset()
protected boolean
sameProcessInstance(Object processInstanceId, org.kie.api.runtime.process.ProcessInstance value)
void
setActivationsFilter(ActivationsFilter filter)
Sets a filter that prevents activations from being added to the agenda.void
setFocus(String name)
Sets the Agenda's focus to the specified AgendaGroupboolean
setFocus(AgendaGroup agendaGroup)
void
setFocus(PropagationContext ctx, String name)
void
setWorkingMemory(InternalWorkingMemory workingMemory)
int
sizeOfRuleFlowGroup(String name)
void
stageLeftTuple(RuleAgendaItem ruleAgendaItem, AgendaItem justified)
boolean
tryDeactivate()
void
writeExternal(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:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
createRuleAgendaItem
public RuleAgendaItem createRuleAgendaItem(int salience, PathMemory rs, TerminalNode rtn)
- Specified by:
createRuleAgendaItem
in interfaceInternalAgenda
-
createAgendaItem
public AgendaItem createAgendaItem(RuleTerminalNodeLeftTuple rtnLeftTuple, int salience, PropagationContext context, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)
- Specified by:
createAgendaItem
in interfaceInternalAgenda
-
setWorkingMemory
public void setWorkingMemory(InternalWorkingMemory workingMemory)
- Specified by:
setWorkingMemory
in interfaceInternalAgenda
-
getPropagationList
public PropagationList getPropagationList()
- Specified by:
getPropagationList
in interfaceInternalAgenda
-
getWorkingMemory
public InternalWorkingMemory getWorkingMemory()
Description copied from interface:InternalAgenda
Returns the WorkignMemory for this Agenda- Specified by:
getWorkingMemory
in interfaceInternalAgenda
- Returns:
- The WorkingMemory
-
addEagerRuleAgendaItem
public void addEagerRuleAgendaItem(RuleAgendaItem item)
- Specified by:
addEagerRuleAgendaItem
in interfaceInternalAgenda
-
removeEagerRuleAgendaItem
public void removeEagerRuleAgendaItem(RuleAgendaItem item)
- Specified by:
removeEagerRuleAgendaItem
in interfaceInternalAgenda
-
addQueryAgendaItem
public void addQueryAgendaItem(RuleAgendaItem item)
- Specified by:
addQueryAgendaItem
in interfaceInternalAgenda
-
removeQueryAgendaItem
public void removeQueryAgendaItem(RuleAgendaItem item)
- Specified by:
removeQueryAgendaItem
in interfaceInternalAgenda
-
addItemToActivationGroup
public void addItemToActivationGroup(AgendaItem item)
If the item belongs to an activation group, add it- Specified by:
addItemToActivationGroup
in interfaceInternalAgenda
- Parameters:
item
-
-
insertAndStageActivation
public void insertAndStageActivation(AgendaItem activation)
- Specified by:
insertAndStageActivation
in interfaceInternalAgenda
-
isDeclarativeAgenda
public boolean isDeclarativeAgenda()
- Specified by:
isDeclarativeAgenda
in interfaceInternalAgenda
-
modifyActivation
public void modifyActivation(AgendaItem activation, boolean previouslyActive)
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:
modifyActivation
in interfaceInternalAgenda
-
isRuleActiveInRuleFlowGroup
public boolean isRuleActiveInRuleFlowGroup(String ruleflowGroupName, String ruleName, long processInstanceId)
- Specified by:
isRuleActiveInRuleFlowGroup
in interfaceInternalAgenda
-
cancelActivation
public void cancelActivation(Activation activation)
- Specified by:
cancelActivation
in interfaceInternalAgenda
-
setFocus
public boolean setFocus(AgendaGroup agendaGroup)
- Specified by:
setFocus
in interfaceInternalAgenda
-
setFocus
public void setFocus(String name)
Description copied from interface:InternalAgenda
Sets the Agenda's focus to the specified AgendaGroup- Specified by:
setFocus
in interfaceInternalAgenda
-
setFocus
public void setFocus(PropagationContext ctx, String name)
-
getNextFocus
public InternalAgendaGroup getNextFocus()
- Specified by:
getNextFocus
in interfaceInternalAgenda
-
peekNextRule
public RuleAgendaItem peekNextRule()
- Specified by:
peekNextRule
in interfaceInternalAgenda
-
getAgendaGroup
public AgendaGroup getAgendaGroup(String name)
- Specified by:
getAgendaGroup
in interfaceorg.kie.api.runtime.rule.Agenda
- Specified by:
getAgendaGroup
in interfaceInternalAgenda
-
removeAgendaGroup
public void removeAgendaGroup(String name)
- Specified by:
removeAgendaGroup
in interfaceInternalAgenda
-
getAgendaGroup
public AgendaGroup getAgendaGroup(String name, InternalKnowledgeBase kBase)
- Specified by:
getAgendaGroup
in interfaceInternalAgenda
-
getAgendaGroups
public AgendaGroup[] getAgendaGroups()
- Specified by:
getAgendaGroups
in interfaceInternalAgenda
-
getAgendaGroupsMap
public Map<String,InternalAgendaGroup> getAgendaGroupsMap()
- Specified by:
getAgendaGroupsMap
in interfaceInternalAgenda
-
putOnAgendaGroupsMap
public void putOnAgendaGroupsMap(String name, InternalAgendaGroup group)
- Specified by:
putOnAgendaGroupsMap
in interfaceInternalAgenda
-
getGroupsName
public Collection<String> getGroupsName()
- Specified by:
getGroupsName
in interfaceInternalAgenda
-
addAgendaGroupOnStack
public void addAgendaGroupOnStack(AgendaGroup agendaGroup)
- Specified by:
addAgendaGroupOnStack
in interfaceInternalAgenda
-
getActivationGroupsMap
public Map<String,InternalActivationGroup> getActivationGroupsMap()
- Specified by:
getActivationGroupsMap
in interfaceInternalAgenda
-
getActivationGroup
public InternalActivationGroup getActivationGroup(String name)
- Specified by:
getActivationGroup
in interfaceorg.kie.api.runtime.rule.Agenda
- Specified by:
getActivationGroup
in interfaceInternalAgenda
-
getRuleFlowGroup
public RuleFlowGroup getRuleFlowGroup(String name)
- Specified by:
getRuleFlowGroup
in interfaceorg.kie.api.runtime.rule.Agenda
- Specified by:
getRuleFlowGroup
in interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(String name)
Description copied from interface:InternalAgenda
Activates theRuleFlowGroup
with the given name. All activations in the givenRuleFlowGroup
are added to the agenda. As long as theRuleFlowGroup
remains active, its activations are automatically added to the agenda.- Specified by:
activateRuleFlowGroup
in interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(String name, long processInstanceId, String nodeInstanceId)
Description copied from interface:InternalAgenda
Activates theRuleFlowGroup
with the given name. All activations in the givenRuleFlowGroup
are added to the agenda. As long as theRuleFlowGroup
remains active, its activations are automatically added to the agenda. The given processInstanceId and nodeInstanceId define the process context in which thisRuleFlowGroup
is used.- Specified by:
activateRuleFlowGroup
in interfaceInternalAgenda
-
activateRuleFlowGroup
public void activateRuleFlowGroup(InternalRuleFlowGroup group, Object processInstanceId, String nodeInstanceId)
-
deactivateRuleFlowGroup
public void deactivateRuleFlowGroup(String name)
Description copied from interface:InternalAgenda
Deactivates theRuleFlowGroup
with the given name. All activations in the givenRuleFlowGroup
are removed from the agenda. As long as theRuleFlowGroup
remains deactive, its activations are not added to the agenda- Specified by:
deactivateRuleFlowGroup
in interfaceInternalAgenda
-
focusStackSize
public int focusStackSize()
Description copied from interface:InternalAgenda
Iterates all theAgendGroup
s in the focus stack returning the total number of
Activation
s- Specified by:
focusStackSize
in interfaceInternalAgenda
- Returns:
- total number of
Activation
s on the focus stack
-
agendaSize
public int agendaSize()
Description copied from interface:InternalAgenda
Iterates all the modules in the focus stack returning the total number ofActivation
s- Specified by:
agendaSize
in interfaceInternalAgenda
- Returns:
- total number of activations on the focus stack
-
getActivations
public Activation[] getActivations()
- Specified by:
getActivations
in interfaceInternalAgenda
-
clear
public void clear()
- Specified by:
clear
in interfaceorg.kie.api.runtime.rule.Agenda
-
reset
public void reset()
- Specified by:
reset
in interfaceInternalAgenda
-
clearAndCancel
public void clearAndCancel()
Description copied from interface:InternalAgenda
Clears all Activations from the Agenda- Specified by:
clearAndCancel
in interfaceInternalAgenda
-
clearAndCancelAgendaGroup
public void clearAndCancelAgendaGroup(String name)
Description copied from interface:InternalAgenda
Clears all Activations from an Agenda Group. Any Activations that are also in an Xor Group are removed the the Xor Group.- Specified by:
clearAndCancelAgendaGroup
in interfaceInternalAgenda
-
clearAndCancelActivationGroup
public void clearAndCancelActivationGroup(String name)
Description copied from interface:InternalAgenda
Clears all Activations from an Activation-Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.- Specified by:
clearAndCancelActivationGroup
in interfaceInternalAgenda
-
clearAndCancelActivationGroup
public void clearAndCancelActivationGroup(InternalActivationGroup activationGroup)
Description copied from interface:InternalAgenda
Clears all Activations from an Activation Group. Any Activations that are also in an Agenda Group are removed from the Agenda Group.- Specified by:
clearAndCancelActivationGroup
in interfaceInternalAgenda
-
clearAndCancelRuleFlowGroup
public void clearAndCancelRuleFlowGroup(String name)
- Specified by:
clearAndCancelRuleFlowGroup
in interfaceInternalAgenda
-
fireNextItem
public int fireNextItem(org.kie.api.runtime.rule.AgendaFilter filter, int fireCount, int fireLimit)
Fire the next scheduledAgenda
item, skipping items that are not allowed by the agenda filter.- Specified by:
fireNextItem
in 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:
evaluateEagerList
in interfaceInternalAgenda
-
evaluateQueriesForRule
public void evaluateQueriesForRule(RuleAgendaItem item)
-
sizeOfRuleFlowGroup
public int sizeOfRuleFlowGroup(String name)
- Specified by:
sizeOfRuleFlowGroup
in interfaceInternalAgenda
-
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 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:InternalAgenda
Returns the name of the agenda group that currently has the focus- Specified by:
getFocusName
in interfaceInternalAgenda
-
stageLeftTuple
public void stageLeftTuple(RuleAgendaItem ruleAgendaItem, AgendaItem justified)
- Specified by:
stageLeftTuple
in interfaceInternalAgenda
-
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 interfaceInternalAgenda
-
fireUntilHalt
public void fireUntilHalt(org.kie.api.runtime.rule.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 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: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 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:
isFiring
in interfaceInternalAgenda
-
executeTask
public void executeTask(ExecutableEntry executable)
- Specified by:
executeTask
in interfaceInternalAgenda
-
executeFlush
public void executeFlush()
- Specified by:
executeFlush
in interfaceInternalAgenda
-
activate
public void activate()
- Specified by:
activate
in interfaceInternalAgenda
-
deactivate
public void deactivate()
- Specified by:
deactivate
in interfaceInternalAgenda
-
tryDeactivate
public boolean tryDeactivate()
- Specified by:
tryDeactivate
in interfaceInternalAgenda
-
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 interfaceInternalAgenda
-
dispose
public boolean dispose(InternalWorkingMemory wm)
- Specified by:
dispose
in interfaceInternalAgenda
-
isAlive
public boolean isAlive()
- Specified by:
isAlive
in interfaceInternalAgenda
-
internalHalt
public void internalHalt()
-
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 interfaceInternalAgenda
-
getActivationsFilter
public ActivationsFilter getActivationsFilter()
Description copied from interface:InternalAgenda
Returns the current activations filter or null if none is set- Specified by:
getActivationsFilter
in interfaceInternalAgenda
-
handleException
public void handleException(InternalWorkingMemory wm, Activation activation, Exception e)
- Specified by:
handleException
in interfaceInternalAgenda
-
getKnowledgeHelper
public KnowledgeHelper getKnowledgeHelper()
- Specified by:
getKnowledgeHelper
in interfaceInternalAgenda
-
addPropagation
public void addPropagation(PropagationEntry propagationEntry)
- Specified by:
addPropagation
in interfaceInternalAgenda
-
flushPropagations
public void flushPropagations()
- Specified by:
flushPropagations
in interfaceInternalAgenda
-
notifyWaitOnRest
public void notifyWaitOnRest()
- Specified by:
notifyWaitOnRest
in interfaceInternalAgenda
-
getActionsIterator
public Iterator<PropagationEntry> getActionsIterator()
- Specified by:
getActionsIterator
in interfaceInternalAgenda
-
hasPendingPropagations
public boolean hasPendingPropagations()
- Specified by:
hasPendingPropagations
in interfaceInternalAgenda
-
registerExpiration
public void registerExpiration(PropagationContext ectx)
- Specified by:
registerExpiration
in interfaceInternalAgenda
-
doRetract
protected void doRetract(PropagationContext ectx)
-
isParallelAgenda
public boolean isParallelAgenda()
- Specified by:
isParallelAgenda
in interfaceInternalAgenda
-
-