ObjectTypeNodes are responsible for filtering and propagating the matching fact assertions propagated from the Rete
node using ObjectType
interface. The assert and retract methods do not attempt to filter as this is the role of the Rete
node which builds up a cache of matching ObjectTypdeNodes
s for each asserted object, using the matches(Object object)
method. Incorrect propagation in these methods is not checked and will result in ClassCastExpcections
later on in the network.
Filters Objects
coming from the Rete
using a ObjectType
semantic module.
@see ObjectType
@see Rete
assertEquals( "r1", list.get(0) );
// Check it was built with MVELReturnValueExpression constraint
List<ObjectTypeNode> nodes = ((InternalRuleBase)((KnowledgeBaseImpl)kbase).ruleBase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for ( ObjectTypeNode n : nodes ) {
if ( ((ClassObjectType)n.getObjectType()).getClassType() == Person.class ) {
node = n;
break;
}
}
AlphaNode alphanode = (AlphaNode) node.getSinkPropagator().getSinks()[0];
assertTrue( (( LiteralConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
assertEquals( new Address("s1"), (( LiteralConstraint ) alphanode.getConstraint()).getField().getValue() );
alphanode = (AlphaNode) alphanode.getSinkPropagator().getSinks()[0];
assertTrue( (( LiteralConstraint ) alphanode.getConstraint()).getFieldExtractor() instanceof MVELClassFieldReader );
assertNotNull( defaultEntryPointNode );
Map<ObjectType, ObjectTypeNode> obnodes = defaultEntryPointNode.getObjectTypeNodes();
ObjectType key = new ClassObjectType( DroolsQuery.class );
ObjectTypeNode droolsQueryNode = obnodes.get( key );
ObjectHashSet droolsQueryMemory = ((ObjectTypeNodeMemory) abstractWorkingMemory.getNodeMemory( droolsQueryNode )).memory;
assertEquals( 0,
droolsQueryMemory.size() );
Entry[] entries = droolsQueryMemory.getTable();
} else {
epn.attach();
}
}
ObjectTypeNode otn = new ObjectTypeNode( context.getNextId(),
epn,
objectType,
context );
long expirationOffset = getExpiratioOffsetForType( context,
objectType );
otn.setExpirationOffset( expirationOffset );
if ( wms.length > 0 ) {
otn.attach( wms );
} else {
otn.attach();
}
return otn;
} finally {
ruleBase.readUnlock();
context.setObjectSource( (ObjectSource) utils.attachNode( context,
new EntryPointNode( context.getNextId(),
context.getRuleBase().getRete(),
context ) ) );
ObjectTypeNode otn = new ObjectTypeNode( context.getNextId(),
(EntryPointNode) context.getObjectSource(),
objectType,
context );
if ( objectType.isEvent() && EventProcessingOption.STREAM.equals( context.getRuleBase().getConfiguration().getEventProcessingMode() ) ) {
long expirationOffset = getExpiratioOffsetForType( context,
objectType );
if( expirationOffset != -1 ) {
// expiration policy is set, so use it
otn.setExpirationOffset( expirationOffset );
} else {
// otherwise calculate it based on behaviours and temporal constraints
for ( Behavior behavior : pattern.getBehaviors() ) {
if ( behavior.getExpirationOffset() != -1 ) {
expirationOffset = Math.max( behavior.getExpirationOffset(),
expirationOffset );
}
}
long distance = context.getTemporalDistance().getExpirationOffset( pattern );
if( distance == -1 ) {
// it means the rules have no temporal constraints, or
// the constraints require events to be hold forever. In this
// case, we allow type declarations to override the implicit
// expiration offset by defining an expiration policy with the
// @expires tag
otn.setExpirationOffset( expirationOffset );
} else {
otn.setExpirationOffset( Math.max( distance, expirationOffset ) );
}
}
}
context.setObjectSource( (ObjectSource) utils.attachNode( context,
public static void writeInitialFactHandleRightTuples(MarshallerWriteContext context) throws IOException {
ObjectOutputStream stream = context.stream;
InternalRuleBase ruleBase = context.ruleBase;
ObjectTypeNode initialFactNode = ruleBase.getRete().getEntryPointNode( EntryPoint.DEFAULT ).getObjectTypeNodes().get( new ClassObjectType( InitialFact.class ) );
// do we write the fact to the objecttypenode memory
if ( initialFactNode != null ) {
ObjectHashSet initialFactMemory = (ObjectHashSet) context.wm.getNodeMemory( initialFactNode );
if ( initialFactMemory != null && !initialFactMemory.isEmpty() ) {
//context.out.println( "InitialFactMemory true int:" + initialFactNode.getId() );
stream.writeBoolean( true );
stream.writeInt( initialFactNode.getId() );
//context.out.println( "InitialFact RightTuples" );
writeRightTuples( context.wm.getInitialFactHandle(),
context );
} else {
partition = RuleBasePartitionId.MAIN_PARTITION;
} else if ( candidate instanceof ObjectTypeNode ) {
// object type nodes are always shared
Map<ObjectType, ObjectTypeNode> map = context.getRuleBase().getRete().getObjectTypeNodes( context.getCurrentEntryPoint() );
if ( map != null ) {
ObjectTypeNode otn = map.get( ((ObjectTypeNode) candidate).getObjectType() );
if ( otn != null ) {
// adjusting expiration offset
otn.setExpirationOffset( Math.max( otn.getExpirationOffset(),
((ObjectTypeNode) candidate).getExpirationOffset() ) );
node = otn;
}
}
// all ObjectTypeNodes belong to the main partition
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
List<ObjectTypeNode> nodes = ((InternalRuleBase)((KnowledgeBaseImpl)kbase).ruleBase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for ( ObjectTypeNode n : nodes ) {
if ( ((ClassObjectType)n.getObjectType()).getClassType() == Person.class ) {
node = n;
break;
}
}
ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) node.getSinkPropagator().getSinks()[0];
JoinNode j2 = ( JoinNode ) liaNode.getSinkPropagator().getSinks()[0]; // $p2
JoinNode j3 = ( JoinNode ) j2.getSinkPropagator().getSinks()[0]; // $p3
JoinNode j4 = ( JoinNode ) j3.getSinkPropagator().getSinks()[0]; // $p4
JoinNode j5 = ( JoinNode ) j4.getSinkPropagator().getSinks()[0]; // $p5
//JoinNode j6 = ( JoinNode ) j5.getSinkPropagator().getSinks()[0]; // $p6 // won't compile
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
List<ObjectTypeNode> nodes = ((InternalRuleBase)((KnowledgeBaseImpl)kbase).ruleBase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for ( ObjectTypeNode n : nodes ) {
if ( ((ClassObjectType)n.getObjectType()).getClassType() == DroolsQuery.class ) {
node = n;
break;
}
}
ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
AlphaNode alphanode = ( AlphaNode ) node.getSinkPropagator().getSinks()[0];
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphanode.getSinkPropagator().getSinks()[0];
JoinNode j = ( JoinNode ) liaNode.getSinkPropagator().getSinks()[0]; // $p2
TripleNonIndexSkipBetaConstraints c = ( TripleNonIndexSkipBetaConstraints ) j.getRawConstraints();
//assertEquals( "$name", ((VariableConstraint)c.getConstraint()).getRequiredDeclarations()[0].getIdentifier() );
kbase = SerializationHelper.serializeObject( kbase );
// Get the accumulate node, so we can test it's memory later
// now check beta memory was correctly cleared
List<ObjectTypeNode> nodes = ((InternalRuleBase) ((KnowledgeBaseImpl) kbase).ruleBase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for ( ObjectTypeNode n : nodes ) {
if ( ((ClassObjectType) n.getObjectType()).getClassType() == String.class ) {
node = n;
break;
}
}
BetaNode stringBetaNode = (BetaNode) node.getSinkPropagator().getSinks()[0];
QueryElementNode queryElementNode1 = (QueryElementNode) stringBetaNode.getSinkPropagator().getSinks()[0];
RightInputAdapterNode riaNode1 = (RightInputAdapterNode) queryElementNode1.getSinkPropagator().getSinks()[0];
AccumulateNode accNode = (AccumulateNode) riaNode1.getSinkPropagator().getSinks()[0];
QueryElementNode queryElementNode2 = (QueryElementNode) accNode.getSinkPropagator().getSinks()[0];
assertNotNull( defaultEntryPointNode );
Map<ObjectType, ObjectTypeNode> obnodes = defaultEntryPointNode.getObjectTypeNodes();
ObjectType key = new ClassObjectType( DroolsQuery.class );
ObjectTypeNode droolsQueryNode = obnodes.get( key );
ObjectHashSet droolsQueryMemory = (ObjectHashSet) abstractWorkingMemory.getNodeMemory( droolsQueryNode );
assertEquals( 0,
droolsQueryMemory.size() );
Entry[] entries = droolsQueryMemory.getTable();
Related Classes of org.drools.reteoo.ObjectTypeNode$ExpireJobContext
Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.