|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.hammurapi.config.ComponentBase
biz.hammurapi.rules.AbstractRule
biz.hammurapi.rules.Rule
public class Rule
Base class for rules.
Nested Class Summary | |
---|---|
static interface |
Rule.AcceptInfo
Instances of this interface are passed to accept() methods as second parameter. |
static interface |
Rule.ChangeDetector
Interface to detect changes in arguments passed to inference methods. |
Field Summary |
---|
Fields inherited from class biz.hammurapi.config.ComponentBase |
---|
owner |
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 | |
---|---|
|
Rule()
Default constructor. |
protected |
Rule(java.lang.String inferMethodName,
java.lang.String removeMethodName,
java.lang.String acceptMethodName)
|
Method Summary | |
---|---|
long |
getInvocationCounter()
|
java.util.Collection |
getInvocationHandlers()
|
java.util.Collection |
getRemoveHandlers()
|
protected Rule.ChangeDetector |
newChangeDetector(java.lang.Object obj)
Creates default change detector, which detects changes in versioned and observable objects. |
protected void |
post(java.lang.Object fact)
Adds new fact to knowledge base. |
protected void |
remove(java.lang.Object fact)
Invokes remove method of the knowledge base and adds trace action. |
void |
reset()
Invoked in rule session reset() method. |
protected long |
resetInvocationCounter()
Resets invocation counter. |
protected void |
setMethodFactTypes(java.lang.Class[] parameterTypes,
java.lang.Class factType)
Convenience method, delegates to setMethodFactTypes(Class[] parameterTypes, Class[] factTypes) |
protected void |
setMethodFactTypes(java.lang.Class[] parameterTypes,
java.lang.Class[] factTypes)
Rule methods can return facts and post facts. |
protected void |
setMethodFactTypes(java.lang.Class parameterType,
java.lang.Class factType)
Convenience method, delegates to setMethodFactTypes(Class[] parameterTypes, Class[] factTypes) |
protected void |
setMethodFactTypes(java.lang.Class parameterType,
java.lang.Class[] factTypes)
Convenience method, delegates to setMethodFactTypes(Class[] parameterTypes, Class[] factTypes) |
void |
start()
Locates collection manager. |
protected void |
update(java.lang.Object fact)
Invokes update method of the knowledge base and adds trace action. |
Methods inherited from class biz.hammurapi.rules.AbstractRule |
---|
getCollection, getDescription, getName, setDescription, setName, stop, toString |
Methods inherited from class biz.hammurapi.config.ComponentBase |
---|
addMeasurement, get, getChild, getMeasurementConsumer, getOwner, getOwner, setMeasurementConsumer, setOwner |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Rule()
protected Rule(java.lang.String inferMethodName, java.lang.String removeMethodName, java.lang.String acceptMethodName)
inferMethodName
- Methods with this name and one or more arguments are invoked when an object of type
compatible with one of parameters is posted to the object bus.removeMethodName
- Single-argument methods with this name will be invoked when rule set's remove
method with compatible type is invoked. Generally rules shall not implement this method because collection
manager and handle manager take care of removal of the object and conclusions made based on this object from
the knowledge base.acceptMethodName
- Methods with this name and two arguments - the first of equal type and the second
of AcceptInfo
type are used to filter inputs to infer methods with more than one parameter.
Type of the first argument of accept
method and corresponding argument of infer
must be equal. accept()
method's return type must be boolean
.Method Detail |
---|
protected Rule.ChangeDetector newChangeDetector(java.lang.Object obj)
obj
-
public long getInvocationCounter()
public void start() throws biz.hammurapi.config.ConfigurationException
start
in interface biz.hammurapi.config.Component
start
in class AbstractRule
biz.hammurapi.config.ConfigurationException
public java.util.Collection getInvocationHandlers()
public java.util.Collection getRemoveHandlers()
getRemoveHandlers
in class AbstractRule
protected void post(java.lang.Object fact)
fact
- protected void remove(java.lang.Object fact)
protected void update(java.lang.Object fact)
public void reset()
AbstractRule
reset
in class AbstractRule
protected long resetInvocationCounter()
protected final void setMethodFactTypes(java.lang.Class[] parameterTypes, java.lang.Class[] factTypes)
post()
.
Also, return type might not be enough, as returned instances may implement
interfaces which other rules are interested in, but which are not declared
in the rule return type.
This method allows rules to inform the inference system about posted types.
This method shall be invoked before rule is started. Place invocations of this method in rule constructors.
Only rules used in backward reasoning need/must call this method to ensure proper reasoning. For methods without fact types information set through this method, the rule system uses method return type.
parameterTypes
- Reasoning method parameter types. Method name is not
required as it is known.factTypes
- Fact types produced by given reasoning (inference) method.
If rule method returns facts as well as posts them, then method return type
must be included in the factTypes array.protected final void setMethodFactTypes(java.lang.Class parameterType, java.lang.Class[] factTypes)
setMethodFactTypes(Class[] parameterTypes, Class[] factTypes)
parameterType
- factTypes
- protected final void setMethodFactTypes(java.lang.Class parameterType, java.lang.Class factType)
setMethodFactTypes(Class[] parameterTypes, Class[] factTypes)
parameterType
- factTypes
- protected final void setMethodFactTypes(java.lang.Class[] parameterTypes, java.lang.Class factType)
setMethodFactTypes(Class[] parameterTypes, Class[] factTypes)
parameterType
- factTypes
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |