站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss RULES 4.0.0.11754MR2 API 英文版文档

AbstractWorkingMemory (Drools 4.0.0.11754MR2 API) - JBoss RULES 4.0.0.11754MR2 API 英文版文档


org.drools.common
Class AbstractWorkingMemory

java.lang.Object
  extended by org.drools.common.AbstractWorkingMemory
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, EventSupport, InternalWorkingMemory, InternalWorkingMemoryActions, WorkingMemory
Direct Known Subclasses:
ReteooWorkingMemory

public abstract class AbstractWorkingMemory
extends Object
implements InternalWorkingMemoryActions, EventSupport, PropertyChangeListener

Implementation of WorkingMemory.

Author:
bob mcwhirter , Mark Proctor, Simon Harris
See Also:
Serialized Form

Nested Class Summary
 class AbstractWorkingMemory.RuleFlowDeactivateEvent
           
 
Field Summary
protected  List actionQueue
           
protected static Class[] ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES
           
protected  Object[] addRemovePropertyChangeListenerArgs
          The arguments used when adding/removing a property change listener.
protected  DefaultAgenda agenda
          Rule-firing agenda.
protected  AgendaEventSupport agendaEventSupport
           
protected  boolean discardOnLogicalOverride
           
protected  boolean firing
          Flag to determine if a rule is currently being fired.
protected  GlobalResolver globalResolver
           
protected  Map globals
          Global values which are associated with this memory.
protected  FactHandleFactory handleFactory
           
protected  long id
           
protected  ReentrantLock lock
           
protected  PrimitiveLongMap nodeMemories
          The actual memory for the JoinNodes.
protected static Object NULL
           
protected  long propagationIdCounter
           
protected  Map queryResults
           
protected  InternalRuleBase ruleBase
          The RuleBase with which this memory is associated.
protected  TruthMaintenanceSystem tms
           
protected  WorkingMemoryEventSupport workingMemoryEventSupport
          The eventSupport
 
Constructor Summary
AbstractWorkingMemory(int id, InternalRuleBase ruleBase, FactHandleFactory handleFactory)
          Construct.
 
Method Summary
 void addEventListener(AgendaEventListener listener)
          Add an event listener.
 void addEventListener(WorkingMemoryEventListener listener)
          Add an event listener.
protected  void addPropertyChangeListener(Object object)
           
 FactHandle assertLogicalObject(Object object)
           
 FactHandle assertLogicalObject(Object object, boolean dynamic)
           
 FactHandle assertObject(Object object)
          Assert a fact.
 FactHandle assertObject(Object object, boolean dynamic)
          Assert a fact registering JavaBean PropertyChangeListeners on the Object to automatically trigger modifyObject calls if dynamic is true.
 FactHandle assertObject(Object object, boolean dynamic, boolean logical, Rule rule, Activation activation)
           
 void clearAgenda()
          Clear the Agenda
 void clearAgendaGroup(String group)
          Clear the Agenda Group
 void clearNodeMemory(NodeMemory node)
           
abstract  void doAssertObject(InternalFactHandle factHandle, Object object, PropagationContext propagationContext)
           
abstract  void doRetract(InternalFactHandle factHandle, PropagationContext propagationContext)
           
 void executeQueuedActions()
           
 void fireAllRules()
          Fire all items on the agenda until empty.
 void fireAllRules(AgendaFilter agendaFilter)
          Fire all items on the agenda until empty, using the given AgendaFiler
 Agenda getAgenda()
          Retrieve the rule-firing Agenda for this WorkingMemory.
 List getAgendaEventListeners()
          Returns all event listeners.
 AgendaEventSupport getAgendaEventSupport()
           
 FactHandle getFactHandle(Object object)
          Retrieve the FactHandle associated with an Object.
 FactHandleFactory getFactHandleFactory()
           
 ObjectHashMap getFactHandleMap()
          This is an internal method, used to avoid java.util.Iterator adaptors
 AgendaGroup getFocus()
           
 Object getGlobal(String name)
          Retrieve a specific piece of global data by name
 Map getGlobals()
          Retrieve all of the set application data in this memory
 long getId()
           
 Lock getLock()
           
 long getNextPropagationIdCounter()
           
 Object getNodeMemory(NodeMemory node)
          Retrieve the JoinMemory for a particular JoinNode.
 Object getObject(FactHandle handle)
          Returns the fact Object for the given FactHandle.
