Search in sources :

Example 21 with ObjectTypeConf

use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.

the class TraitHelper method makeTraitable.

private <K> TraitableBean makeTraitable(K core, TraitFactory builder, boolean logical, Activation activation) {
    boolean needsWrapping = !(core instanceof TraitableBean);
    ClassDefinition coreDef = lookupClassDefinition(core);
    TraitableBean<K, ? extends TraitableBean> inner = needsWrapping ? builder.asTraitable(core, coreDef) : (TraitableBean<K, ? extends TraitableBean>) core;
    if (needsWrapping) {
        InternalFactHandle h = (InternalFactHandle) lookupFactHandle(core);
        WorkingMemoryEntryPoint ep = h != null ? h.getEntryPoint() : ((StatefulKnowledgeSessionImpl) workingMemory).getEntryPoint("DEFAULT");
        ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry();
        ObjectTypeConf coreConf = reg.getObjectTypeConf(ep.getEntryPoint(), core);
        ObjectTypeConf innerConf = reg.getObjectTypeConf(ep.getEntryPoint(), inner);
        if (coreConf.isTMSEnabled()) {
            innerConf.enableTMS();
        }
        if (inner._getFieldTMS() != null && inner._getFieldTMS().needsInit()) {
            inner._getFieldTMS().init(workingMemory);
        }
    } else {
        TraitFieldTMS ftms = inner._getFieldTMS();
        if (ftms != null) {
            FactHandle handle = lookupFactHandle(inner);
            if (handle == null) {
                handle = this.workingMemory.insert(inner, false, activation.getRule(), activation.getTuple().getTupleSink());
            }
            if (ftms.needsInit()) {
                ftms.init(workingMemory);
            }
        }
    }
    return inner;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) TraitableBean(org.drools.core.factmodel.traits.TraitableBean) ClassDefinition(org.drools.core.factmodel.ClassDefinition) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry)

Example 22 with ObjectTypeConf

use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.

the class JTMSBeliefSystem method getObjectTypeConf.

private ObjectTypeConf getObjectTypeConf(BeliefSet<M> jtmsBeliefSet) {
    InternalFactHandle fh = jtmsBeliefSet.getFactHandle();
    ObjectTypeConfigurationRegistry reg;
    ObjectTypeConf typeConf;
    reg = ep.getObjectTypeConfigurationRegistry();
    typeConf = reg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
    return typeConf;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) InternalFactHandle(org.drools.core.common.InternalFactHandle) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry)

Example 23 with ObjectTypeConf

use of org.drools.core.reteoo.ObjectTypeConf in project drools by kiegroup.

the class BeliefSystemLogicalCallback method execute.

public void execute(InternalWorkingMemory workingMemory) {
    NamedEntryPoint nep = (NamedEntryPoint) handle.getEntryPoint();
    BeliefSet bs = handle.getEqualityKey().getBeliefSet();
    bs.setWorkingMemoryAction(null);
    if (update) {
        if (!bs.isEmpty()) {
            // We need the isEmpty check, in case the BeliefSet was made empty (due to retract) after this was scheduled
            ((NamedEntryPoint) handle.getEntryPoint()).update(handle, handle.getObject(), allSetButTraitBitMask(), Object.class, null);
        }
    } else {
        if (fullyRetract) {
            ((NamedEntryPoint) handle.getEntryPoint()).delete(this.handle, context.getRuleOrigin(), this.activation.getTuple().getTupleSink());
        } else {
            final ObjectTypeConf typeConf = nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), handle.getObject());
            ((NamedEntryPoint) handle.getEntryPoint()).getEntryPointNode().retractObject(handle, context, typeConf, workingMemory);
        }
    }
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) BeliefSet(org.drools.core.beliefsystem.BeliefSet)

Aggregations

ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)23 InternalFactHandle (org.drools.core.common.InternalFactHandle)9 PropagationContext (org.drools.core.spi.PropagationContext)6 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)4 ObjectTypeConfigurationRegistry (org.drools.core.common.ObjectTypeConfigurationRegistry)4 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)3 BeliefSet (org.drools.core.beliefsystem.BeliefSet)3 Test (org.junit.Test)3 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)3 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)2 EqualityKey (org.drools.core.common.EqualityKey)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)2 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)2 ObjectTypeConfiguration (org.drools.core.marshalling.impl.ProtobufMessages.ObjectTypeConfiguration)2 EntryPointId (org.drools.core.rule.EntryPointId)2 Activation (org.drools.core.spi.Activation)2 MockActivation (org.drools.core.test.model.MockActivation)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 HashSet (java.util.HashSet)1