use of org.drools.compiler.kie.builder.impl.KieProject 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()));
}
}
use of org.drools.compiler.kie.builder.impl.KieProject in project drools by kiegroup.
the class ClassLoaderLeakTest method buildKjarsInALoop.
private void buildKjarsInALoop(boolean withExecModel) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieContainer kieContainer = null;
int oldSize = Integer.MAX_VALUE;
for (int i = 0; i < 3; i++) {
KieModule kModule = buildKieModule("1.0." + i, RULES, withExecModel);
if (kieContainer == null) {
kieContainer = ks.newKieContainer(kModule.getReleaseId());
} else {
kieContainer.updateToVersion(kModule.getReleaseId());
}
KieProject kp = ((KieContainerImpl) kieContainer).getKieProject();
ProjectClassLoader cl = (ProjectClassLoader) kp.getClassLoader();
System.out.println(String.format("ProjectClassLoader.store size: %d, " + "retained bytes: %d.", cl.getStore().size(), cl.getStore().values().stream().map(b -> b.length).reduce(0, Integer::sum)));
assertTrue(cl.getStore().size() <= oldSize);
oldSize = cl.getStore().size();
kr.removeKieModule(kModule.getReleaseId());
}
}
use of org.drools.compiler.kie.builder.impl.KieProject in project drools by kiegroup.
the class DMNUpdateTest method test_as_kie_wb_common_services_backend_Builder.
@Test
public void test_as_kie_wb_common_services_backend_Builder() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
final KieContainer kieContainer = ks.newKieContainer(v100);
final KieSession kieSession = kieContainer.newKieSession();
final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
check0001_input_data_string(runtime);
// the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
// exhibit the issue.
final KieSession kieSession2 = kieContainer2.newKieSession();
final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime2);
assertThat(runtime2.getModels(), hasSize(1));
check0001_input_data_string(runtime2);
}
use of org.drools.compiler.kie.builder.impl.KieProject in project drools by kiegroup.
the class WBCommonServicesBackendTest method testAsKieWbCommonServicesBackendBuilder.
@Test
public void testAsKieWbCommonServicesBackendBuilder() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("wbcommonservicesbackend_app.dmn", this.getClass()), ks.getResources().newClassPathResource("wbcommonservicesbackend_route.dmn", this.getClass()));
final KieContainer kieContainer = ks.newKieContainer(v100);
final KieSession kieSession = kieContainer.newKieSession();
final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(2));
checkApp(runtime);
// the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
// exhibit the issue.
final KieSession kieSession2 = kieContainer2.newKieSession();
final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime2);
assertThat(runtime2.getModels(), hasSize(2));
checkApp(runtime2);
}
Aggregations