Class ReteNode
- java.lang.Object
-
- jadex.rules.rulesystem.rete.nodes.AbstractNode
-
- jadex.rules.rulesystem.rete.nodes.ReteNode
-
- All Implemented Interfaces:
INode,IObjectSourceNode,java.lang.Cloneable
public class ReteNode extends AbstractNode implements IObjectSourceNode
ReteNode implementation of the IConditionSystem.
-
-
Field Summary
Fields Modifier and Type Field Description protected ReteBuilderbuilderThe rete builder.protected intchangecntprotected booleancheckDo a consistency check after each state change (requires asserts).protected java.util.Listcheckedprotected java.util.MapindirectnodesetsIndirectly affected nodes for an attribute type (cached for speed).protected booleaninitedFor debugging: node is inited and network must not be changed anymore.protected InitialFactNodeinitialfactThe initial fact node (if any).protected intnodecounterThe node counter in this network.protected AttributeSetrelevantsThe set of relevant attributes.protected java.util.MapterminalnodesThe terminal nodes (IRule -> Node).protected java.util.MaptypenodesThe type nodes.protected java.util.MaptypenodesetsMatching nodes for each (sub)type (cached for speed).-
Fields inherited from class jadex.rules.rulesystem.rete.nodes.AbstractNode
clones, nodeid
-
-
Constructor Summary
Constructors Constructor Description ReteNode()Create a new rete system.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObject(java.lang.Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a new object in the state.voidaddObjectConsumer(IObjectConsumerNode node)Add an object consumer node.voidaddRule(IRule rule)Add a rule to the network.protected booleancheckConsistency(ReteMemory mem)Check consistency of Rete network/memory.java.lang.ObjectcreateNodeMemory(IOAVState state)Create the node memory.protected voiddoClone(java.lang.Object theclone)Do clone makes a deep clone without regarding cycles.ReteBuildergetBuilder()Get the builder.AttributeSetgetIndirectAttributes()Get the set of indirect attribute types.protected java.util.SetgetIndirectNodes(OAVAttributeType attrtype, OAVTypeModel tmodel)Get the set of indirectly affected nodes for an attribute type.InitialFactNodegetInitialFactNode()Get the initial fact node (if any).intgetNextNodeId()Get the next nodecounter.intgetNodeCount()Get the number of nodes in the network.java.util.CollectiongetNodeMemory(ReteMemory mem)Get the memory for this node.IObjectConsumerNode[]getObjectConsumers()Get all object consumer nodes.AttributeSetgetRelevantAttributes()Get the set of relevant attribute types.TerminalNodegetTerminalNode(IRule rule)Set the terminal node for a rule.TypeNodegetTypeNode(OAVObjectType type)Get the node for a type.protected java.util.SetgetTypeNodes(OAVObjectType type)Get the set of matching type nodes for a (sub)type.voidmodifyIndirectObject(java.lang.Object object, OAVAttributeType type, java.lang.Object oldvalue, java.lang.Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Propagate an indirect object change to this node.voidmodifyObject(java.lang.Object id, OAVObjectType type, OAVAttributeType attr, java.lang.Object oldvalue, java.lang.Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a modified object in the state.voidputTerminalNode(TerminalNode node)Set the terminal node for a rule.voidremoveObject(java.lang.Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a removed object in the state.voidremoveObjectConsumer(IObjectConsumerNode node)Remove an object consumer.voidremoveRule(IRule rule)Remove a rule from the network.voidsetInited(boolean inited)Set the inited state.-
Methods inherited from class jadex.rules.rulesystem.rete.nodes.AbstractNode
checkNodeConsistency, clone, equals, getNodeId, hashCode, toString, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jadex.rules.rulesystem.rete.nodes.INode
checkNodeConsistency, clone, getNodeId
-
-
-
-
Field Detail
-
typenodes
protected java.util.Map typenodes
The type nodes.
-
typenodesets
protected java.util.Map typenodesets
Matching nodes for each (sub)type (cached for speed).
-
indirectnodesets
protected volatile java.util.Map indirectnodesets
Indirectly affected nodes for an attribute type (cached for speed).
-
initialfact
protected InitialFactNode initialfact
The initial fact node (if any).
-
terminalnodes
protected java.util.Map terminalnodes
The terminal nodes (IRule -> Node).
-
builder
protected ReteBuilder builder
The rete builder.
-
relevants
protected volatile AttributeSet relevants
The set of relevant attributes.
-
check
protected boolean check
Do a consistency check after each state change (requires asserts).
-
nodecounter
protected int nodecounter
The node counter in this network.
-
inited
protected boolean inited
For debugging: node is inited and network must not be changed anymore.
-
changecnt
protected int changecnt
-
checked
protected java.util.List checked
-
-
Method Detail
-
addObject
public void addObject(java.lang.Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a new object in the state.- Parameters:
object- The new object.
-
removeObject
public void removeObject(java.lang.Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a removed object in the state.- Parameters:
object- The removed object.
-
modifyObject
public void modifyObject(java.lang.Object id, OAVObjectType type, OAVAttributeType attr, java.lang.Object oldvalue, java.lang.Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Tell the condition system about a modified object in the state.- Parameters:
object- The new object.
-
modifyIndirectObject
public void modifyIndirectObject(java.lang.Object object, OAVAttributeType type, java.lang.Object oldvalue, java.lang.Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda)Propagate an indirect object change to this node.- Specified by:
modifyIndirectObjectin interfaceINode- Parameters:
object- The changed object.
-
addRule
public void addRule(IRule rule)
Add a rule to the network.- Parameters:
rule- The rule to add.
-
removeRule
public void removeRule(IRule rule)
Remove a rule from the network.- Parameters:
rule- The rule to remove.
-
putTerminalNode
public void putTerminalNode(TerminalNode node)
Set the terminal node for a rule.- Parameters:
rule- The rule.node- The node.
-
getTerminalNode
public TerminalNode getTerminalNode(IRule rule)
Set the terminal node for a rule.- Parameters:
rule- The rule.node- The node.
-
getNodeCount
public int getNodeCount()
Get the number of nodes in the network.- Returns:
- The number of nodes.
-
addObjectConsumer
public void addObjectConsumer(IObjectConsumerNode node)
Add an object consumer node.- Specified by:
addObjectConsumerin interfaceIObjectSourceNode- Parameters:
node- A new consumer node.
-
removeObjectConsumer
public void removeObjectConsumer(IObjectConsumerNode node)
Remove an object consumer.- Specified by:
removeObjectConsumerin interfaceIObjectSourceNode- Parameters:
node- The consumer node.
-
getNodeMemory
public java.util.Collection getNodeMemory(ReteMemory mem)
Get the memory for this node.- Specified by:
getNodeMemoryin interfaceINode- Specified by:
getNodeMemoryin interfaceIObjectSourceNode- Returns:
- The memory.
-
getObjectConsumers
public IObjectConsumerNode[] getObjectConsumers()
Get all object consumer nodes.- Specified by:
getObjectConsumersin interfaceIObjectSourceNode- Returns:
- All object consumer nodes.
-
getTypeNode
public TypeNode getTypeNode(OAVObjectType type)
Get the node for a type.- Parameters:
type- The type.- Returns:
- The type node (if any).
-
getInitialFactNode
public InitialFactNode getInitialFactNode()
Get the initial fact node (if any).
-
createNodeMemory
public java.lang.Object createNodeMemory(IOAVState state)
Create the node memory.- Specified by:
createNodeMemoryin interfaceINode- Parameters:
state- The state.- Returns:
- The node memory.
-
getRelevantAttributes
public AttributeSet getRelevantAttributes()
Get the set of relevant attribute types.- Specified by:
getRelevantAttributesin interfaceINode
-
getIndirectAttributes
public AttributeSet getIndirectAttributes()
Get the set of indirect attribute types. I.e. attributes of objects, which are not part of an object conditions (e.g. for chained extractors)- Specified by:
getIndirectAttributesin interfaceINode- Returns:
- The relevant attribute types.
-
getBuilder
public ReteBuilder getBuilder()
Get the builder.- Returns:
- The rete builder.
-
getTypeNodes
protected java.util.Set getTypeNodes(OAVObjectType type)
Get the set of matching type nodes for a (sub)type.- Parameters:
type- The object type.- Returns:
- The set of type nodes for that object type.
-
getIndirectNodes
protected java.util.Set getIndirectNodes(OAVAttributeType attrtype, OAVTypeModel tmodel)
Get the set of indirectly affected nodes for an attribute type.- Parameters:
attrtype- The attribute type.tmodel- The OAV type model.- Returns:
- The set of indirectly affected nodes for that attribute type.
-
doClone
protected void doClone(java.lang.Object theclone)
Do clone makes a deep clone without regarding cycles.- Specified by:
doClonein classAbstractNode- Parameters:
clone- The clone.
-
checkConsistency
protected boolean checkConsistency(ReteMemory mem)
Check consistency of Rete network/memory. For debugging. Only performs some simple checks and does not assure complete consistency.
-
getNextNodeId
public int getNextNodeId()
Get the next nodecounter.- Returns:
- The id for the next node.
-
setInited
public void setInited(boolean inited)
Set the inited state.
-
-