Search in sources :

Example 1 with KieSessionModelImpl

use of org.drools.compiler.kproject.models.KieSessionModelImpl in project drools by kiegroup.

the class AbstractKieProject method indexKieModule.

private void indexKieModule(Map<String, InternalKieModule> kJarFromKBaseName, InternalKieModule kJar, boolean isMainModule) {
    boolean defaultKieBaseFromMain = false;
    boolean defaultKieSessionFromMain = false;
    boolean defaultStatelessKieSessionFromMain = false;
    KieModuleModel kieProject = kJar.getKieModuleModel();
    for (KieBaseModel kieBaseModel : kieProject.getKieBaseModels().values()) {
        if (kieBaseModel.isDefault()) {
            if (defaultKieBase == null || (isMainModule && !defaultKieBaseFromMain)) {
                defaultKieBase = kieBaseModel;
                defaultKieBaseFromMain = isMainModule;
            } else {
                defaultKieBase = null;
                log.warn("Found more than one default KieBase: disabling all. KieBases will be accessible only by name");
            }
        }
        kBaseModels.put(kieBaseModel.getName(), kieBaseModel);
        // should already be set, but just in case
        ((KieBaseModelImpl) kieBaseModel).setKModule(kieProject);
        kJarFromKBaseName.put(kieBaseModel.getName(), kJar);
        for (KieSessionModel kieSessionModel : kieBaseModel.getKieSessionModels().values()) {
            if (kieSessionModel.isDefault()) {
                if (kieSessionModel.getType() == KieSessionModel.KieSessionType.STATEFUL) {
                    if (defaultKieSession == null || (isMainModule && !defaultKieSessionFromMain)) {
                        defaultKieSession = kieSessionModel;
                        defaultKieSessionFromMain = isMainModule;
                    } else {
                        defaultKieSession = null;
                        log.warn("Found more than one default KieSession: disabling all. KieSessions will be accessible only by name");
                    }
                } else {
                    if (defaultStatelessKieSession == null || (isMainModule && !defaultStatelessKieSessionFromMain)) {
                        defaultStatelessKieSession = kieSessionModel;
                        defaultStatelessKieSessionFromMain = isMainModule;
                    } else {
                        defaultStatelessKieSession = null;
                        log.warn("Found more than one default StatelessKieSession: disabling all. StatelessKieSessions will be accessible only by name");
                    }
                }
            }
            // should already be set, but just in case
            ((KieSessionModelImpl) kieSessionModel).setKBase(kieBaseModel);
            kSessionModels.put(kieSessionModel.getName(), kieSessionModel);
        }
    }
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieSessionModelImpl(org.drools.compiler.kproject.models.KieSessionModelImpl) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBaseModelImpl(org.drools.compiler.kproject.models.KieBaseModelImpl) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Example 2 with KieSessionModelImpl

use of org.drools.compiler.kproject.models.KieSessionModelImpl in project drools by kiegroup.

the class KieContainerImpl method newStatelessKieSession.

public StatelessKieSession newStatelessKieSession(String kSessionName, KieSessionConfiguration conf) {
    KieSessionModelImpl kSessionModel = kSessionName != null ? (KieSessionModelImpl) getKieSessionModel(kSessionName) : (KieSessionModelImpl) findKieSessionModel(true);
    if (kSessionModel == null) {
        log.error("Unknown KieSession name: " + kSessionName);
        return null;
    }
    if (kSessionModel.getType() == KieSessionModel.KieSessionType.STATEFUL) {
        throw new RuntimeException("Trying to create a stateless KieSession from a stateful KieSessionModel: " + kSessionModel.getName());
    }
    KieBase kBase = getKieBase(kSessionModel.getKieBaseModel().getName());
    if (kBase == null) {
        log.error("Unknown KieBase name: " + kSessionModel.getKieBaseModel().getName());
        return null;
    }
    StatelessKieSession statelessKieSession = kBase.newStatelessKieSession(conf != null ? conf : getKieSessionConfiguration(kSessionModel));
    if (isJndiAvailable()) {
        wireSessionComponents(kSessionModel, statelessKieSession);
    }
    registerLoggers(kSessionModel, statelessKieSession);
    ((StatelessKnowledgeSessionImpl) statelessKieSession).initMBeans(containerId, ((InternalKnowledgeBase) kBase).getId(), kSessionModel.getName());
    statelessKSessions.put(kSessionModel.getName(), statelessKieSession);
    return statelessKieSession;
}
Also used : KieSessionModelImpl(org.drools.compiler.kproject.models.KieSessionModelImpl) StatelessKnowledgeSessionImpl(org.drools.core.impl.StatelessKnowledgeSessionImpl) KieBase(org.kie.api.KieBase) StatelessKieSession(org.kie.api.runtime.StatelessKieSession)

Example 3 with KieSessionModelImpl

use of org.drools.compiler.kproject.models.KieSessionModelImpl in project drools by kiegroup.

the class KieContainerImpl method newKieSession.

public KieSession newKieSession(String kSessionName, Environment environment, KieSessionConfiguration conf) {
    KieSessionModelImpl kSessionModel = kSessionName != null ? (KieSessionModelImpl) getKieSessionModel(kSessionName) : (KieSessionModelImpl) findKieSessionModel(false);
    if (kSessionModel == null) {
        log.error("Unknown KieSession name: " + kSessionName);
        return null;
    }
    if (kSessionModel.getType() == KieSessionModel.KieSessionType.STATELESS) {
        throw new RuntimeException("Trying to create a stateful KieSession from a stateless KieSessionModel: " + kSessionModel.getName());
    }
    KieBase kBase = getKieBase(kSessionModel.getKieBaseModel().getName());
    if (kBase == null) {
        log.error("Unknown KieBase name: " + kSessionModel.getKieBaseModel().getName());
        return null;
    }
    KieSession kSession = kBase.newKieSession(conf != null ? conf : getKieSessionConfiguration(kSessionModel), environment);
    if (isJndiAvailable()) {
        wireSessionComponents(kSessionModel, kSession);
    }
    registerLoggers(kSessionModel, kSession);
    ((StatefulKnowledgeSessionImpl) kSession).initMBeans(containerId, ((InternalKnowledgeBase) kBase).getId(), kSessionModel.getName());
    kSessions.put(kSessionModel.getName(), kSession);
    return kSession;
}
Also used : KieSessionModelImpl(org.drools.compiler.kproject.models.KieSessionModelImpl) KieBase(org.kie.api.KieBase) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession)

