Search in sources :

Example 21 with WorkingMemoryEntryPoint

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

the class ObjectTypeNode method attach.

/**
 * Rete needs to know that this ObjectTypeNode has been added
 */
public void attach(BuildContext context) {
    this.source.addObjectSink(this);
    InternalWorkingMemory[] workingMemories = context.getWorkingMemories();
    InternalWorkingMemory workingMemory = workingMemories.length > 0 ? workingMemories[0] : null;
    if (workingMemory != null) {
        WorkingMemoryEntryPoint wmEntryPoint = workingMemory.getWorkingMemoryEntryPoint(((EntryPointNode) source).getEntryPoint().getEntryPointId());
        ObjectTypeConf objectTypeConf = wmEntryPoint.getObjectTypeConfigurationRegistry().getObjectTypeConfByClass(((ClassObjectType) objectType).getClassType());
        if (objectTypeConf != null) {
            objectTypeConf.resetCache();
        }
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Example 22 with WorkingMemoryEntryPoint

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

the class TraitHelper 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) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) 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 23 with WorkingMemoryEntryPoint

use of org.drools.core.WorkingMemoryEntryPoint 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 24 with WorkingMemoryEntryPoint

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

the class AbstractFactHandleFactory method newFactHandle.

public final InternalFactHandle newFactHandle(final long id, final Object object, final long recency, final ObjectTypeConf conf, final ReteEvaluator reteEvaluator, final WorkingMemoryEntryPoint wmEntryPoint) {
    WorkingMemoryEntryPoint entryPoint = getWmEntryPoint(reteEvaluator, wmEntryPoint);
    boolean isTrait = conf != null && conf.isTrait();
    if (conf != null && conf.isEvent()) {
        TypeDeclaration type = conf.getTypeDeclaration();
        long timestamp;
        if (type != null && type.getTimestampExtractor() != null) {
            timestamp = type.getTimestampExtractor().getLongValue(reteEvaluator, object);
        } else {
            timestamp = reteEvaluator.getTimerService().getCurrentTime();
        }
        long duration = 0;
        if (type != null && type.getDurationExtractor() != null) {
            duration = type.getDurationExtractor().getLongValue(reteEvaluator, object);
        }
        return createEventFactHandle(id, object, recency, entryPoint, isTrait, timestamp, duration);
    } else {
        return createDefaultFactHandle(id, object, recency, entryPoint, isTrait);
    }
}
Also used : WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 25 with WorkingMemoryEntryPoint

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

the class StatefulKnowledgeSessionImpl method dispose.

public void dispose() {
    alive = false;
    if (pool != null) {
        pool.release(this);
        return;
    }
    if (!agenda.dispose(this)) {
        return;
    }
    if (logger != null) {
        try {
            logger.close();
        } catch (Exception e) {
        /* the logger was already closed, swallow */
        }
    }
    for (WorkingMemoryEntryPoint ep : this.entryPointsManager.getEntryPoints()) {
        ep.dispose();
    }
    for (AsyncReceiveNode.AsyncReceiveMemory receiveMemory : this.receiveNodeMemories) {
        receiveMemory.dispose();
    }
    this.ruleRuntimeEventSupport.clear();
    this.ruleEventListenerSupport.clear();
    this.agendaEventSupport.clear();
    for (KieBaseEventListener listener : kieBaseEventListeners) {
        this.kBase.removeEventListener(listener);
    }
    if (this.processRuntime != null) {
        this.processRuntime.dispose();
    }
    if (this.timerService != null) {
        this.timerService.shutdown();
    }
    if (this.workItemManager != null) {
        ((org.drools.core.process.instance.WorkItemManager) this.workItemManager).dispose();
    }
    this.kBase.disposeStatefulSession(this);
    if (this.mbeanRegistered.get()) {
        DroolsManagementAgent.getInstance().unregisterKnowledgeSessionUnderName(mbeanRegisteredCBSKey, this);
    }
}
Also used : KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) AsyncReceiveNode(org.drools.core.reteoo.AsyncReceiveNode) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) IOException(java.io.IOException)

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