Search in sources :

Example 6 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl 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

KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)6 ReleaseId (org.kie.api.builder.ReleaseId)5 KieProject (org.drools.compiler.kie.builder.impl.KieProject)3 Test (org.junit.Test)3 KReleaseId (org.kie.api.cdi.KReleaseId)3 KieContainer (org.kie.api.runtime.KieContainer)3 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 FileKieModule (org.drools.compiler.kie.builder.impl.FileKieModule)1 KieModuleKieProject (org.drools.compiler.kie.builder.impl.KieModuleKieProject)1 ResultsImpl (org.drools.compiler.kie.builder.impl.ResultsImpl)1 ZipKieModule (org.drools.compiler.kie.builder.impl.ZipKieModule)1 KieSessionModelImpl (org.drools.compiler.kproject.models.KieSessionModelImpl)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 KieBase (org.kie.api.KieBase)1 KieServices (org.kie.api.KieServices)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 KieSessionModel (org.kie.api.builder.model.KieSessionModel)1