Package org.drools.core
Interface WorkingMemory
-
- All Superinterfaces:
org.kie.api.runtime.rule.EntryPoint
,org.kie.api.event.kiebase.KieBaseEventManager
,WorkingMemoryEntryPoint
,WorkingMemoryEventManager
- All Known Subinterfaces:
InternalWorkingMemory
,InternalWorkingMemoryActions
- All Known Implementing Classes:
StatefulKnowledgeSessionImpl
,WrappedStatefulKnowledgeSessionForRHS
public interface WorkingMemory extends WorkingMemoryEventManager, WorkingMemoryEntryPoint
A knowledge session for aRuleBase
. While this object can be serialised out, it cannot be serialised in. This is because the RuleBase reference is transient. Please see the RuleBase interface for serializing in WorkingMemories from an InputStream.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clearActivationGroup(String group)
Clears the Activation Group, cancellings all its Activationsvoid
clearAgenda()
Clear the Agenda.void
clearAgendaGroup(String group)
Clear the Agenda Group, cancelling all its Activations.void
clearRuleFlowGroup(String group)
Clears the RuleFlow group, cancelling all its Activationsint
fireAllRules()
Fire all items on the agenda until empty.int
fireAllRules(int fireLimit)
Fire all items on the agenda until empty or at most 'fireLimit' rules have firedint
fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter)
Fire all items on the agenda until empty, using the given AgendaFilerint
fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter, int fireLimit)
Fire all items on the agenda using the given AgendaFiler until empty or at most 'fireLimit' rules have firedorg.kie.api.runtime.rule.Agenda
getAgenda()
Returns the Agenda for this WorkingMemory.org.kie.api.runtime.Environment
getEnvironment()
org.kie.api.runtime.rule.FactHandle
getFactHandle(Object object)
Retrieve theFactHandle
associated with an Object.org.kie.api.runtime.rule.FactHandle
getFactHandleByIdentity(Object object)
Object
getGlobal(String identifier)
Retrieve a specific instance of global data by identifierGlobalResolver
getGlobalResolver()
Returns the current GlobalResolverInternalKnowledgeBase
getKnowledgeBase()
Retrieve theRuleBase
for this working memory.Object
getObject(org.kie.api.runtime.rule.FactHandle handle)
Retrieve the object associated with aFactHandle
.org.kie.api.runtime.process.ProcessInstance
getProcessInstance(long id)
Returns the process instance with the given id.org.kie.api.runtime.process.ProcessInstance
getProcessInstance(long id, boolean readOnly)
Collection<org.kie.api.runtime.process.ProcessInstance>
getProcessInstances()
Returns the list of process instances of this working memory.org.kie.api.runtime.rule.QueryResults
getQueryResults(String query, Object... arguments)
Retrieve the QueryResults of the specified query and argumentsorg.kie.api.time.SessionClock
getSessionClock()
Returns the session clock instance associated with this sessionWorkingMemoryEntryPoint
getWorkingMemoryEntryPoint(String id)
Returns the interface instance for a given entry point, so that the application can manage entry-point-scoped facts.org.kie.api.runtime.process.WorkItemManager
getWorkItemManager()
void
halt()
Stops rule firing after the current rule finishes executingIterator<InternalFactHandle>
iterateFactHandles()
Returns an Iterator for the FactHandles in the Working Memory.Iterator<InternalFactHandle>
iterateFactHandles(org.kie.api.runtime.ObjectFilter filter)
Returns an Iterator for the Objects in the Working Memory.Iterator<?>
iterateObjects()
Returns an Iterator for the Objects in the Working Memory.Iterator<?>
iterateObjects(org.kie.api.runtime.ObjectFilter filter)
Returns an Iterator for the Objects in the Working Memory.void
setAsyncExceptionHandler(AsyncExceptionHandler handler)
Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda Scheduler used for duration rules.void
setFocus(String focus)
Set the focus to the specified AgendaGroupvoid
setGlobal(String identifier, Object value)
Set a specific instance as a global in this working memory.void
setGlobalResolver(GlobalResolver globalResolver)
Sets the GlobalResolver instance to be used when resolving globals, replaces the current GlobalResolver.org.kie.api.runtime.process.ProcessInstance
startProcess(String processId)
Starts a new process instance for the process with the given id.org.kie.api.runtime.process.ProcessInstance
startProcess(String processId, Map<String,Object> parameters)
Starts a new process instance for the process with the given id.-
Methods inherited from interface org.kie.api.runtime.rule.EntryPoint
delete, delete, getEntryPointId, getFactCount, getFactHandles, getFactHandles, getObjects, getObjects, insert, retract, update, update
-
Methods inherited from interface org.kie.api.event.kiebase.KieBaseEventManager
addEventListener, getKieBaseEventListeners, removeEventListener
-
Methods inherited from interface org.drools.core.WorkingMemoryEntryPoint
delete, delete, dispose, getEntryPoint, getEntryPointNode, getHandleFactory, getInternalWorkingMemory, getObjectStore, getObjectTypeConfigurationRegistry, getRuleUnit, getTruthMaintenanceSystem, insert, reset, setRuleUnit, update
-
Methods inherited from interface org.drools.core.WorkingMemoryEventManager
addEventListener, addEventListener, getAgendaEventListeners, getRuleRuntimeEventListeners, removeEventListener, removeEventListener
-
-
-
-
Method Detail
-
getAgenda
org.kie.api.runtime.rule.Agenda getAgenda()
Returns the Agenda for this WorkingMemory. While the WorkingMemory interface is considered public, the Agenda interface is more subject to change.- Returns:
- the Agenda
-
setGlobal
void setGlobal(String identifier, Object value)
Set a specific instance as a global in this working memory. Null values will return doing nothing. The global identifier and its type must be declared in the drl.- Parameters:
identifier
- the identifier under which to populate the datavalue
- the global value, cannot be null
-
getGlobal
Object getGlobal(String identifier)
Retrieve a specific instance of global data by identifier- Returns:
- application data or null if nothing is set under this identifier
-
getEnvironment
org.kie.api.runtime.Environment getEnvironment()
-
setGlobalResolver
void setGlobalResolver(GlobalResolver globalResolver)
Sets the GlobalResolver instance to be used when resolving globals, replaces the current GlobalResolver. Typcicaly a delegating GlobalResolver is created that first gets a reference to the current GlobalResolver, for delegating- Parameters:
globalResolver
-
-
getGlobalResolver
GlobalResolver getGlobalResolver()
Returns the current GlobalResolver- Returns:
-
getKnowledgeBase
InternalKnowledgeBase getKnowledgeBase()
Retrieve theRuleBase
for this working memory.- Specified by:
getKnowledgeBase
in interfaceWorkingMemoryEntryPoint
- Returns:
- The
RuleBase
.
-
fireAllRules
int fireAllRules()
Fire all items on the agenda until empty.
-
fireAllRules
int fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter)
Fire all items on the agenda until empty, using the given AgendaFiler
-
fireAllRules
int fireAllRules(int fireLimit)
Fire all items on the agenda until empty or at most 'fireLimit' rules have fired
-
fireAllRules
int fireAllRules(org.kie.api.runtime.rule.AgendaFilter agendaFilter, int fireLimit)
Fire all items on the agenda using the given AgendaFiler until empty or at most 'fireLimit' rules have fired
-
getObject
Object getObject(org.kie.api.runtime.rule.FactHandle handle)
Retrieve the object associated with aFactHandle
.- Specified by:
getObject
in interfaceorg.kie.api.runtime.rule.EntryPoint
- Parameters:
handle
- The fact handle.- Returns:
- The associated object.
-
getFactHandle
org.kie.api.runtime.rule.FactHandle getFactHandle(Object object)
Retrieve theFactHandle
associated with an Object.- Specified by:
getFactHandle
in interfaceorg.kie.api.runtime.rule.EntryPoint
- Parameters:
object
- The object.- Returns:
- The associated fact handle.
-
getFactHandleByIdentity
org.kie.api.runtime.rule.FactHandle getFactHandleByIdentity(Object object)
- Specified by:
getFactHandleByIdentity
in interfaceWorkingMemoryEntryPoint
-
iterateObjects
Iterator<?> iterateObjects()
Returns an Iterator for the Objects in the Working Memory. This Iterator is not thread safe. This means that any working memory actions during iteration may invalidate the iterator.- Returns:
- the Iterator
-
iterateObjects
Iterator<?> iterateObjects(org.kie.api.runtime.ObjectFilter filter)
Returns an Iterator for the Objects in the Working Memory. This Iterator will filter out any objects that the ObjectFilter does not accept. This Iterator is not thread safe. This means that any working memory actions during iteration may invalidate the iterator.- Parameters:
filter
-- Returns:
- the Iterator
-
iterateFactHandles
Iterator<InternalFactHandle> iterateFactHandles()
Returns an Iterator for the FactHandles in the Working Memory. This Iterator is not thread safe. This means that any working memory actions during iteration may invalidate the iterator.- Returns:
- the Iterator
-
iterateFactHandles
Iterator<InternalFactHandle> iterateFactHandles(org.kie.api.runtime.ObjectFilter filter)
Returns an Iterator for the Objects in the Working Memory. This Iterator will filter out any objects that the ObjectFilter does not accept. This Iterator is not thread safe. This means that any working memory actions during iteration may invalidate the iterator.- Parameters:
filter
-- Returns:
- the Iterator
-
setFocus
void setFocus(String focus)
Set the focus to the specified AgendaGroup- Parameters:
focus
-
-
getQueryResults
org.kie.api.runtime.rule.QueryResults getQueryResults(String query, Object... arguments)
Retrieve the QueryResults of the specified query and arguments- Parameters:
query
- The name of the query.arguments
- The arguments used for the query- Returns:
- The QueryResults of the specified query. If no results match the query it is empty.
- Throws:
IllegalArgumentException
- if no query named "query" is found in the rulebase
-
setAsyncExceptionHandler
void setAsyncExceptionHandler(AsyncExceptionHandler handler)
Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda Scheduler used for duration rules.- Parameters:
handler
-
-
clearAgenda
void clearAgenda()
Clear the Agenda. Iterates over each AgendaGroup cancalling all Activations.
-
clearAgendaGroup
void clearAgendaGroup(String group)
Clear the Agenda Group, cancelling all its Activations.
-
clearActivationGroup
void clearActivationGroup(String group)
Clears the Activation Group, cancellings all its Activations- Parameters:
group
-
-
clearRuleFlowGroup
void clearRuleFlowGroup(String group)
Clears the RuleFlow group, cancelling all its Activations- Parameters:
group
-
-
startProcess
org.kie.api.runtime.process.ProcessInstance startProcess(String processId)
Starts a new process instance for the process with the given id.
-
startProcess
org.kie.api.runtime.process.ProcessInstance startProcess(String processId, Map<String,Object> parameters)
Starts a new process instance for the process with the given id.
-
getProcessInstances
Collection<org.kie.api.runtime.process.ProcessInstance> getProcessInstances()
Returns the list of process instances of this working memory. This list is unmodifiable.- Returns:
- the list of process instances
-
getProcessInstance
org.kie.api.runtime.process.ProcessInstance getProcessInstance(long id)
Returns the process instance with the given id.- Returns:
- the process instance with the given id
-
getProcessInstance
org.kie.api.runtime.process.ProcessInstance getProcessInstance(long id, boolean readOnly)
-
getWorkItemManager
org.kie.api.runtime.process.WorkItemManager getWorkItemManager()
-
halt
void halt()
Stops rule firing after the current rule finishes executing
-
getWorkingMemoryEntryPoint
WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String id)
Returns the interface instance for a given entry point, so that the application can manage entry-point-scoped facts.- Specified by:
getWorkingMemoryEntryPoint
in interfaceWorkingMemoryEntryPoint
- Parameters:
id
- the id of the entry point, as defined in the rules file- Returns:
-
getSessionClock
org.kie.api.time.SessionClock getSessionClock()
Returns the session clock instance associated with this session- Returns:
-
-