abstract  QueryResults getQueryResults(String query)
          Retrieve the QueryResults of the specified query.
 RuleBase getRuleBase()
          Retrieve the RuleBase of this working memory.
 TruthMaintenanceSystem getTruthMaintenanceSystem()
           
 List getWorkingMemoryEventListeners()
          Returns all event listeners.
 WorkingMemoryEventSupport getWorkingMemoryEventSupport()
           
 Iterator iterateFactHandles()
          This class is not thread safe, changes to the working memory during iteration may give unexpected results
 Iterator iterateFactHandles(ObjectFilter filter)
          This class is not thread safe, changes to the working memory during iteration may give unexpected results
 Iterator iterateObjects()
          This class is not thread safe, changes to the working memory during iteration may give unexpected results
 Iterator iterateObjects(ObjectFilter filter)
          This class is not thread safe, changes to the working memory during iteration may give unexpected results
 List iterateObjectsToList()
           
 void modifyObject(FactHandle handle, Object object)
          Modify a fact.
 void modifyObject(FactHandle factHandle, Object object, Rule rule, Activation activation)
          modify is implemented as half way retract / assert due to the truth maintenance issues.
 void propertyChange(PropertyChangeEvent event)
           
 void queueWorkingMemoryAction(WorkingMemoryAction action)
           
 void removeEventListener(AgendaEventListener listener)
          Remove an event listener.
 void removeEventListener(WorkingMemoryEventListener listener)
          Remove an event listener.
 void removeLogicalDependencies(Activation activation, PropagationContext context, Rule rule)
           
protected  void removePropertyChangeListener(FactHandle handle)
           
 void retractObject(FactHandle handle)
          Retract a fact.
 void retractObject(FactHandle factHandle, boolean removeLogical, boolean updateEqualsMap, Rule rule, Activation activation)
           
 void setAsyncExceptionHandler(AsyncExceptionHandler handler)
          Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda Scheduler used for duration rules.
 void setFocus(AgendaGroup focus)
           
 void setFocus(String focus)
           
 void setGlobal(String name, Object value)
          Set a specific piece of global in this working memory.
 void setGlobalResolver(GlobalResolver globalResolver)
          Delegate used to resolve any global names not found in the global map.
 IProcessInstance startProcess(String processId)
          Starts a new process instance for the process with the given id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES

protected static final Class[] ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES

id

protected final long id

addRemovePropertyChangeListenerArgs

protected final Object[] addRemovePropertyChangeListenerArgs
The arguments used when adding/removing a property change listener.


nodeMemories

protected final PrimitiveLongMap nodeMemories
The actual memory for the JoinNodes.


globals

protected final Map globals
Global values which are associated with this memory.


queryResults

protected Map queryResults

globalResolver

protected GlobalResolver globalResolver

NULL

protected static final Object NULL

workingMemoryEventSupport

protected final WorkingMemoryEventSupport workingMemoryEventSupport
The eventSupport


agendaEventSupport

protected final AgendaEventSupport agendaEventSupport

ruleBase

protected transient InternalRuleBase ruleBase
The RuleBase with which this memory is associated.


handleFactory

protected final FactHandleFactory handleFactory

tms

protected final TruthMaintenanceSystem tms

agenda

protected DefaultAgenda agenda
Rule-firing agenda.


actionQueue

protected final List actionQueue

lock

protected final ReentrantLock lock

discardOnLogicalOverride

protected final boolean discardOnLogicalOverride

propagationIdCounter

protected long propagationIdCounter

firing

protected boolean firing
Flag to determine if a rule is currently being fired.

Constructor Detail

AbstractWorkingMemory

public AbstractWorkingMemory(int id,
                             InternalRuleBase ruleBase,
                             FactHandleFactory handleFactory)
Construct.

Parameters:
ruleBase - The backing rule-base.
Method Detail

