Search in sources :

Example 6 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.

the class CursoredDataSource method bind.

@Override
public void bind(RuleUnit unit, WorkingMemoryEntryPoint ep) {
    setWorkingMemory(ep.getInternalWorkingMemory());
    PropagationList propagationList = propagationsMap.get(unit.getUnitIdentity());
    if (propagationList != null) {
        flush(ep, propagationList.takeAll());
    } else {
        Iterator<InternalFactHandle> fhs = objectStore.iterateFactHandles();
        while (fhs.hasNext()) {
            new Insert((DataSourceFactHandle) fhs.next()).execute(ep);
        }
        propagationsMap.put(unit.getUnitIdentity(), new SynchronizedPropagationList(((WorkingMemoryEntryPoint) ep).getInternalWorkingMemory()));
    }
    currentUnit = unit.getUnitIdentity();
    currentEntryPoint = ep;
}
Also used : SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) PropagationList(org.drools.core.phreak.PropagationList) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint)

Example 7 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.

the class DefaultAgenda method insertAndStageActivation.

@Override
public void insertAndStageActivation(final AgendaItem activation) {
    if (activationObjectTypeConf == null) {
        EntryPointId ep = workingMemory.getEntryPoint();
        activationObjectTypeConf = ((WorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint(ep.getEntryPointId())).getObjectTypeConfigurationRegistry().getObjectTypeConf(ep, activation);
    }
    InternalFactHandle factHandle = workingMemory.getFactHandleFactory().newFactHandle(activation, activationObjectTypeConf, workingMemory, workingMemory);
    workingMemory.getEntryPointNode().assertActivation(factHandle, activation.getPropagationContext(), workingMemory);
    activation.setActivationFactHandle(factHandle);
}
Also used : EntryPointId(org.drools.core.rule.EntryPointId) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Example 8 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.

the class TraitHelperImpl method lookupHandleForWrapper.

private <K> InternalFactHandle lookupHandleForWrapper(K core) {
    for (EntryPoint ep : workingMemory.getEntryPoints()) {
        ObjectStore store = ((WorkingMemoryEntryPoint) ep).getObjectStore();
        Iterator<InternalFactHandle> iter = store.iterateFactHandles();
        while (iter.hasNext()) {
            InternalFactHandle handle = iter.next();
            if (handle.isTraitable() && handle.getObject() instanceof CoreWrapper && ((CoreWrapper) handle.getObject()).getCore() == core) {
                return handle;
            }
        }
    }
    return null;
}
Also used : CoreWrapper(org.drools.core.factmodel.traits.CoreWrapper) ObjectStore(org.drools.core.common.ObjectStore) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint)

Example 9 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.

the class TraitHelperImpl method makeTraitable.

private <K> TraitableBean makeTraitable(K core, TraitFactoryImpl 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(workingMemory) : ((StatefulKnowledgeSessionImpl) workingMemory).getEntryPoint("DEFAULT");
        ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry();
        ObjectTypeConf coreConf = reg.getOrCreateObjectTypeConf(ep.getEntryPoint(), core);
        ObjectTypeConf innerConf = reg.getOrCreateObjectTypeConf(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 10 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.

the class ProtobufInputMarshaller method assertHandleIntoOTN.

private static void assertHandleIntoOTN(ProtobufMarshallerReaderContext context, InternalWorkingMemory wm, InternalFactHandle handle, List<PropagationContext> pctxs) {
    Object object = handle.getObject();
    WorkingMemoryEntryPoint ep = handle.getEntryPoint(wm);
    ObjectTypeConf typeConf = ep.getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(ep.getEntryPoint(), object);
    PropagationContextFactory pctxFactory = RuntimeComponentFactory.get().getPropagationContextFactory();
    PropagationContext propagationContext = pctxFactory.createPropagationContext(wm.getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, ep.getEntryPoint(), context);
    // keeping this list for a later cleanup is necessary because of the lazy propagations that might occur
    pctxs.add(propagationContext);
    ep.getEntryPointNode().assertObject(handle, propagationContext, typeConf, wm);
    wm.flushPropagations();
}
Also used : PropagationContextFactory(org.drools.core.common.PropagationContextFactory) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) PropagationContext(org.drools.core.spi.PropagationContext) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Aggregations

WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)31 InternalFactHandle (org.drools.core.common.InternalFactHandle)14 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)11 EntryPoint (org.kie.api.runtime.rule.EntryPoint)8 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)6 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)6 PropagationContext (org.drools.core.spi.PropagationContext)6 EventFactHandle (org.drools.core.common.EventFactHandle)5 EntryPointId (org.drools.core.rule.EntryPointId)5 NamedEntryPoint (org.drools.kiesession.entrypoints.NamedEntryPoint)5 PropagationContextFactory (org.drools.core.common.PropagationContextFactory)4 EntryPointNode (org.drools.core.reteoo.EntryPointNode)4 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)2 EqualityKey (org.drools.core.common.EqualityKey)2 ObjectStore (org.drools.core.common.ObjectStore)2