Search in sources :

Example 1 with WorkingMemoryEntryPoint

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

the class StatefulKnowledgeSessionImpl method dispose.

public void dispose() {
    if (!agenda.dispose(this)) {
        return;
    }
    if (logger != null) {
        try {
            logger.close();
        } catch (Exception e) {
        /* the logger was already closed, swallow */
        }
    }
    for (WorkingMemoryEntryPoint ep : this.entryPoints.values()) {
        ep.dispose();
    }
    this.ruleRuntimeEventSupport.clear();
    this.ruleEventListenerSupport.clear();
    this.agendaEventSupport.clear();
    for (KieBaseEventListener listener : kieBaseEventListeners) {
        this.kBase.removeEventListener(listener);
    }
    if (processRuntime != null) {
        this.processRuntime.dispose();
    }
    if (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) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) IOException(java.io.IOException)

Example 2 with WorkingMemoryEntryPoint

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

the class StatefulKnowledgeSessionImpl method reset.

public void reset(int handleId, long handleCounter, long propagationCounter) {
    if (nodeMemories != null) {
        nodeMemories.clear();
    }
    this.agenda.clear();
    for (WorkingMemoryEntryPoint ep : this.entryPoints.values()) {
        // clear the state for each entry point
        ep.reset();
    }
    this.handleFactory.clear(handleId, handleCounter);
    this.propagationIdCounter = new AtomicLong(propagationCounter);
    this.opCounter.set(0);
    this.lastIdleTimestamp.set(-1);
// TODO should these be cleared?
// we probably neeed to do CEP and Flow timers too
// this.processInstanceManager.clear()
// this.workItemManager.clear();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint)

Example 3 with WorkingMemoryEntryPoint

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

the class InputMarshaller method readFactHandle.

public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
    int type = context.stream.readInt();
    int id = context.stream.readInt();
    long recency = context.stream.readLong();
    long startTimeStamp = 0;
    long duration = 0;
    boolean expired = false;
    long activationsCount = 0;
    if (type == 2) {
        startTimeStamp = context.stream.readLong();
        duration = context.stream.readLong();
        expired = context.stream.readBoolean();
        activationsCount = context.stream.readLong();
    }
    int strategyIndex = context.stream.readInt();
    Object object = null;
    ObjectMarshallingStrategy strategy = null;
    // This is the old way of de/serializing strategy objects
    if (strategyIndex >= 0) {
        strategy = context.resolverStrategyFactory.getStrategy(strategyIndex);
    } else // This is the new way
    if (strategyIndex == -2) {
        String strategyClassName = context.stream.readUTF();
        if (!StringUtils.isEmpty(strategyClassName)) {
            strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
            if (strategy == null) {
                throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
            }
        }
    }
    // If either way retrieves a strategy, use it
    if (strategy != null) {
        object = strategy.read(context.stream);
    }
    EntryPoint entryPoint = null;
    if (context.readBoolean()) {
        String entryPointId = context.readUTF();
        if (entryPointId != null && !entryPointId.equals("")) {
            entryPoint = ((RuleRuntime) context.wm).getEntryPoint(entryPointId);
        }
    }
    EntryPointId confEP;
    if (entryPoint != null) {
        confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
    } else {
        confEP = context.wm.getEntryPoint();
    }
    ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
    InternalFactHandle handle = null;
    switch(type) {
        case 0:
            {
                handle = new DefaultFactHandle(id, object, recency, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                break;
            }
        case 1:
            {
                handle = new QueryElementFactHandle(object, id, recency);
                break;
            }
        case 2:
            {
                handle = new EventFactHandle(id, object, recency, startTimeStamp, duration, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                ((EventFactHandle) handle).setExpired(expired);
                ((EventFactHandle) handle).setActivationsCount(activationsCount);
                break;
            }
        default:
            {
                throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + type);
            }
    }
    return handle;
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) EntryPointId(org.drools.core.rule.EntryPointId) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 4 with WorkingMemoryEntryPoint

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

the class ProtobufInputMarshaller method readSession.

public static StatefulKnowledgeSessionImpl readSession(ProtobufMessages.KnowledgeSession _session, StatefulKnowledgeSessionImpl session, InternalAgenda agenda, MarshallerReaderContext context) throws IOException, ClassNotFoundException {
    GlobalResolver globalResolver = (GlobalResolver) context.env.get(EnvironmentName.GLOBALS);
    if (globalResolver != null) {
        session.setGlobalResolver(globalResolver);
    }
    if (session.getTimerService() instanceof PseudoClockScheduler) {
        PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
        clock.advanceTime(_session.getTime(), TimeUnit.MILLISECONDS);
    }
    // RuleFlowGroups need to reference the session
    // for ( InternalAgendaGroup group : agenda.getAgendaGroupsMap().values() ) {
    // ((RuleFlowGroupImpl) group).setWorkingMemory( session );
    // }
    context.wm = session;
    // need to read node memories before reading the fact handles
    // because this data is required during fact propagation
    readNodeMemories(context, _session.getRuleData());
    List<PropagationContext> pctxs = new ArrayList<PropagationContext>();
    if (_session.getRuleData().hasInitialFact()) {
        session.setInitialFactHandle(session.initInitialFact(context.kBase, context));
        context.handles.put(session.getInitialFactHandle().getId(), session.getInitialFactHandle());
    }
    for (ProtobufMessages.EntryPoint _ep : _session.getRuleData().getEntryPointList()) {
        EntryPoint wmep = ((StatefulKnowledgeSessionImpl) context.wm).getEntryPointMap().get(_ep.getEntryPointId());
        readFactHandles(context, _ep, ((WorkingMemoryEntryPoint) wmep).getObjectStore(), pctxs);
        context.filter.fireRNEAs(context.wm);
        readTruthMaintenanceSystem(context, wmep, _ep, pctxs);
    }
    cleanReaderContexts(pctxs);
    readActionQueue(context, _session.getRuleData());
    if (processMarshaller != null) {
        if (_session.hasProcessData()) {
            context.parameterObject = _session.getProcessData();
            processMarshaller.readProcessInstances(context);
            context.parameterObject = _session.getProcessData();
            processMarshaller.readWorkItems(context);
            // This actually does ALL timers, due to backwards compatability issues
            // It will read in old JBPM binaries, but always write to the new binary format.
            context.parameterObject = _session.getProcessData();
            processMarshaller.readProcessTimers(context);
        }
    } else {
        if (_session.hasProcessData()) {
            throw new IllegalStateException("No process marshaller, unable to unmarshall process data.");
        }
    }
    if (_session.hasTimers()) {
        for (ProtobufMessages.Timers.Timer _timer : _session.getTimers().getTimerList()) {
            readTimer(context, _timer);
        }
    }
    // need to process any eventual left over timer node timers
    if (!context.timerNodeSchedulers.isEmpty()) {
        for (Map<TupleKey, Scheduler> schedulers : context.timerNodeSchedulers.values()) {
            for (Scheduler scheduler : schedulers.values()) {
                scheduler.schedule(scheduler.getTrigger());
            }
        }
        context.timerNodeSchedulers.clear();
    }
    // remove the activations filter
    agenda.setActivationsFilter(null);
    return session;
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) Scheduler(org.drools.core.phreak.PhreakTimerNode.Scheduler) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) ArrayList(java.util.ArrayList) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) GlobalResolver(org.drools.core.spi.GlobalResolver) Timer(org.drools.core.marshalling.impl.ProtobufMessages.Timers.Timer)

Example 5 with WorkingMemoryEntryPoint

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

the class ProtobufInputMarshaller method assertHandleIntoOTN.

private static void assertHandleIntoOTN(MarshallerReaderContext context, InternalWorkingMemory wm, InternalFactHandle handle, List<PropagationContext> pctxs) {
    Object object = handle.getObject();
    WorkingMemoryEntryPoint ep = handle.getEntryPoint();
    ObjectTypeConf typeConf = ep.getObjectTypeConfigurationRegistry().getObjectTypeConf(ep.getEntryPoint(), object);
    PropagationContextFactory pctxFactory = wm.getKnowledgeBase().getConfiguration().getComponentFactory().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