Search in sources :

Example 31 with ObjectType

use of org.drools.core.spi.ObjectType in project drools by kiegroup.

the class BetaNode method initDeclaredMask.

@Override
protected void initDeclaredMask(BuildContext context, LeftTupleSource leftInput) {
    if (context == null || context.getLastBuiltPatterns() == null) {
        // only happens during unit tests
        rightDeclaredMask = AllSetBitMask.get();
        super.initDeclaredMask(context, leftInput);
        return;
    }
    // right input pattern
    Pattern pattern = context.getLastBuiltPatterns()[0];
    rightInputIsPassive = pattern.isPassive();
    if (!isRightInputIsRiaNode()) {
        ObjectType objectType = pattern.getObjectType();
        if (objectType instanceof ClassObjectType) {
            Class objectClass = ((ClassObjectType) objectType).getClassType();
            if (isPropertyReactive(context, objectClass)) {
                rightListenedProperties = pattern.getListenedProperties();
                List<String> accessibleProperties = getAccessibleProperties(context.getKnowledgeBase(), objectClass);
                rightDeclaredMask = calculatePositiveMask(objectClass, rightListenedProperties, accessibleProperties);
                rightDeclaredMask = rightDeclaredMask.setAll(constraints.getListenedPropertyMask(objectClass, accessibleProperties));
                rightNegativeMask = calculateNegativeMask(objectClass, rightListenedProperties, accessibleProperties);
            } else {
                // if property reactive is not on, then accept all modification propagations
                rightDeclaredMask = AllSetBitMask.get();
            }
        } else {
            // InitialFact has no type declaration and cannot be property specific
            // Only ClassObjectType can use property specific
            rightDeclaredMask = AllSetBitMask.get();
        }
    } else {
        rightDeclaredMask = AllSetBitMask.get();
        // There would have been no right input pattern, so swap current to first, so leftInput can still work
        context.setLastBuiltPattern(context.getLastBuiltPatterns()[0]);
    }
    super.initDeclaredMask(context, leftInput);
}
Also used : Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectType(org.drools.core.spi.ObjectType) ClassObjectType(org.drools.core.base.ClassObjectType)

Example 32 with ObjectType

use of org.drools.core.spi.ObjectType in project drools by kiegroup.

the class EntryPointNode method updateSink.

public void updateSink(final ObjectSink sink, final PropagationContext context, final InternalWorkingMemory workingMemory) {
    // @todo
    // JBRULES-612: the cache MUST be invalidated when a new node type is added to the network, so iterate and reset all caches.
    final ObjectTypeNode node = (ObjectTypeNode) sink;
    final ObjectType newObjectType = node.getObjectType();
    WorkingMemoryEntryPoint wmEntryPoint = workingMemory.getWorkingMemoryEntryPoint(this.entryPoint.getEntryPointId());
    for (ObjectTypeConf objectTypeConf : wmEntryPoint.getObjectTypeConfigurationRegistry().values()) {
        if (objectTypeConf.getConcreteObjectTypeNode() != null && newObjectType.isAssignableFrom(objectTypeConf.getConcreteObjectTypeNode().getObjectType())) {
            objectTypeConf.resetCache();
            ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
            Iterator<InternalFactHandle> it = workingMemory.getNodeMemory(sourceNode).iterator();
            while (it.hasNext()) {
                sink.assertObject(it.next(), context, workingMemory);
            }
        }
    }
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) ObjectType(org.drools.core.spi.ObjectType) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Example 33 with ObjectType

use of org.drools.core.spi.ObjectType in project drools by kiegroup.

the class LeftInputAdapterNode method calculateSinkMask.

private BitMask calculateSinkMask(BuildContext context) {
    Pattern pattern = context.getLastBuiltPatterns() != null ? context.getLastBuiltPatterns()[0] : null;
    if (pattern == null) {
        return AllSetBitMask.get();
    }
    ObjectType objectType = pattern.getObjectType();
    if (!(objectType instanceof ClassObjectType)) {
        // Only ClassObjectType can use property specific
        return AllSetBitMask.get();
    }
    Class objectClass = ((ClassWireable) objectType).getClassType();
    return isPropertyReactive(context, objectClass) ? calculatePositiveMask(objectClass, pattern.getListenedProperties(), getAccessibleProperties(context.getKnowledgeBase(), objectClass)) : AllSetBitMask.get();
}
Also used : Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectType(org.drools.core.spi.ObjectType) ClassObjectType(org.drools.core.base.ClassObjectType) ClassWireable(org.drools.core.spi.ClassWireable)

Aggregations

ObjectType (org.drools.core.spi.ObjectType)33 ClassObjectType (org.drools.core.base.ClassObjectType)32 Test (org.junit.Test)17 Pattern (org.drools.core.rule.Pattern)13 Declaration (org.drools.core.rule.Declaration)7 FactTemplateObjectType (org.drools.core.facttemplates.FactTemplateObjectType)5 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 InternalFactHandle (org.drools.core.common.InternalFactHandle)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)4 TypeDeclaration (org.drools.core.rule.TypeDeclaration)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)3 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)3