use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class WireChannelTest method testWireChannel.
@Test
public void testWireChannel() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "listener-test", "1.0-SNAPSHOT");
build(ks, releaseId);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieSession ksession = kieContainer.newKieSession();
ksession.fireAllRules();
assertEquals(1, channelMessages.size());
assertEquals("Test Message", channelMessages.get(0));
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieProjectRuntimeModulesTest method createModuleAndFindResources.
@Test
public void createModuleAndFindResources() throws IOException, ClassNotFoundException, InterruptedException {
createKieModule("fol4", false);
ReleaseId releaseId = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT");
KieContainer kieContainer = KieServices.Factory.get().newKieContainer(releaseId);
assertNotNull(kieContainer);
InputStream is = kieContainer.getClassLoader().getResourceAsStream("/META-INF/beans.xml");
assertNotNull(is);
byte[] bytesFromStream = readBytesFromInputStream(is);
Enumeration<URL> foundResources = kieContainer.getClassLoader().getResources("/META-INF/beans.xml");
assertNotNull(foundResources);
List<URL> resourcesAsList = Collections.list(foundResources);
assertNotNull(resourcesAsList);
assertEquals(1, resourcesAsList.size());
URL resourceUrl = resourcesAsList.get(0);
byte[] bytesFromURL = readBytesFromInputStream(resourceUrl.openStream());
assertTrue(Arrays.equals(bytesFromStream, bytesFromURL));
String url = resourceUrl.toString();
assertNotNull(url);
assertEquals("mfs:/META-INF/beans.xml", url);
String file = resourceUrl.getFile();
assertNotNull(file);
assertEquals("/META-INF/beans.xml", file);
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieServicesImpl method newKieClasspathContainer.
public KieContainer newKieClasspathContainer(String containerId, ClassLoader classLoader) {
if (containerId == null) {
KieContainerImpl newContainer = new KieContainerImpl(UUID.randomUUID().toString(), new ClasspathKieProject(classLoader, listener), null);
return newContainer;
}
if (kContainers.get(containerId) == null) {
KieContainerImpl newContainer = new KieContainerImpl(containerId, new ClasspathKieProject(classLoader, listener), null);
KieContainer check = kContainers.putIfAbsent(containerId, newContainer);
if (check == null) {
return newContainer;
} else {
newContainer.dispose();
throw new IllegalStateException("There's already another KieContainer created with the id " + containerId);
}
} else {
throw new IllegalStateException("There's already another KieContainer created with the id " + containerId);
}
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class GetKieContainerCommand method execute.
public KieContainer execute(Context context) {
// use the new API to retrieve the session by ID
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.newKieContainer(releaseId);
((RegistryContext) context).register(KieContainer.class, kieContainer);
return kieContainer;
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class ApplyPmmlModelCommand method execute.
@Override
public PMML4Result execute(Context context) {
PMML4Result resultHolder = new PMML4Result(requestData.getCorrelationId());
RequestContextImpl ctx = (RequestContextImpl) context;
KieBase kbase = ((RegistryContext) context).lookup(KieBase.class);
if (kbase == null) {
System.out.println("KieBase not found in context!");
return null;
} else {
KieContainer kcont = ((KnowledgeBaseImpl) kbase).getKieContainer();
kcont.getKieBaseNames().forEach(n -> {
System.out.println(n);
});
kbase.getKiePackages().forEach(kp -> {
System.out.println("Package: " + kp.getName());
});
}
return null;
// RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
// DataSource<PMMLRequestData> data = executor.newDataSource("request", this.requestData);
// DataSource<PMML4Result> resultData = executor.newDataSource("results", resultHolder);
// System.out.println("Setting result: "+resultHolder);
// ctx.lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, resultHolder);
// return resultHolder;
}
Aggregations