Package org.drools.core.common
Class DefaultAgenda
- java.lang.Object
-
- org.drools.core.common.DefaultAgenda
-
- All Implemented Interfaces:
Externalizable,Serializable,ActivationsManager,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)voidaddEagerRuleAgendaItem(RuleAgendaItem item)voidaddItemToActivationGroup(AgendaItem activation)voidaddPropagation(PropagationEntry propagationEntry)voidaddQueryAgendaItem(RuleAgendaItem item)voidcancelActivation(Activation activation)voidclear()voidclearAndCancel()Clears all Activations from the AgendavoidclearAndCancelActivationGroup(String name)Clears all Activations from an Activation-Group.voidclearAndCancelActivationGroup(InternalActivationGroup activationGroup)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()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()Iterator<PropagationEntry>getActionsIterator()InternalActivationGroupgetActivationGroup(String name)Map<String,InternalActivationGroup>getActivationGroupsMap()ActivationsFiltergetActivationsFilter()AgendaEventSupportgetAgendaEventSupport()org.kie.api.runtime.rule.AgendaGroupgetAgendaGroup(String name)AgendaGroupsManagergetAgendaGroupsManager()StringgetFocusName()Returns the name of the agenda group that currently has the focusKnowledgeHelpergetKnowledgeHelper()PropagationListgetPropagationList()ReteEvaluatorgetReteEvaluator()RuleFlowGroupgetRuleFlowGroup(String name)InternalWorkingMemorygetWorkingMemory()Returns the WorkignMemory for this Agendavoidhalt()Stop agenda from firing any other rule.voidhandleException(Activation activation, Exception e)booleanhasPendingPropagations()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)voidnotifyWaitOnRest()RuleAgendaItempeekNextRule()voidreadExternal(ObjectInput in)voidregisterExpiration(PropagationContext ectx)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 AgendaGroupvoidsetFocus(PropagationContext ctx, String name)voidsetWorkingMemory(InternalWorkingMemory workingMemory)intsizeOfRuleFlowGroup(String name)booleantryDeactivate()voidwriteExternal(ObjectOutput out)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.drools.core.common.ActivationsManager
stageLeftTuple
-
-
-
-
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 interfaceActivationsManager
-
createAgendaItem
public AgendaItem createAgendaItem(RuleTerminalNodeLeftTuple rtnLeftTuple, int salience, PropagationContext context, RuleAgendaItem ruleAgendaItem, InternalAgendaGroup agendaGroup)
- Specified by:
createAgendaItemin interfaceActivationsManager
-
setWorkingMemory
public void setWorkingMemory(InternalWorkingMemory workingMemory)
- Specified by:
setWorkingMemoryin interfaceInternalAgenda
-
getPropagationList
public PropagationList getPropagationList()
-
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 interfaceActivationsManager
-
removeEagerRuleAgendaItem
public void removeEagerRuleAgendaItem(RuleAgendaItem item)
- Specified by:
removeEagerRuleAgendaItemin interfaceActivationsManager
-
addQueryAgendaItem
public void addQueryAgendaItem(RuleAgendaItem item)
- Specified by:
addQueryAgendaItemin interfaceActivationsManager
-
removeQueryAgendaItem
public void removeQueryAgendaItem(RuleAgendaItem item)
- Specified by:
removeQueryAgendaItemin interfaceActivationsManager
-
addItemToActivationGroup
public void addItemToActivationGroup(AgendaItem activation)
- Specified by:
addItemToActivationGroupin interfaceActivationsManager
-
peekNextRule
public RuleAgendaItem peekNextRule()
- Specified by:
peekNextRulein interfaceActivationsManager
-
isDeclarativeAgenda
public boolean isDeclarativeAgenda()
- Specified by:
isDeclarativeAgendain interfaceInternalAgenda
-
isRuleActiveInRuleFlowGroup
public boolean isRuleActiveInRuleFlowGroup(String ruleflowGroupName, String ruleName, long processInstanceId)
- Specified by:
isRuleActiveInRuleFlowGroupin interfaceInternalAgenda
-
cancelActivation
public void cancelActivation(Activation activation)
- Specified by:
cancelActivationin interfaceActivationsManager
-
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)
-
getReteEvaluator
public ReteEvaluator getReteEvaluator()
- Specified by:
getReteEvaluatorin interfaceActivationsManager
-
getAgendaGroupsManager
public AgendaGroupsManager getAgendaGroupsManager()
- Specified by:
getAgendaGroupsManagerin interfaceActivationsManager
-
getAgendaEventSupport
public AgendaEventSupport getAgendaEventSupport()
- Specified by:
getAgendaEventSupportin interfaceActivationsManager
-
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
-
getRuleFlowGroup
public RuleFlowGroup getRuleFlowGroup(String name)
- Specified by:
getRuleFlowGroupin interfaceorg.kie.api.runtime.rule.Agenda
-
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)
-
clear
public void clear()
- Specified by:
clearin interfaceorg.kie.api.runtime.rule.Agenda
-
getAgendaGroup
public org.kie.api.runtime.rule.AgendaGroup getAgendaGroup(String name)
- Specified by:
getAgendaGroupin 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 interfaceActivationsManager- Specified by:
clearAndCancelActivationGroupin interfaceInternalAgenda
-
clearAndCancelActivationGroup
public void clearAndCancelActivationGroup(InternalActivationGroup activationGroup)
- Specified by:
clearAndCancelActivationGroupin interfaceActivationsManager
-
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 interfaceActivationsManager
-
evaluateQueriesForRule
public void evaluateQueriesForRule(RuleAgendaItem item)
- Specified by:
evaluateQueriesForRulein interfaceActivationsManager
-
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
-
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 interfaceActivationsManager- 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 interfaceActivationsManager
-
executeTask
public void executeTask(ExecutableEntry executable)
- Specified by:
executeTaskin interfaceActivationsManager
-
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()
- Specified by:
getActivationsFilterin interfaceActivationsManager
-
handleException
public void handleException(Activation activation, Exception e)
- Specified by:
handleExceptionin interfaceActivationsManager
-
getKnowledgeHelper
public KnowledgeHelper getKnowledgeHelper()
- Specified by:
getKnowledgeHelperin interfaceActivationsManager
-
addPropagation
public void addPropagation(PropagationEntry propagationEntry)
- Specified by:
addPropagationin interfaceActivationsManager
-
flushPropagations
public void flushPropagations()
- Specified by:
flushPropagationsin interfaceActivationsManager
-
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 interfaceActivationsManager
-
doRetract
protected void doRetract(PropagationContext ectx)
-
isParallelAgenda
public boolean isParallelAgenda()
- Specified by:
isParallelAgendain interfaceInternalAgenda
-
-