use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class KieServicesTest method testDisposeClearTheIDReference.
@Test
public void testDisposeClearTheIDReference() {
ReleaseId releaseId = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
createAndDeployJar(ks, releaseId, createDRL("ruleA"));
KieContainer c1 = ks.newKieContainer("id1", releaseId);
try {
ks.newKieClasspathContainer("id1");
fail("should not allow repeated container IDs.");
} catch (IllegalStateException is) {
// ok.
}
((KieContainerImpl) c1).dispose();
// now OK.
ks.newKieClasspathContainer("id1");
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project jbpm by kiegroup.
the class InjectableRegisterableItemsFactory method getWorkItemHandlers.
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handler = new HashMap<String, WorkItemHandler>();
handler.put("Human Task", getHTWorkItemHandler(runtime));
RuntimeManager manager = ((RuntimeEngineImpl) runtime).getManager();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ksession", runtime.getKieSession());
parameters.put("taskService", runtime.getTaskService());
parameters.put("runtimeManager", manager);
parameters.put("kieContainer", getRuntimeManager().getKieContainer());
try {
parameters.put("executorService", executorService.get());
} catch (Exception e) {
logger.debug("Executor service not available due to {}", e.getMessage());
}
if (kieContainer != null) {
// add classloader as one of the parameters so it can be easily referenced
parameters.put("classLoader", kieContainer.getClassLoader());
KieSessionModel ksessionModel = null;
if (StringUtils.isEmpty(ksessionName)) {
ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
if (ksessionModel == null) {
ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(DEFAULT_KIE_SESSION);
}
} else {
ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
}
if (ksessionModel == null) {
throw new IllegalStateException("Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml");
}
try {
InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
} catch (Throwable e) {
// use fallback mechanism
InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
}
}
try {
for (WorkItemHandlerProducer producer : workItemHandlerProducer) {
handler.putAll(producer.getWorkItemHandlers(manager.getIdentifier(), parameters));
}
} catch (Exception e) {
// do nothing as work item handler is considered optional
logger.warn("Exception while evalutating work item handler prodcuers {}", e.getMessage());
}
// add handlers from descriptor
handler.putAll(getWorkItemHandlersFromDescriptor(runtime));
return handler;
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class DMNRuntimeKBWrappingIKB method getListeners.
@Override
public List<DMNRuntimeEventListener> getListeners() {
if (knowledgeBase != null && knowledgeBase.getKieContainer() instanceof KieContainerImpl) {
KieBaseModelImpl kieBaseModel = (KieBaseModelImpl) ((KieContainerImpl) knowledgeBase.getKieContainer()).getKieProject().getKieBaseModel(knowledgeBase.getId());
ChainedProperties cp = ChainedProperties.getChainedProperties(getRootClassLoader());
Properties kmoduleProperties = new Properties();
kmoduleProperties.putAll(kieBaseModel.getKModule().getConfigurationProperties());
cp.addProperties(kmoduleProperties);
Map<String, String> listenersMap = new HashMap<>();
cp.mapStartsWith(listenersMap, DMNAssemblerService.DMN_RUNTIME_LISTENER_PREFIX, true);
logger.debug("{}", listenersMap);
return listenersMap.values().stream().map(this::loadEventListener).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).collect(Collectors.toList());
} else {
logger.warn("No DMNRuntime Listener can be provided, as created without a reference to KnowledgeBase");
}
return Collections.emptyList();
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class DMNUpdateTest method test_as_kie_wb_common_services_backend_Builder2.
@Test
public void test_as_kie_wb_common_services_backend_Builder2() 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("v1_2/dmn-hotcold.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));
checkDMNHotColdDMN12WithNSScattered(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));
checkDMNHotColdDMN12WithNSScattered(runtime2);
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class WBCommonServicesBackendTest method testProfileWithKieWbCommonServicesBackendBuilder.
@Test
public void testProfileWithKieWbCommonServicesBackendBuilder() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0.0");
final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("nowGT1970.dmn", this.getClass()));
final KieContainer kieContainer = ks.newKieContainer(v100);
final DMNRuntime runtime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
check_nowGT1970(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);
final DMNRuntime runtime2 = KieRuntimeFactory.of(kieContainer2.getKieBase()).get(DMNRuntime.class);
Assert.assertNotNull(runtime2);
assertThat(runtime2.getModels(), hasSize(1));
check_nowGT1970(runtime2);
}
Aggregations