use of org.kie.api.builder.KieRepository in project drools by kiegroup.
the class DefaultKieSessionFromFileExample method go.
public void go(PrintStream out) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource(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();
}
use of org.kie.api.builder.KieRepository in project drools by kiegroup.
the class KieModuleFromMultipleFilesExample method go.
public void go(PrintStream out) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
Resource ex1Res = ks.getResources().newFileSystemResource(getFile("kiebase-inclusion"));
Resource ex2Res = ks.getResources().newFileSystemResource(getFile("named-kiesession"));
KieModule kModule = kr.addKieModule(ex1Res, ex2Res);
KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
KieSession kSession = kContainer.newKieSession("ksession2");
kSession.setGlobal("out", out);
Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
kSession.insert(msg1);
kSession.fireAllRules();
Object msg2 = createMessage(kContainer, "Dave", "Open the pod bay doors, HAL.");
kSession.insert(msg2);
kSession.fireAllRules();
}
use of org.kie.api.builder.KieRepository in project drools by kiegroup.
the class KieFileSystemExample method go.
public void go(PrintStream out) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/org/kie/example5/HAL5.drl", getRule());
KieBuilder kb = ks.newKieBuilder(kfs);
// kieModule is automatically deployed to KieRepository if successfully built.
kb.buildAll();
if (kb.getResults().hasMessages(Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieSession kSession = kContainer.newKieSession();
kSession.setGlobal("out", out);
kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?"));
kSession.fireAllRules();
}
use of org.kie.api.builder.KieRepository in project drools by kiegroup.
the class PerformanceExample method loadContainerFromString.
private static KieContainer loadContainerFromString(String rules) {
long startTime = System.currentTimeMillis();
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/examples/pertest.drl", rules);
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
long endTime = System.currentTimeMillis();
System.out.println("Time to build rules : " + (endTime - startTime) + " ms");
startTime = System.currentTimeMillis();
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
endTime = System.currentTimeMillis();
System.out.println("Time to load container: " + (endTime - startTime) + " ms");
return kContainer;
}
use of org.kie.api.builder.KieRepository in project drools by kiegroup.
the class KieModuleRepoTest method createMockKieContainer.
private static KieContainerImpl createMockKieContainer(final ReleaseId projectReleaseId, final KieModuleRepo kieModuleRepo) throws Exception {
// kie module
final InternalKieModule mockKieProjectKieModule = mock(InternalKieModule.class);
final ResourceProvider mockKieProjectKieModuleResourceProvider = mock(ResourceProvider.class);
when(mockKieProjectKieModule.createResourceProvider()).thenReturn(mockKieProjectKieModuleResourceProvider);
// kie project
final KieModuleKieProject kieProject = new KieModuleKieProject(mockKieProjectKieModule);
final KieModuleKieProject mockKieProject = spy(kieProject);
doNothing().when(mockKieProject).init();
doReturn(projectReleaseId).when(mockKieProject).getGAV();
doReturn(new HashMap<String, KieBaseModel>()).when(mockKieProject).updateToModule(any(InternalKieModule.class));
// kie repository
final KieRepository kieRepository = new KieRepositoryImpl();
final Field kieModuleRepoField = KieRepositoryImpl.class.getDeclaredField("kieModuleRepo");
kieModuleRepoField.setAccessible(true);
kieModuleRepoField.set(kieRepository, kieModuleRepo);
kieModuleRepoField.setAccessible(false);
// kie container
final KieContainerImpl kieContainerImpl = new KieContainerImpl(mockKieProject, kieRepository);
return kieContainerImpl;
}
Aggregations