Search in sources :

Example 11 with PropagationContext

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

the class NamedEntryPoint method deleteStated.

private void deleteStated(RuleImpl rule, TerminalNode terminalNode, InternalFactHandle handle, EqualityKey key) {
    if (key != null && key.getStatus() == EqualityKey.JUSTIFIED) {
        return;
    }
    if (handle.isTraitable()) {
        traitHelper.deleteWMAssertedTraitProxies(handle, rule, terminalNode);
    }
    final Object object = handle.getObject();
    final ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
    if (typeConf.isDynamic()) {
        removePropertyChangeListener(handle, true);
    }
    PropagationContext propagationContext = delete(handle, object, typeConf, rule, null, terminalNode);
    deleteFromTMS(handle, key, typeConf, propagationContext);
    this.handleFactory.destroyFactHandle(handle);
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) PropagationContext(org.drools.core.spi.PropagationContext)

Example 12 with PropagationContext

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

the class NamedEntryPoint method insertAsync.

public FactHandle insertAsync(Object object) {
    ObjectTypeConf typeConf = getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint, object);
    PropagationContext pctx = this.pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, null, entryPoint);
    InternalFactHandle handle = createHandle(object, typeConf);
    pctx.setFactHandle(handle);
    this.entryPointNode.assertObject(handle, pctx, typeConf, this.wm);
    this.wm.getRuleRuntimeEventSupport().fireObjectInserted(pctx, handle, object, this.wm);
    return handle;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) PropagationContext(org.drools.core.spi.PropagationContext)

Example 13 with PropagationContext

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

the class NamedEntryPoint method delete.

public PropagationContext delete(InternalFactHandle handle, Object object, ObjectTypeConf typeConf, RuleImpl rule, Activation activation, TerminalNode terminalNode) {
    final PropagationContext propagationContext = pctxFactory.createPropagationContext(this.wm.getNextPropagationIdCounter(), PropagationContext.Type.DELETION, rule, terminalNode, handle, this.entryPoint);
    this.entryPointNode.retractObject(handle, propagationContext, typeConf, this.wm);
    if (handle.isTraiting() && handle.getObject() instanceof TraitProxy) {
        (((TraitProxy) handle.getObject()).getObject()).removeTrait(((TraitProxy) handle.getObject())._getTypeCode());
    } else if (handle.isTraitable()) {
        traitHelper.deleteWMAssertedTraitProxies(handle, rule, terminalNode);
    }
    this.objectStore.removeHandle(handle);
    this.wm.getRuleRuntimeEventSupport().fireObjectRetracted(propagationContext, handle, object, this.wm);
    return propagationContext;
}
Also used : TraitProxy(org.drools.core.factmodel.traits.TraitProxy) PropagationContext(org.drools.core.spi.PropagationContext)

Example 14 with PropagationContext

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

the class TraitHelper method updateCore.

private <T> void updateCore(TraitableBean inner, Object core, Class<T> trait, boolean logical, Activation activation) {
    FactHandle handle = lookupFactHandle(inner);
    InternalFactHandle h = (InternalFactHandle) handle;
    if (handle != null) {
        TraitFieldTMS fieldTMS = inner._getFieldTMS();
        BitMask mask = fieldTMS == null ? onlyTraitBitSetMask() : fieldTMS.getModificationMask();
        Object o = h.getObject();
        NamedEntryPoint nep = (NamedEntryPoint) h.getEntryPoint();
        PropagationContext propagationContext = nep.getPctxFactory().createPropagationContext(nep.getInternalWorkingMemory().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation.getRule(), activation.getTuple().getTupleSink(), h, nep.getEntryPoint(), mask, core.getClass(), null);
        nep.update(h, o, o, nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), o), propagationContext);
    } else {
        handle = this.workingMemory.insert(inner, false, activation.getRule(), activation.getTuple().getTupleSink());
    }
}
Also used : TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS) PropagationContext(org.drools.core.spi.PropagationContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) BitMask(org.drools.core.util.bitmask.BitMask) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 15 with PropagationContext

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

the class JTMSBeliefSystem method processBeliefSet.

private boolean processBeliefSet(RuleImpl rule, Activation activation, Object payload, PropagationContext pctx, JTMSBeliefSet<M> jtmsBeliefSet, boolean wasDecided, boolean wasNegated, InternalFactHandle fh) {
    if (!wasDecided && jtmsBeliefSet.isDecided()) {
        ep.insert(jtmsBeliefSet.getFactHandle(), payload, rule, activation != null ? activation.getTuple().getTupleSink() : null, getObjectTypeConf(jtmsBeliefSet));
        return true;
    } else if (wasDecided && !jtmsBeliefSet.isDecided()) {
        // Handle Conflict
        if (STRICT) {
            throw new IllegalStateException("FATAL : A fact and its negation have been asserted " + jtmsBeliefSet.getFactHandle().getObject());
        }
        // was decided, now is not, so must be removed from the network. Leave in EP though, we only delete from that when the set is empty
        ep.delete(fh, fh.getObject(), getObjectTypeConf(jtmsBeliefSet), pctx.getRuleOrigin(), null, activation != null ? activation.getTuple().getTupleSink() : null);
        return true;
    } else if (wasNegated != jtmsBeliefSet.isNegated()) {
        // was decided, still is decided by the negation changed. This must be propagated through the engine
        // This does not happen for pure JTMS, but does for DFL.
        final PropagationContext updatePctx = ep.getPctxFactory().createPropagationContext(ep.getInternalWorkingMemory().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, pctx.getRuleOrigin(), pctx.getTerminalNodeOrigin(), fh, ep.getEntryPoint());
        ep.update(fh, fh.getObject(), fh.getObject(), getObjectTypeConf(jtmsBeliefSet), updatePctx);
    }
    return false;
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext)

Aggregations

PropagationContext (org.drools.core.spi.PropagationContext)35 PropagationContextFactory (org.drools.core.common.PropagationContextFactory)8 LeftTuple (org.drools.core.reteoo.LeftTuple)8 DroolsQuery (org.drools.core.base.DroolsQuery)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)6 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)6 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)4 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 DefaultKnowledgeHelper (org.drools.core.base.DefaultKnowledgeHelper)2 BetaConstraints (org.drools.core.common.BetaConstraints)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 EventSupport (org.drools.core.common.EventSupport)2