addEventListener

public void addEventListener(WorkingMemoryEventListener listener)
Description copied from interface: WorkingMemory
Add an event listener.

Specified by:
addEventListener in interface WorkingMemory
Parameters:
listener - The listener to add.

removeEventListener

public void removeEventListener(WorkingMemoryEventListener listener)
Description copied from interface: WorkingMemory
Remove an event listener.

Specified by:
removeEventListener in interface WorkingMemory
Parameters:
listener - The listener to remove.

getWorkingMemoryEventListeners

public List getWorkingMemoryEventListeners()
Description copied from interface: WorkingMemory
Returns all event listeners.

Specified by:
getWorkingMemoryEventListeners in interface EventSupport
Specified by:
getWorkingMemoryEventListeners in interface WorkingMemory
Returns:
listeners The listeners.

addEventListener

public void addEventListener(AgendaEventListener listener)
Description copied from interface: WorkingMemory
Add an event listener.

Specified by:
addEventListener in interface WorkingMemory
Parameters:
listener - The listener to add.

removeEventListener

public void removeEventListener(AgendaEventListener listener)
Description copied from interface: WorkingMemory
Remove an event listener.

Specified by:
removeEventListener in interface WorkingMemory
Parameters:
listener - The listener to remove.

getAgendaEventListeners

public List getAgendaEventListeners()
Description copied from interface: WorkingMemory
Returns all event listeners.

Specified by:
getAgendaEventListeners in interface EventSupport
Specified by:
getAgendaEventListeners in interface WorkingMemory
Returns:
listeners The listeners.

getFactHandleFactory

public FactHandleFactory getFactHandleFactory()
Specified by:
getFactHandleFactory in interface InternalWorkingMemory

getGlobals

public Map getGlobals()
Description copied from interface: WorkingMemory
Retrieve all of the set application data in this memory

Specified by:
getGlobals in interface WorkingMemory
Returns:
the application data as a Map
See Also:
WorkingMemory

setGlobal

public void setGlobal(String name,
                      Object value)
Description copied from interface: WorkingMemory
Set a specific piece of global in this working memory. Null values will return doing nothign

Specified by:
setGlobal in interface WorkingMemory
Parameters:
name - the name under which to populate the data
value - the global value, cannot be null
See Also:
WorkingMemory

setGlobalResolver

public void setGlobalResolver(GlobalResolver globalResolver)
Description copied from interface: WorkingMemory
Delegate used to resolve any global names not found in the global map.

Specified by:
setGlobalResolver in interface WorkingMemory

getId

public long getId()
Specified by:
getId in interface InternalWorkingMemory

getGlobal

public Object getGlobal(String name)
Description copied from interface: WorkingMemory
Retrieve a specific piece of global data by name

Specified by:
getGlobal in interface WorkingMemory
Returns:
application data or null if nothing is set under this name
See Also:
WorkingMemory

getAgenda

public Agenda getAgenda()
Retrieve the rule-firing Agenda for this WorkingMemory.

Specified by:
getAgenda in interface WorkingMemory
Returns:
The Agenda.

clearAgenda

public void clearAgenda()
Clear the Agenda

Specified by:
clearAgenda in interface WorkingMemory

clearAgendaGroup

public void clearAgendaGroup(String group)
Clear the Agenda Group

Specified by:
clearAgendaGroup in interface WorkingMemory

getRuleBase

public RuleBase getRuleBase()
Description copied from interface: WorkingMemory
Retrieve the RuleBase of this working memory.

Specified by:
getRuleBase in interface WorkingMemory
Returns:
The RuleBase.
See Also:
WorkingMemory

fireAllRules

public void fireAllRules()
                  throws FactException
Description copied from interface: WorkingMemory
Fire all items on the agenda until empty.

Specified by:
fireAllRules in interface WorkingMemory
Throws:
FactException - If an error occurs.
See Also:
WorkingMemory

fireAllRules

public void fireAllRules(AgendaFilter agendaFilter)
                  throws FactException
Description copied from interface: WorkingMemory
Fire all items on the agenda until empty, using the given AgendaFiler

