public ClassObjectTypeConf( final EntryPointId entryPoint, final Class<?> clazz, final InternalKnowledgeBase kBase) { this.cls = (Activation.class.isAssignableFrom(clazz)) ? ClassObjectType.Match_ObjectType.getClassType() : clazz; this.kBase = kBase; this.entryPoint = entryPoint; this.typeDecl = kBase.getTypeDeclaration(clazz); isEvent = typeDecl != null && typeDecl.getRole() == Role.Type.EVENT; if (isEvent) { expirationOffset = typeDecl.getExpirationOffset(); } isTrait = determineTraitStatus(); this.objectType = kBase .getClassFieldAccessorCache() .getClassObjectType(new ClassObjectType(clazz, isEvent), false); this.concreteObjectTypeNode = kBase.getRete().getObjectTypeNodes(entryPoint).get(objectType); this.supportsPropertyListeners = checkPropertyListenerSupport(clazz); Traitable ttbl = cls.getAnnotation(Traitable.class); this.traitTmsEnabled = ttbl != null && ttbl.logical(); }
/** * Tests the assertion of objects into LeftInputAdapterNode * * @throws Exception */ @Test public void testAssertObjectWithoutMemory() throws Exception { PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory(); final PropagationContext pcontext = pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, null); BuildContext context = new BuildContext(kBase, kBase.getReteooBuilder().getIdGenerator()); final EntryPointNode entryPoint = new EntryPointNode(-1, kBase.getRete(), context); entryPoint.attach(context); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(0, entryPoint, new ClassObjectType(Object.class), context); objectTypeNode.attach(context); final LeftInputAdapterNode liaNode = new LeftInputAdapterNode(23, objectTypeNode, buildContext); liaNode.attach(context); final StatefulKnowledgeSessionImpl workingMemory = new StatefulKnowledgeSessionImpl(1L, kBase); final MockLeftTupleSink sink = new MockLeftTupleSink(); liaNode.addTupleSink(sink); final Object string1 = "cheese"; // assert object final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert(string1); liaNode.assertObject(f0, pcontext, workingMemory); final List asserted = sink.getAsserted(); assertLength(1, asserted); final LeftTuple tuple0 = (LeftTuple) ((Object[]) asserted.get(0))[0]; assertSame(string1, workingMemory.getObject(tuple0.get(0))); }
private ObjectTypeNode[] getMatchingObjectTypes(final Class<?> clazz) { final List<ObjectTypeNode> cache = new ArrayList<ObjectTypeNode>(); for (ObjectTypeNode node : kBase.getRete().getObjectTypeNodes(this.entryPoint).values()) { if (clazz == DroolsQuery.class) { // for query objects only add direct matches if (((ClassObjectType) node.getObjectType()).getClassType() == clazz) { cache.add(node); } } else if (node.isAssignableFrom(new ClassObjectType(clazz))) { cache.add(node); } } Collections.sort(cache, OBJECT_TYPE_NODE_COMPARATOR); return cache.toArray(new ObjectTypeNode[cache.size()]); }
private InternalFactHandle createEventFactHandle( StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) { // EntryPointNode Rete rete = kBase.getRete(); NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService(); RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION; EntryPointNode entryPointNode = nFacotry.buildEntryPointNode( 1, partionId, false, (ObjectSource) rete, EntryPointId.DEFAULT); InternalWorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm); EventFactHandle factHandle = new EventFactHandle(1, (Object) new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint); return factHandle; }
@Test public void testLeftInputAdapterNode() { BuildContext context = new BuildContext(kBase, kBase.getReteooBuilder().getIdGenerator()); final EntryPointNode entryPoint = new EntryPointNode(-1, kBase.getRete(), context); entryPoint.attach(context); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(0, entryPoint, new ClassObjectType(Object.class), context); objectTypeNode.attach(context); final LeftInputAdapterNode liaNode = new LeftInputAdapterNode(23, objectTypeNode, buildContext); assertEquals(23, liaNode.getId()); assertEquals(0, objectTypeNode.getSinkPropagator().getSinks().length); liaNode.attach(context); assertEquals(1, objectTypeNode.getSinkPropagator().getSinks().length); }
public ClassObjectTypeConf( final EntryPointId entryPoint, final Class<?> clazz, final InternalKnowledgeBase kBase) { this.cls = (Activation.class.isAssignableFrom(clazz)) ? ClassObjectType.Match_ObjectType.getClassType() : clazz; this.kBase = kBase; this.entryPoint = entryPoint; this.typeDecl = kBase.getTypeDeclaration(clazz); isEvent = typeDecl != null && typeDecl.getRole() == TypeDeclaration.Role.EVENT; isTrait = determineTraitStatus(); ObjectType objectType = kBase.getClassFieldAccessorCache().getClassObjectType(new ClassObjectType(clazz, isEvent)); this.concreteObjectTypeNode = kBase.getRete().getObjectTypeNodes(entryPoint).get(objectType); if (this.concreteObjectTypeNode == null) { BuildContext context = new BuildContext(kBase, kBase.getReteooBuilder().getIdGenerator()); context.setCurrentEntryPoint(entryPoint); if (DroolsQuery.class == clazz) { context.setTupleMemoryEnabled(false); context.setObjectTypeNodeMemoryEnabled(false); } else if (context.getKnowledgeBase().getConfiguration().isSequential()) { // We are in sequential mode, so no nodes should have memory // context.setTupleMemoryEnabled( false ); // context.setObjectTypeNodeMemoryEnabled( false ); context.setTupleMemoryEnabled(true); context.setObjectTypeNodeMemoryEnabled(true); } else { context.setTupleMemoryEnabled(true); context.setObjectTypeNodeMemoryEnabled(true); } // there must exist an ObjectTypeNode for this concrete class this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode(context, objectType); } this.supportsPropertyListeners = checkPropertyListenerSupport(clazz); Traitable ttbl = cls.getAnnotation(Traitable.class); this.traitTmsEnabled = ttbl != null && ttbl.logical(); }
public ObjectTypeNode getConcreteObjectTypeNode() { if (concreteObjectTypeNode == null) { concreteObjectTypeNode = kBase.getRete().getObjectTypeNodes(entryPoint).get(objectType); } return concreteObjectTypeNode; }