Example 4 with KieSessionModelImpl

use of org.drools.compiler.kproject.models.KieSessionModelImpl in project drools by kiegroup.

the class KieCDIExtension method addKSessionBean.

public void addKSessionBean(AfterBeanDiscovery abd, KieCDIEntry entry) {
    ReleaseId releaseId = entry.getReleaseId();
    // default to classpath, but allow it to be overriden
    KieContainerImpl kieContainer = classpathKContainer;
    if (releaseId != null) {
        kieContainer = (KieContainerImpl) gavs.get(releaseId);
        if (kieContainer == null) {
            log.error("Unable to create KSession({}), could not retrieve KieContainer for ReleaseId {}", entry.getValue(), releaseId.toString());
            return;
        }
    }
    KieProject kProject = kieContainer.getKieProject();
    String kSessionName = entry.getValue();
    KieSessionModel kSessionModel = null;
    if (StringUtils.isEmpty(kSessionName)) {
        kSessionModel = (entry.getType() == KieSession.class) ? kProject.getDefaultKieSession() : kProject.getDefaultStatelessKieSession();
    } else {
        kSessionModel = kProject.getKieSessionModel(kSessionName);
    }
    if (kSessionModel == null) {
        log.error("Annotation @KSession({}) found, but no KieSessionModel exists.\nEither the required kmodule.xml does not exist, is corrupted, or is missing the KieBase entry", kSessionName);
        return;
    }
    if (kSessionModel.getScope() != null && !kSessionModel.getScope().trim().equals(entry.getScope().getClass().getName())) {
        try {
            if (kSessionModel.getScope().indexOf('.') >= 0) {
                entry.setScope((Class<? extends Annotation>) Class.forName(kSessionModel.getScope()));
            } else {
                entry.setScope((Class<? extends Annotation>) Class.forName("javax.enterprise.context." + kSessionModel.getScope()));
            }
        } catch (ClassNotFoundException e) {
            log.error("KieBaseModule {} overrides default annotation, but it was not able to find it {}\n{}", new String[] { kSessionName, kSessionModel.getScope(), e.getMessage() });
        }
    }
    if (KieSessionType.STATELESS.equals(kSessionModel.getType())) {
        if (log.isDebugEnabled()) {
            InternalKieModule kModule = kProject.getKieModuleForKBase(((KieSessionModelImpl) kSessionModel).getKieBaseModel().getName());
            log.debug("Added Bean for Stateless @KSession({}) from: {}", kSessionName, kModule);
        }
        abd.addBean(new StatelessKSessionBean(kSessionModel, kieContainer, entry.getKReleaseId(), entry.getScope(), entry.getName(), entry.getInjectionPoints()));
    } else {
        InternalKieModule kModule = kProject.getKieModuleForKBase(((KieSessionModelImpl) kSessionModel).getKieBaseModel().getName());
        log.debug("Added Bean for Stateful @KSession({})  from: {}", kSessionName, kModule);
        abd.addBean(new StatefulKSessionBean(kSessionName, kSessionModel, kieContainer, entry.getKReleaseId(), entry.getScope(), entry.getName(), entry.getInjectionPoints()));
    }
}
Also used : KieSessionModelImpl(org.drools.compiler.kproject.models.KieSessionModelImpl) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) KReleaseId(org.kie.api.cdi.KReleaseId) ReleaseId(org.kie.api.builder.ReleaseId) KieSessionModel(org.kie.api.builder.model.KieSessionModel) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

KieSessionModelImpl (org.drools.compiler.kproject.models.KieSessionModelImpl)4 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)3 KieBase (org.kie.api.KieBase)2 KieSessionModel (org.kie.api.builder.model.KieSessionModel)2 KieSession (org.kie.api.runtime.KieSession)2 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 KieProject (org.drools.compiler.kie.builder.impl.KieProject)1 KieBaseModelImpl (org.drools.compiler.kproject.models.KieBaseModelImpl)1 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)1 StatelessKnowledgeSessionImpl (org.drools.core.impl.StatelessKnowledgeSessionImpl)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 KReleaseId (org.kie.api.cdi.KReleaseId)1