Search in sources :

Example 81 with KieContainer

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));
}
Also used : KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 82 with KieContainer

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);
}
Also used : IoUtils.readBytesFromInputStream(org.drools.core.util.IoUtils.readBytesFromInputStream) InputStream(java.io.InputStream) ReleaseId(org.kie.api.builder.ReleaseId) URL(java.net.URL) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 83 with KieContainer

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);
    }
}
Also used : KieContainer(org.kie.api.runtime.KieContainer)

Example 84 with KieContainer

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;
}
Also used : KieServices(org.kie.api.KieServices) RegistryContext(org.drools.core.command.impl.RegistryContext) KieContainer(org.kie.api.runtime.KieContainer)

Example 85 with 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;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) RequestContextImpl(org.drools.core.command.RequestContextImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

KieContainer (org.kie.api.runtime.KieContainer)357 KieServices (org.kie.api.KieServices)271 Test (org.junit.Test)246 KieSession (org.kie.api.runtime.KieSession)191 ReleaseId (org.kie.api.builder.ReleaseId)185 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)108 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)90 KieFileSystem (org.kie.api.builder.KieFileSystem)81 KieModule (org.kie.api.builder.KieModule)75 KieBuilder (org.kie.api.builder.KieBuilder)56 KieModuleModel (org.kie.api.builder.model.KieModuleModel)54 KieBase (org.kie.api.KieBase)49 ArrayList (java.util.ArrayList)44 Results (org.kie.api.builder.Results)40 Resource (org.kie.api.io.Resource)29 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)29 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)27 Message (org.drools.compiler.Message)26 KieBaseModel (org.kie.api.builder.model.KieBaseModel)26 InternalKieContainer (org.drools.core.impl.InternalKieContainer)25