Specified by:
fireAllRules in interface WorkingMemory
Throws:
FactException - If an error occurs.

getObject

public Object getObject(FactHandle handle)
Returns the fact Object for the given FactHandle. It actually attemps to return the value from the handle, before retrieving it from objects map.

Specified by:
getObject in interface WorkingMemory
Parameters:
handle - The FactHandle reference for the Object lookup
Returns:
The associated object.
See Also:
WorkingMemory

getFactHandle

public FactHandle getFactHandle(Object object)
Description copied from interface: WorkingMemory
Retrieve the FactHandle associated with an Object.

Specified by:
getFactHandle in interface WorkingMemory
Parameters:
object - The object.
Returns:
The associated fact handle.
See Also:
WorkingMemory

getFactHandleMap

public ObjectHashMap getFactHandleMap()
This is an internal method, used to avoid java.util.Iterator adaptors

Specified by:
getFactHandleMap in interface InternalWorkingMemory

iterateObjects

public Iterator iterateObjects()
This class is not thread safe, changes to the working memory during iteration may give unexpected results

Specified by:
iterateObjects in interface WorkingMemory

iterateObjects

public Iterator iterateObjects(ObjectFilter filter)
This class is not thread safe, changes to the working memory during iteration may give unexpected results

Specified by:
iterateObjects in interface WorkingMemory

iterateFactHandles

public Iterator iterateFactHandles()
This class is not thread safe, changes to the working memory during iteration may give unexpected results

Specified by:
iterateFactHandles in interface WorkingMemory

iterateFactHandles

public Iterator iterateFactHandles(ObjectFilter filter)
This class is not thread safe, changes to the working memory during iteration may give unexpected results

Specified by:
iterateFactHandles in interface WorkingMemory

getQueryResults

public abstract QueryResults getQueryResults(String query)
Description copied from interface: WorkingMemory
Retrieve the QueryResults of the specified query.

Specified by:
getQueryResults in interface WorkingMemory
Parameters:
query - The name of the query.
Returns:
The QueryResults of the specified query. If no results match the query it is empty.

getFocus

public AgendaGroup getFocus()
Specified by:
getFocus in interface WorkingMemory

setFocus

public void setFocus(String focus)
Specified by:
setFocus in interface WorkingMemory

setFocus

public void setFocus(AgendaGroup focus)
Specified by:
setFocus in interface WorkingMemory

getTruthMaintenanceSystem

public TruthMaintenanceSystem getTruthMaintenanceSystem()
Specified by:
getTruthMaintenanceSystem in interface InternalWorkingMemory

assertObject

public FactHandle assertObject(Object object)
                        throws FactException
Description copied from interface: WorkingMemory
Assert a fact.

Specified by:
assertObject in interface WorkingMemory
Parameters:
object - The fact object.
Returns:
The new fact-handle associated with the object.
Throws:
FactException - If an error occurs.
See Also:
WorkingMemory

assertLogicalObject

public FactHandle assertLogicalObject(Object object)
                               throws FactException
Throws:
FactException
See Also:
WorkingMemory

assertObject

public FactHandle assertObject(Object object,
                               boolean dynamic)
                        throws FactException
Description copied from interface: WorkingMemory
Assert a fact registering JavaBean PropertyChangeListeners on the Object to automatically trigger modifyObject calls if dynamic is true.

Specified by:
assertObject in interface WorkingMemory
Parameters:
object - The fact object.
dynamic - true if Drools should add JavaBean PropertyChangeListeners to the object.
Returns:
The new fact-handle associated with the object.
Throws:
FactException - If an error occurs.

assertLogicalObject

public FactHandle assertLogicalObject(Object object,
                                      boolean dynamic)
                               throws FactException
Specified by:
assertLogicalObject in interface InternalWorkingMemoryActions
Throws:
FactException

assertObject

public FactHandle assertObject(Object object,
                               boolean dynamic,
                               boolean logical,
                               Rule rule,
                               Activation activation)
                        throws FactException
Specified by:
assertObject in interface InternalWorkingMemoryActions
Throws:
FactException

addPropertyChangeListener

