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);
}
}
}
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;
}
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;
}
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()));
}
}
Aggregations