Search in sources :

Example 51 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class CommonTestMethodBase method deployJar.

public static KieModule deployJar(KieServices ks, byte[] jar) {
    // Deploy jar into the repository
    Resource jarRes = ks.getResources().newByteArrayResource(jar);
    KieModule km = ks.getRepository().addKieModule(jarRes);
    return km;
}
Also used : Resource(org.kie.api.io.Resource) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 52 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class BuildtimeUtil method generateKJarFromKieBuilder.

public static void generateKJarFromKieBuilder(final KieBuilder kieBuilder, final boolean useCanonicalModel) throws IOException {
    final ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
    final InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
    final File kjarFile = bytesToTempFile(releaseId, kieModule.getBytes(), ".jar");
    final KieModule zipKieModule;
    if (useCanonicalModel) {
        zipKieModule = new CanonicalKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    } else {
        zipKieModule = new ZipKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    }
    KieServices.get().getRepository().addKieModule(zipKieModule);
}
Also used : ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 53 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class DefaultKieSessionFromByteArrayExampleTest method go.

public void go(PrintStream out) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieModule kModule = kr.addKieModule(ks.getResources().newByteArrayResource(getKjarAsByteArray(getFile("default-kiesession"))));
    KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
    KieSession kSession = kContainer.newKieSession();
    kSession.setGlobal("out", out);
    Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
    kSession.insert(msg1);
    kSession.fireAllRules();
}
Also used : KieRepository(org.kie.api.builder.KieRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 54 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class NamedKieSessionFromFileExample method go.

public void go(PrintStream out) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource(getFile("named-kiesession")));
    KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
    KieSession kSession = kContainer.newKieSession("ksession1");
    kSession.setGlobal("out", out);
    Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
    kSession.insert(msg1);
    kSession.fireAllRules();
}
Also used : KieRepository(org.kie.api.builder.KieRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 55 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class KieScannerMemoryTest method testScannerMemoryFootprint.

@Test
public void testScannerMemoryFootprint() throws IOException {
    final KieServices kieServices = KieServices.Factory.get();
    final KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    final KieModule kieModule = KieBaseUtil.getKieModuleAndBuildInstallModuleFromDrl(TestConstants.PACKAGE_FUNCTIONAL, KieBaseTestConfiguration.CLOUD_IDENTITY, "rule R when then end");
    final ReleaseId releaseId = kieModule.getReleaseId();
    repository.installArtifact(releaseId, (InternalKieModule) kieModule, MavenUtil.createPomXml(fileManager, releaseId));
    final KieContainer kieContainer = kieServices.newKieContainer(releaseId);
    final KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
    kieScanner.start(20);
    try {
        measureMemoryFootprint(1000, 100, 6, 30);
    } finally {
        kieScanner.stop();
    }
}
Also used : KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5