Package org.drools.core.reteoo
Class ObjectTypeNode
- java.lang.Object
-
- org.drools.core.common.BaseNode
-
- org.drools.core.reteoo.ObjectSource
-
- org.drools.core.reteoo.ObjectTypeNode
-
- All Implemented Interfaces:
Externalizable
,Serializable
,MemoryFactory<ObjectTypeNode.ObjectTypeNodeMemory>
,NetworkNode
,ObjectSink
,Sink
- Direct Known Subclasses:
ReteObjectTypeNode
,TraitProxyObjectTypeNode
public class ObjectTypeNode extends ObjectSource implements ObjectSink, Externalizable, MemoryFactory<ObjectTypeNode.ObjectTypeNodeMemory>
ObjectTypeNodes
are responsible for filtering and propagating the matching fact assertions propagated from the
Rete
node usingObjectType
interface. The assert and retract methods do not attempt to filter as this is the role of theRete
node which builds up a cache of matchingObjectTypdeNodes
s for each asserted object, using thematches(Object object)
method. Incorrect propagation in these methods is not checked and will result inClassCastExpcections
later on in the network. FiltersObjects
coming from theRete
using aObjectType
semantic module.- See Also:
Rete
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ObjectTypeNode.ExpireJob
static class
ObjectTypeNode.ExpireJobContext
static class
ObjectTypeNode.Id
static class
ObjectTypeNode.InitialFactObjectTypeNodeMemory
static class
ObjectTypeNode.ObjectTypeNodeMemory
-
Field Summary
Fields Modifier and Type Field Description static ObjectTypeNode.Id
DEFAULT_ID
protected org.drools.core.reteoo.ObjectTypeNode.IdGenerator
idGenerator
protected ObjectType
objectType
TheObjectType
semantic module.-
Fields inherited from class org.drools.core.reteoo.ObjectSource
alphaNodeHashingThreshold, alphaNodeRangeIndexThreshold, declaredMask, inferredMask, sink, source
-
Fields inherited from class org.drools.core.common.BaseNode
associations, hashcode, id, memoryId, partitionId, partitionsEnabled
-
-
Constructor Summary
Constructors Constructor Description ObjectTypeNode()
ObjectTypeNode(int id, EntryPointNode source, ObjectType objectType, BuildContext context)
Construct given a semanticObjectType
and the provided unique id.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertInitialFact(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
void
assertObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
Propagate theFactHandleimpl
through theRete
network.void
byPassModifyToBetaNode(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory)
BitMask
calculateDeclaredMask(Class modifiedClass, List<String> settableProperties)
protected void
checkDirty()
ObjectTypeNode.ObjectTypeNodeMemory
createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm)
Creates memory for the node using PrimitiveLongMap as its optimised for storage and reteivals of Longs.void
doAttach(BuildContext context)
Rete needs to know that this ObjectTypeNode has been addedprotected boolean
doRemove(RuleRemovalContext context, ReteooBuilder builder)
OTN needs to override remove to avoid releasing the node ID, since OTN are never removed from the rulebase in the current implementationstatic void
doRetractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
boolean
equals(Object object)
static void
expireLeftTuple(LeftTuple leftTuple)
static void
expireRightTuple(RightTuple rightTuple)
EntryPointId
getEntryPoint()
long
getExpirationOffset()
ObjectType
getObjectType()
Retrieve the semanticObjectType
differentiator.int
getOtnIdCounter()
RuleBasePartitionId
getPartitionId()
Returns the partition ID for which this node belongs toshort
getType()
boolean
isAssignableFrom(ObjectType objectType)
boolean
isObjectMemoryEnabled()
void
mergeExpirationOffset(ObjectTypeNode other)
void
modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory)
void
networkUpdated(UpdateContext updateContext)
A method that is called for all nodes whose network below them changed, after the change is complete, providing them with an opportunity for state updateObjectTypeNode.Id
nextOtnId()
void
propagateAssert(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
void
readExternal(ObjectInput in)
boolean
remove(RuleRemovalContext context, ReteooBuilder builder)
OTN needs to override remove to avoid releasing the node ID, since OTN are never removed from the rulebase in the current implementationprotected void
resetIdGenerator()
static void
retractLeftTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
static void
retractLeftTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
void
retractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
Retract theFactHandleimpl
from theRete
network.void
retractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
static void
retractRightTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
static void
retractRightTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
void
setExpirationOffset(long expirationOffset)
void
setObjectMemoryEnabled(boolean objectMemoryEnabled)
String
toString()
void
updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory)
protected static void
updateTupleSinkId(ObjectTypeNode otn, ObjectSource source)
void
writeExternal(ObjectOutput out)
-
Methods inherited from class org.drools.core.reteoo.ObjectSource
addObjectSink, getDeclaredMask, getKnowledgeBase, getObjectSinkPropagator, getObjectTypeNode, getParentObjectSource, initDeclaredMask, isInUse, removeObjectSink, resetInferredMask, setObjectSinkPropagator, setParentObjectSource, setPartitionId, setPartitionIdWithSinks, setSourcePartitionId, updateMask
-
Methods inherited from class org.drools.core.common.BaseNode
addAssociation, addAssociation, attach, getAssociatedRules, getAssociatedRuleSize, getAssociationsSize, getAssociationsSize, getId, getMemoryId, getSinks, hashCode, initMemoryId, isAssociatedWith, isStreamMode, removeAssociation, setId, setPartitionsEnabled, setStreamMode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.drools.core.common.MemoryFactory
getMemoryId
-
Methods inherited from interface org.drools.core.common.NetworkNode
getAssociatedRules, getAssociatedRuleSize, getAssociationsSize, getAssociationsSize, getId, isAssociatedWith
-
-
-
-
Field Detail
-
objectType
protected ObjectType objectType
TheObjectType
semantic module.
-
idGenerator
protected transient org.drools.core.reteoo.ObjectTypeNode.IdGenerator idGenerator
-
DEFAULT_ID
public static final ObjectTypeNode.Id DEFAULT_ID
-
-
Constructor Detail
-
ObjectTypeNode
public ObjectTypeNode()
-
ObjectTypeNode
public ObjectTypeNode(int id, EntryPointNode source, ObjectType objectType, BuildContext context)
Construct given a semanticObjectType
and the provided unique id. AllObjectTypdeNode
have node memory.- Parameters:
id
- The unique id for the node.objectType
- The semantic object-type differentiator.
-
-
Method Detail
-
getOtnIdCounter
public int getOtnIdCounter()
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classObjectSource
- Throws:
IOException
ClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classObjectSource
- Throws:
IOException
-
getType
public short getType()
- Specified by:
getType
in interfaceNetworkNode
-
getObjectType
public ObjectType getObjectType()
Retrieve the semanticObjectType
differentiator.- Returns:
- The semantic
ObjectType
differentiator.
-
getPartitionId
public RuleBasePartitionId getPartitionId()
Returns the partition ID for which this node belongs to- Specified by:
getPartitionId
in interfaceNetworkNode
- Overrides:
getPartitionId
in classBaseNode
-
calculateDeclaredMask
public BitMask calculateDeclaredMask(Class modifiedClass, List<String> settableProperties)
- Specified by:
calculateDeclaredMask
in classObjectSource
-
isAssignableFrom
public boolean isAssignableFrom(ObjectType objectType)
-
assertInitialFact
public void assertInitialFact(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
-
checkDirty
protected void checkDirty()
-
assertObject
public void assertObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
Propagate theFactHandleimpl
through theRete
network. AllFactHandleImpl
should be remembered in the node memory, so that later runtime rule attachmnents can have the matched facts propagated to them.- Specified by:
assertObject
in interfaceObjectSink
- Parameters:
factHandle
- The fact handle.context
- The propagation context.workingMemory
- The working memory session.
-
propagateAssert
public void propagateAssert(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
-
retractObject
public void retractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
Retract theFactHandleimpl
from theRete
network. Also remove theFactHandleImpl
from the node memory.- Parameters:
factHandle
- The fact handle.context
- The propagation context.workingMemory
- The working memory session.
-
retractObject
public void retractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
-
doRetractObject
public static void doRetractObject(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
-
expireLeftTuple
public static void expireLeftTuple(LeftTuple leftTuple)
-
expireRightTuple
public static void expireRightTuple(RightTuple rightTuple)
-
retractLeftTuples
public static void retractLeftTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
-
retractLeftTuples
public static void retractLeftTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
-
retractRightTuples
public static void retractRightTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory)
-
retractRightTuples
public static void retractRightTuples(InternalFactHandle factHandle, PropagationContext context, InternalWorkingMemory workingMemory, int partition)
-
resetIdGenerator
protected void resetIdGenerator()
-
modifyObject
public void modifyObject(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory)
- Specified by:
modifyObject
in interfaceObjectSink
-
updateSink
public void updateSink(ObjectSink sink, PropagationContext context, InternalWorkingMemory workingMemory)
- Specified by:
updateSink
in classObjectSource
-
doAttach
public void doAttach(BuildContext context)
Rete needs to know that this ObjectTypeNode has been added
-
networkUpdated
public void networkUpdated(UpdateContext updateContext)
Description copied from class:BaseNode
A method that is called for all nodes whose network below them changed, after the change is complete, providing them with an opportunity for state update- Overrides:
networkUpdated
in classObjectSource
-
updateTupleSinkId
protected static void updateTupleSinkId(ObjectTypeNode otn, ObjectSource source)
-
nextOtnId
public ObjectTypeNode.Id nextOtnId()
-
remove
public boolean remove(RuleRemovalContext context, ReteooBuilder builder)
OTN needs to override remove to avoid releasing the node ID, since OTN are never removed from the rulebase in the current implementation
-
doRemove
protected boolean doRemove(RuleRemovalContext context, ReteooBuilder builder)
OTN needs to override remove to avoid releasing the node ID, since OTN are never removed from the rulebase in the current implementation- Overrides:
doRemove
in classObjectSource
-
createMemory
public ObjectTypeNode.ObjectTypeNodeMemory createMemory(RuleBaseConfiguration config, InternalWorkingMemory wm)
Creates memory for the node using PrimitiveLongMap as its optimised for storage and reteivals of Longs. However PrimitiveLongMap is not ideal for spase data. So it should be monitored incase its more optimal to switch back to a standard HashMap.- Specified by:
createMemory
in interfaceMemoryFactory<ObjectTypeNode.ObjectTypeNodeMemory>
-
isObjectMemoryEnabled
public boolean isObjectMemoryEnabled()
-
setObjectMemoryEnabled
public void setObjectMemoryEnabled(boolean objectMemoryEnabled)
-
getEntryPoint
public EntryPointId getEntryPoint()
- Returns:
- the entryPoint
-
getExpirationOffset
public long getExpirationOffset()
-
setExpirationOffset
public void setExpirationOffset(long expirationOffset)
-
mergeExpirationOffset
public void mergeExpirationOffset(ObjectTypeNode other)
-
byPassModifyToBetaNode
public void byPassModifyToBetaNode(InternalFactHandle factHandle, ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory)
- Specified by:
byPassModifyToBetaNode
in interfaceObjectSink
-
-