Search in sources :

Example 1 with WorkingMemoryFactory

use of org.drools.core.common.WorkingMemoryFactory in project drools by kiegroup.

the class KnowledgeBaseImpl method newKieSession.

public KieSession newKieSession(KieSessionConfiguration conf, Environment environment) {
    // NOTE if you update here, you'll also need to update the JPAService
    if (conf == null) {
        conf = getSessionConfiguration();
    }
    SessionConfiguration sessionConfig = (SessionConfiguration) conf;
    if (environment == null) {
        environment = EnvironmentFactory.newEnvironment();
    }
    if (this.getConfiguration().isSequential()) {
        throw new RuntimeException("Cannot have a stateful rule session, with sequential configuration set to true");
    }
    readLock();
    try {
        WorkingMemoryFactory wmFactory = kieComponentFactory.getWorkingMemoryFactory();
        StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) wmFactory.createWorkingMemory(nextWorkingMemoryCounter(), this, sessionConfig, environment);
        if (sessionConfig.isKeepReference()) {
            addStatefulSession(session);
        }
        return session;
    } finally {
        readUnlock();
    }
}
Also used : WorkingMemoryFactory(org.drools.core.common.WorkingMemoryFactory) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration)

Example 2 with WorkingMemoryFactory

use of org.drools.core.common.WorkingMemoryFactory in project drools by kiegroup.

the class ProtobufInputMarshaller method createAndInitializeSession.

private static StatefulKnowledgeSessionImpl createAndInitializeSession(MarshallerReaderContext context, int id, Environment environment, SessionConfiguration config, ProtobufMessages.KnowledgeSession _session) throws IOException {
    FactHandleFactory handleFactory = context.kBase.newFactHandleFactory(_session.getRuleData().getLastId(), _session.getRuleData().getLastRecency());
    InternalAgenda agenda = context.kBase.getConfiguration().getComponentFactory().getAgendaFactory().createAgenda(context.kBase, false);
    readAgenda(context, _session.getRuleData(), agenda);
    WorkingMemoryFactory wmFactory = context.kBase.getConfiguration().getComponentFactory().getWorkingMemoryFactory();
    StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) wmFactory.createWorkingMemory(id, context.kBase, handleFactory, // pCTx starts at 1, as InitialFact is 0
    1, config, agenda, environment);
    return session;
}
Also used : InternalAgenda(org.drools.core.common.InternalAgenda) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) WorkingMemoryFactory(org.drools.core.common.WorkingMemoryFactory) FactHandleFactory(org.drools.core.spi.FactHandleFactory)

Aggregations

WorkingMemoryFactory (org.drools.core.common.WorkingMemoryFactory)2 SessionConfiguration (org.drools.core.SessionConfiguration)1 InternalAgenda (org.drools.core.common.InternalAgenda)1 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)1 FactHandleFactory (org.drools.core.spi.FactHandleFactory)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1