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 ReteBuilder
builder
The rete builder.protected int
changecnt
protected boolean
check
Do a consistency check after each state change (requires asserts).protected java.util.List
checked
protected java.util.Map
indirectnodesets
Indirectly affected nodes for an attribute type (cached for speed).protected boolean
inited
For debugging: node is inited and network must not be changed anymore.protected InitialFactNode
initialfact
The initial fact node (if any).protected int
nodecounter
The node counter in this network.protected AttributeSet
relevants
The set of relevant attributes.protected java.util.Map
terminalnodes
The terminal nodes (IRule -> Node).protected java.util.Map
typenodes
The type nodes.protected java.util.Map
typenodesets
Matching 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 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.void
addObjectConsumer(IObjectConsumerNode node)
Add an object consumer node.void
addRule(IRule rule)
Add a rule to the network.protected boolean
checkConsistency(ReteMemory mem)
Check consistency of Rete network/memory.java.lang.Object
createNodeMemory(IOAVState state)
Create the node memory.protected void
doClone(java.lang.Object theclone)
Do clone makes a deep clone without regarding cycles.ReteBuilder
getBuilder()
Get the builder.AttributeSet
getIndirectAttributes()
Get the set of indirect attribute types.protected java.util.Set
getIndirectNodes(OAVAttributeType attrtype, OAVTypeModel tmodel)
Get the set of indirectly affected nodes for an attribute type.InitialFactNode
getInitialFactNode()
Get the initial fact node (if any).int
getNextNodeId()
Get the next nodecounter.int
getNodeCount()
Get the number of nodes in the network.java.util.Collection
getNodeMemory(ReteMemory mem)
Get the memory for this node.IObjectConsumerNode[]
getObjectConsumers()
Get all object consumer nodes.AttributeSet
getRelevantAttributes()
Get the set of relevant attribute types.TerminalNode
getTerminalNode(IRule rule)
Set the terminal node for a rule.TypeNode
getTypeNode(OAVObjectType type)
Get the node for a type.protected java.util.Set
getTypeNodes(OAVObjectType type)
Get the set of matching type nodes for a (sub)type.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.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.void
putTerminalNode(TerminalNode node)
Set the terminal node for a rule.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.void
removeObjectConsumer(IObjectConsumerNode node)
Remove an object consumer.void
removeRule(IRule rule)
Remove a rule from the network.void
setInited(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:
modifyIndirectObject
in 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:
addObjectConsumer
in interfaceIObjectSourceNode
- Parameters:
node
- A new consumer node.
-
removeObjectConsumer
public void removeObjectConsumer(IObjectConsumerNode node)
Remove an object consumer.- Specified by:
removeObjectConsumer
in interfaceIObjectSourceNode
- Parameters:
node
- The consumer node.
-
getNodeMemory
public java.util.Collection getNodeMemory(ReteMemory mem)
Get the memory for this node.- Specified by:
getNodeMemory
in interfaceINode
- Specified by:
getNodeMemory
in interfaceIObjectSourceNode
- Returns:
- The memory.
-
getObjectConsumers
public IObjectConsumerNode[] getObjectConsumers()
Get all object consumer nodes.- Specified by:
getObjectConsumers
in 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:
createNodeMemory
in interfaceINode
- Parameters:
state
- The state.- Returns:
- The node memory.
-
getRelevantAttributes
public AttributeSet getRelevantAttributes()
Get the set of relevant attribute types.- Specified by:
getRelevantAttributes
in 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:
getIndirectAttributes
in 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:
doClone
in 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.
-
-