protected void addPropertyChangeListener(Object object)

doAssertObject

public abstract void doAssertObject(InternalFactHandle factHandle,
                                    Object object,
                                    PropagationContext propagationContext)
                             throws FactException
Throws:
FactException

removePropertyChangeListener

protected void removePropertyChangeListener(FactHandle handle)
                                     throws NoSuchFactObjectException
Throws:
NoSuchFactObjectException

retractObject

public void retractObject(FactHandle handle)
                   throws FactException
Description copied from interface: WorkingMemory
Retract a fact.

Specified by:
retractObject in interface WorkingMemory
Parameters:
handle - The fact-handle associated with the fact to retract.
Throws:
FactException - If an error occurs.

doRetract

public abstract void doRetract(InternalFactHandle factHandle,
                               PropagationContext propagationContext)

retractObject

public void retractObject(FactHandle factHandle,
                          boolean removeLogical,
                          boolean updateEqualsMap,
                          Rule rule,
                          Activation activation)
                   throws FactException
Specified by:
retractObject in interface InternalWorkingMemory
Specified by:
retractObject in interface InternalWorkingMemoryActions
Throws:
FactException
See Also:
WorkingMemory

modifyObject

public void modifyObject(FactHandle handle,
                         Object object)
                  throws FactException
Description copied from interface: WorkingMemory
Modify a fact.

Specified by:
modifyObject in interface WorkingMemory
Parameters:
handle - The fact-handle associated with the fact to modify.
object - The new value of the fact.
Throws:
FactException - If an error occurs.

modifyObject

public void modifyObject(FactHandle factHandle,
                         Object object,
                         Rule rule,
                         Activation activation)
                  throws FactException
modify is implemented as half way retract / assert due to the truth maintenance issues.

Specified by:
modifyObject in interface InternalWorkingMemoryActions
Throws:
FactException
See Also:
WorkingMemory

executeQueuedActions

public void executeQueuedActions()
Specified by:
executeQueuedActions in interface InternalWorkingMemory

queueWorkingMemoryAction

public void queueWorkingMemoryAction(WorkingMemoryAction action)
Specified by:
queueWorkingMemoryAction in interface InternalWorkingMemory

removeLogicalDependencies

public void removeLogicalDependencies(Activation activation,
                                      PropagationContext context,
                                      Rule rule)
                               throws FactException
Specified by:
removeLogicalDependencies in interface InternalWorkingMemory
Throws:
FactException

getNodeMemory

public Object getNodeMemory(NodeMemory node)
Retrieve the JoinMemory for a particular JoinNode.

Specified by:
getNodeMemory in interface InternalWorkingMemory
Parameters:
node - The JoinNode key.
Returns:
The node's memory.

clearNodeMemory

public void clearNodeMemory(NodeMemory node)
Specified by:
clearNodeMemory in interface InternalWorkingMemory

getWorkingMemoryEventSupport

public WorkingMemoryEventSupport getWorkingMemoryEventSupport()

getAgendaEventSupport

public AgendaEventSupport getAgendaEventSupport()
Specified by:
getAgendaEventSupport in interface EventSupport
Specified by:
getAgendaEventSupport in interface InternalWorkingMemory

setAsyncExceptionHandler

public void setAsyncExceptionHandler(AsyncExceptionHandler handler)
Sets the AsyncExceptionHandler to handle exceptions thrown by the Agenda Scheduler used for duration rules.

Specified by:
setAsyncExceptionHandler in interface WorkingMemory
Parameters:
handler -

propertyChange

public void propertyChange(PropertyChangeEvent event)
Specified by:
propertyChange in interface PropertyChangeListener

getNextPropagationIdCounter

public long getNextPropagationIdCounter()
Specified by:
getNextPropagationIdCounter in interface InternalWorkingMemory

getLock

public Lock getLock()
Specified by:
getLock in interface InternalWorkingMemory

startProcess

public IProcessInstance startProcess(String processId)
Description copied from interface: WorkingMemory
Starts a new process instance for the process with the given id.

Specified by:
startProcess in interface WorkingMemory

iterateObjectsToList

public List iterateObjectsToList()


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