biz.hammurapi.rules.backwardreasoning
Class BackwardReasoningRulesContainer

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.backwardreasoning.BackwardReasoningRulesContainer
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, FactSource, biz.hammurapi.util.Attributable, biz.hammurapi.util.Searchable, biz.hammurapi.util.Visitable
Direct Known Subclasses:
NoDuplicatesBackwardReasoningRulesContainer

public class BackwardReasoningRulesContainer
extends biz.hammurapi.config.DomConfigurableContainer
implements Constants, FactSource

Backward reasoning rules container. How to use:

  1. Instantiate from XML definition.
  2. Set collection manager if rule set contains join rules (inference methods with more than one parameter).
  3. Set worker for concurrent reasoning. (Optional)
  4. Set exception sink. Otherwise all exceptions will be reported to the logger. (Optional)
  5. Set fact sources.
  6. Invoke getFacts() for fact/conclusion type of interest.

Author:
Pavel Vlasov

Field Summary
protected  int maxPass
           
 
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
BackwardReasoningRulesContainer()
           
 
Method Summary
 void addFactSource(FactSource factSource)
          Sets single fact source.
 void addFactSources(java.util.Collection factSources)
          Sets multiple fact sources.
protected  Accumulator createAccumulator(java.lang.Class type)
          This implementation creates simple accumulator which doesn't eliminate duplicates.
protected  java.lang.String getComponentName(org.w3c.dom.Node node)
           
 java.util.Iterator getFacts(java.lang.Class factType)
          If there is exact match, returns iterator for that match, combines subclasses otherwise.
 java.lang.Class[] getFactTypes()
           
 java.util.Collection getRules()
           
 void join()
          This method blocks until all reasoning jobs finish execution.
protected  void onAccumulatorBlock()
           
 void setCollectionManager(CollectionManager collectionManager)
          Collection manager is required for join (multi-parameter) rules.
 void setExceptionSink(biz.hammurapi.util.ExceptionSink exceptionSink)
          Exception sink to consume exceptions during reasoning.
 void setMaxWorkerJobs(int maxWorkerJobs)
          When concurrent reasoning is used, deadlocks are possible depending on worker implementation/configuration.
 void setWorker(biz.hammurapi.util.Worker worker)
          Set worker for concurrent reasoning.
 void start()
           
 
Methods inherited from class biz.hammurapi.config.DomConfigurableContainer
configure
 
Methods inherited from class biz.hammurapi.config.GenericContainer
acceptChildren, addComponent, addMeasurement, execute, get, getAttribute, getComponentMap, getComponentNames, getComponents, getMeasurementConsumer, getOwner, removeAttribute, setAttribute, setMeasurementConsumer, setOwner, stop
 
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
 

Field Detail

maxPass

protected int maxPass
Constructor Detail

BackwardReasoningRulesContainer

public BackwardReasoningRulesContainer()
Method Detail

addFactSource

public void addFactSource(FactSource factSource)
Sets single fact source. Resets reasoning results.

Parameters:
factSource -

setExceptionSink

public void setExceptionSink(biz.hammurapi.util.ExceptionSink exceptionSink)
Exception sink to consume exceptions during reasoning. If exception sink is not set, exceptions are sent to logger.

Parameters:
exceptionSink -

setMaxWorkerJobs

public void setMaxWorkerJobs(int maxWorkerJobs)
When concurrent reasoning is used, deadlocks are possible depending on worker implementation/configuration. If excessive jobs are queued, a situation is possible when all active type jobs wait for a job in a queue to complete and that job never gets to execution. Setting maxWorkerJobs to value greater than zero will limit number of concurrent jobs posted to worker. Excessive jobs will be executed in invoking thread, to avoid being queued by the worker.

Parameters:
maxWorkerJobs -

addFactSources

public void addFactSources(java.util.Collection factSources)
Sets multiple fact sources. Resets reasoning results.

Parameters:
factSources -

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

setCollectionManager

public void setCollectionManager(CollectionManager collectionManager)
                          throws biz.hammurapi.config.ConfigurationException
Collection manager is required for join (multi-parameter) rules.

Parameters:
collectionManager -
Throws:
biz.hammurapi.config.ConfigurationException

setWorker

public void setWorker(biz.hammurapi.util.Worker worker)
Set worker for concurrent reasoning. E.g. if rules access database or network resources for different types of facts, retrieval of these facts can be done in parallel.

Parameters:
worker -

getRules

public java.util.Collection getRules()

getComponentName

protected java.lang.String getComponentName(org.w3c.dom.Node node)
Specified by:
getComponentName in class biz.hammurapi.config.DomConfigurableContainer

join

public void join()
          throws java.lang.InterruptedException
This method blocks until all reasoning jobs finish execution. If worker is not set, this method returns immediately.

Throws:
java.lang.InterruptedException

getFacts

public java.util.Iterator getFacts(java.lang.Class factType)
If there is exact match, returns iterator for that match, combines subclasses otherwise.

Specified by:
getFacts in interface FactSource
Returns:
Iterator over facts of requested type.

createAccumulator

protected Accumulator createAccumulator(java.lang.Class type)
This implementation creates simple accumulator which doesn't eliminate duplicates. If several rules come to the same conclusion, these conclusions will not be merged. Override this method to produce accumulator which eliminates duplicates and merges conclusions.

Parameters:
producers -
Returns:

onAccumulatorBlock

protected void onAccumulatorBlock()

getFactTypes

public java.lang.Class[] getFactTypes()
Specified by:
getFactTypes in interface FactSource
Returns:
Fact types provided by this source.


Copyright © 2005 Hammurapi Group. All Rights Reserved.