biz.hammurapi.rules
Class QueueingRulesContainer

java.lang.Object
  extended by biz.hammurapi.util.VisitableBase
      extended by biz.hammurapi.config.GenericContainer
          extended by biz.hammurapi.config.DomConfigurableContainer
              extended by biz.hammurapi.rules.RulesContainerBase
                  extended by biz.hammurapi.rules.QueueingRulesContainer
All Implemented Interfaces:
biz.hammurapi.config.Command, biz.hammurapi.config.Component, biz.hammurapi.config.Context, biz.hammurapi.config.DomConfigurable, biz.hammurapi.metrics.MeasurementCollector, biz.hammurapi.metrics.MeasurementConsumer, Constants, KnowledgeBase, biz.hammurapi.util.Attributable, biz.hammurapi.util.Searchable, biz.hammurapi.util.Visitable

public class QueueingRulesContainer
extends RulesContainerBase
implements Constants

This rules container uses QueuingDispatcher and negation semantics for remove(). It can also leverage worker (thread pool) provided in worker-ref attribute for multithreaded inference. This container also uses loop detection.

Author:
Pavel Vlasov

Nested Class Summary
 
Nested classes/interfaces inherited from interface biz.hammurapi.rules.KnowledgeBase
KnowledgeBase.KnowledgeBaseCommand
 
Field Summary
 
Fields inherited from interface biz.hammurapi.rules.Constants
COLLECTION_MANAGER, DESCRIPTION, HANDLE_MANAGER, KNOWLEDGE_COMPACTOR, NAME, NEGATOR_CLASS, OBJECT_FILTER, RETAIN_NEGATORS, RULES, URI_DIRECT, URI_PROPERTY, WORKER_REF
 
Constructor Summary
QueueingRulesContainer()
           
 
Method Summary
 void add(java.lang.Object obj)
          Adds object to handle manager and dispatches to rules.
protected  boolean checkLoop(java.lang.Object object)
          Checks recent conclusions and derivation depth to discard conclusions which came through dispatching too many times or conclusions with too big depth.
 void configure(org.w3c.dom.Node configNode, biz.hammurapi.config.Context context, java.lang.ClassLoader classLoader)
           
 void executeRules()
          Invokes dispatcher's join() to wait until all jobs are finished.
protected  java.util.Collection getObjectActions(java.lang.Object obj)
          Returns actions performed when object was added to the database.
 java.util.Collection getRules()
           
protected  Negator newNegator(java.lang.Object obj)
          Instantiates new negator.
protected  void onDiscardedConclusion(Conclusion conclusion)
          Conclusions discarded because their derivation depth is too big are passed to this method.
protected  void onDispatchException(DispatchException exception)
          Consumes DispatchException.
 void remove(java.lang.Object obj)
          Removes object from handle manager and recent facts.
 void reset()
          Resets rules state (if any).
 void start()
           
 void stop()
           
 
Methods inherited from class biz.hammurapi.rules.RulesContainerBase
getComponentName
 
Methods inherited from class biz.hammurapi.config.GenericContainer
acceptChildren, addComponent, addMeasurement, execute, get, getAttribute, getComponentMap, getComponentNames, getComponents, getMeasurementConsumer, getOwner, removeAttribute, setAttribute, setMeasurementConsumer, setOwner
 
Methods inherited from class biz.hammurapi.util.VisitableBase
accept, convert2searchable, find, findAll, object2visitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueueingRulesContainer

public QueueingRulesContainer()
Method Detail

add

public void add(java.lang.Object obj)
Adds object to handle manager and dispatches to rules. If the object is instance of Negator then it is presented to collection manager.

Specified by:
add in interface KnowledgeBase

onDispatchException

protected void onDispatchException(DispatchException exception)
Consumes DispatchException. This implementation just prints stack trace. Override if needed.

Parameters:
exception -

checkLoop

protected boolean checkLoop(java.lang.Object object)
Checks recent conclusions and derivation depth to discard conclusions which came through dispatching too many times or conclusions with too big depth.

Parameters:
object -
Returns:
true if there is no loop

onDiscardedConclusion

protected void onDiscardedConclusion(Conclusion conclusion)
Conclusions discarded because their derivation depth is too big are passed to this method. The method does nothing. Override as needed.

Parameters:
conclusion -

remove

public void remove(java.lang.Object obj)
Removes object from handle manager and recent facts. Then creates a negator, negates facts in collection manager and then dispatches the object to remove methods. Subclasses implementing ActionTracing undo actions instead of using a negator.

Specified by:
remove in interface KnowledgeBase

getObjectActions

protected java.util.Collection getObjectActions(java.lang.Object obj)
Returns actions performed when object was added to the database. This method must be overriden by subclasses which implement ActionTracer.

Parameters:
obj -
Returns:

newNegator

protected Negator newNegator(java.lang.Object obj)
Instantiates new negator.

Parameters:
obj -
Returns:

executeRules

public void executeRules()
Invokes dispatcher's join() to wait until all jobs are finished.

Specified by:
executeRules in interface KnowledgeBase

configure

public void configure(org.w3c.dom.Node configNode,
                      biz.hammurapi.config.Context context,
                      java.lang.ClassLoader classLoader)
               throws biz.hammurapi.config.ConfigurationException
Specified by:
configure in interface biz.hammurapi.config.DomConfigurable
Overrides:
configure in class biz.hammurapi.config.DomConfigurableContainer
Throws:
biz.hammurapi.config.ConfigurationException

start

public void start()
           throws biz.hammurapi.config.ConfigurationException
Specified by:
start in interface biz.hammurapi.config.Component
Overrides:
start in class biz.hammurapi.config.GenericContainer
Throws:
biz.hammurapi.config.ConfigurationException

stop

public void stop()
          throws biz.hammurapi.config.ConfigurationException
Specified by:
stop in interface biz.hammurapi.config.Component
Overrides:
stop in class biz.hammurapi.config.GenericContainer
Throws:
biz.hammurapi.config.ConfigurationException

reset

public void reset()
Description copied from interface: KnowledgeBase
Resets rules state (if any).

Specified by:
reset in interface KnowledgeBase

getRules

public java.util.Collection getRules()
Specified by:
getRules in interface KnowledgeBase
Returns:
Collection of rule instances in the knowledge base.


Copyright © 2005 Hammurapi Group. All Rights Reserved.