本文整理汇总了Java中org.kie.api.runtime.KieContainer类的典型用法代码示例。如果您正苦于以下问题:Java KieContainer类的具体用法?Java KieContainer怎么用?Java KieContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KieContainer类属于org.kie.api.runtime包,在下文中一共展示了KieContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initKie
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
private void initKie() {
KieServices ks = KieServices.Factory.get();
kfs = ks.newKieFileSystem();
uploadDroolFiles();
KieBuilder kbuilder = ks.newKieBuilder(kfs);
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(Level.ERROR)) {
throw new IllegalArgumentException(kbuilder.getResults().toString());
}
KieContainer kcontainer = ks.newKieContainer(kbuilder.getKieModule().getReleaseId());
KieBaseConfiguration kbConfig = KieServices.Factory.get().newKieBaseConfiguration();
kbConfig.setOption(ConstraintJittingThresholdOption.get(-1));
kbase = kcontainer.newKieBase(kbConfig);
}
示例2: refreshContainer
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
public void refreshContainer(String containerName){
logger.info("refreshing container {}", containerName);
ReleaseId releaseId = new ReleaseIdImpl("org.demo.rule", containerName, "1.0.0-" + UUID.randomUUID().toString().replaceAll("-", ""));
// retrieve rules from db
List<String> rules = ruleBucket.findAll().stream().map((r -> r.getContent())).collect(Collectors.toList());
logger.info("total {} rules for [{}]", rules.size(), ruleBucket);
Resource resource = kieServices.getResources().newByteArrayResource(RuleEngineUtil.createKJar(releaseId, rules));
KieModule module = kieServices.getRepository().addKieModule(resource);
KieContainer kieContainer = kieServices.newKieContainer(module.getReleaseId());
// create container is heavy, we only create once and cache it
containerMap.put(containerName, kieContainer);
// remove the repo immediately
kieServices.getRepository().removeKieModule(module.getReleaseId());
}
示例3: execute
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
public static void execute( KieContainer kc ) throws Exception{
// From the container, a session is created based on
// its definition and configuration in the META-INF/kmodule.xml file
KieSession ksession = kc.newKieSession("point-rulesKS");
List<Order> orderList = getInitData();
for (int i = 0; i < orderList.size(); i++) {
Order o = orderList.get(i);
ksession.insert(o);
ksession.fireAllRules();
// 执行完规则后, 执行相关的逻辑
addScore(o);
}
ksession.dispose();
}
示例4: loadContainerFromString
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
private KieContainer loadContainerFromString(List<Rule> rules) {
long startTime = System.currentTimeMillis();
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (Rule rule:rules) {
String drl=rule.getContent();
kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl);
}
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;
}
示例5: helloDroolsTest
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Test
public void helloDroolsTest() {
System.out.println( "Bootstrapping the Rule Engine ..." );
// Bootstrapping a Rule Engine Session
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.newKieClasspathContainer();
KieBase kBase = kContainer.getKieBase( "confKBase" );
KieSession kSession = kBase.newKieSession();
ArrayList<String> errors = new ArrayList<String>();
kSession.setGlobal( "errors", errors );
House house = new House( "Maniac Mansion" );
kSession.insert( house );
int fired = kSession.fireAllRules();
assertEquals( 1, fired );
assertEquals( 1, errors.size() );
assertThat( errors, Matchers.contains( "Warn: Your House ( " + house.getName() + " ) has no Rooms" ) );
kSession.dispose();
}
示例6: setup
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Before
public void setup() {
KieServices kieServices = KieServices.Factory.get();
KieContainer kContainer = kieServices.getKieClasspathContainer();
Results verifyResults = kContainer.verify();
for (Message m : verifyResults.getMessages()) {
LOG.debug("Kie container message: {}", m);
}
KieBase kieBase = kContainer.getKieBase();
LOG.debug("Created kieBase");
for ( KiePackage kp : kieBase.getKiePackages() ) {
for (Rule rule : kp.getRules()) {
LOG.debug("kp " + kp + " rule " + rule.getName());
}
}
session = kieBase.newKieSession();
LOG.info(session.getGlobals().toString());
Logger kieLogger = LoggerFactory.getLogger(this.getClass());
// session.setGlobal("logger",kieLogger);
}
示例7: doTest
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Test
public void doTest() throws InterruptedException {
new UrlResource();
KieServices kieServices = KieServices.Factory.get();
ReleaseIdImpl releaseId = new ReleaseIdImpl(G, A, V);
KieContainer kContainer = KieServices.Factory.get().newKieContainer(
releaseId);
KieScanner kScanner = kieServices.newKieScanner(kContainer);
KieSession kSession = kContainer.newKieSession();
kScanner.start(3000);
// KieScanner will continue scanning the server looking for artifact
// update
while (true) {
Thread.sleep(3000);
kSession.fireAllRules();
}
}
示例8: doTest
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Test
public void doTest() {
logger.info("Running test using persistence");
// start our mock DB
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
// setting persistence
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
// to load our kbase
KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
KieBase kb = kc.getKieBase("TestProcessKB");
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
StatefulKnowledgeSession kSession = JPAKnowledgeService
.newStatefulKnowledgeSession(kb, null, env);
kSession.startProcess("HelloWorldProcess");
}
示例9: doTest
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Test
public void doTest() throws IOException {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
UrlResource urlResource = (UrlResource) ks.getResources().newUrlResource(URL);
urlResource.setUsername(USER);
urlResource.setPassword(PASSWORD);
urlResource.setBasicAuthentication("enabled");
InputStream is = urlResource.getInputStream();
KieModule kModule = kr.addKieModule(ks.getResources().newInputStreamResource(is));
KieContainer kc = ks.newKieContainer(kModule.getReleaseId());
// This fact was created using Data Modeller in business central
// Product p = new Product();
// p.setName("Table");
// p.setPrice(500f);
KieSession kSession = kc.newKieSession();
// kSession.insert(p);
kSession.fireAllRules();
}
示例10: doTest
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Test
public void doTest() throws InterruptedException {
//System.setProperty("kie.maven.settings.custom", value)
KieServices kieServices = KieServices.Factory.get();
ReleaseIdImpl releaseId = new ReleaseIdImpl(G, A, V);
KieContainer kContainer = KieServices.Factory.get().newKieContainer(
releaseId);
KieScanner kScanner = kieServices.newKieScanner(kContainer);
KieSession kSession = kContainer.newKieSession();
kScanner.start(3000);
// KieScanner will continue scanning the server looking for artifact
// update
while (true) {
Thread.sleep(3000);
kSession.fireAllRules();
}
}
示例11: setupClasspathKmoduleBuilder
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder(KieContainer kieContainer,
String kbaseName,
String ksessionName) {
if (StringUtils.isEmpty(kbaseName)) {
KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel();
if (defaultKBaseModel != null) {
kbaseName = defaultKBaseModel.getName();
} else {
kbaseName = DEFAULT_KBASE_NAME;
}
}
InternalKieModule module = (InternalKieModule) ((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName);
if (module == null) {
throw new IllegalStateException("Cannot find kbase with name " + kbaseName);
}
KieBase kbase = kieContainer.getKieBase(kbaseName);
return getDefault()
.knowledgeBase(kbase)
.classLoader(kieContainer.getClassLoader())
.registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
}
示例12: createKieContainer
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
private KieContainer createKieContainer(String... ruleFiles) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
for (String ruleFile : ruleFiles) {
InputStream ruleFileIs = DroolsTestSupport.class.getResourceAsStream("/" + ruleFile);
Assert.assertNotNull("Can't open stream for rule file. Does it exist?", ruleFileIs);
kfs.write(ks.getResources().newInputStreamResource(ruleFileIs).setSourcePath(ruleFile));
try {
ruleFileIs.close();
} catch (IOException e) {
throw new RuntimeException("InputStream of rule file could not be closed.");
}
}
kieBuilder.buildAll();
StringBuilder message = new StringBuilder();
List<Message> messages = kieBuilder.getResults().getMessages();
for (Message m : messages) {
message.append(m.toString()).append("\n");
}
Assert.assertEquals(message.toString(), 0, messages.size());
return ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
}
示例13: HrMaxQuizService
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Autowired
public HrMaxQuizService(KieContainer kieContainer, SimpMessagingTemplate template) {
log.info("Initialising a new quiz session.");
this.kieSession = kieContainer.newKieSession("HrmaxSession");
this.agendaEventPublisher = new PublishingAgendaEventListener(template);
this.agendaEventListener = new LoggingAgendaEventListener();
this.ruleRuntimeEventListener = new LoggingRuleRuntimeEventListener();
this.kieSession.addEventListener(agendaEventPublisher);
this.kieSession.addEventListener(agendaEventListener);
this.kieSession.addEventListener(ruleRuntimeEventListener);
this.kieSession.fireAllRules();
}
示例14: setupClasspathKmoduleBuilder
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder(KieContainer kieContainer, String kbaseName, String ksessionName) {
if (StringUtils.isEmpty(kbaseName)) {
KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel();
if (defaultKBaseModel != null) {
kbaseName = defaultKBaseModel.getName();
} else {
kbaseName = DEFAULT_KBASE_NAME;
}
}
InternalKieModule module = (InternalKieModule)((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName);
if (module == null) {
throw new IllegalStateException("Cannot find kbase with name " + kbaseName);
}
KieBase kbase = kieContainer.getKieBase(kbaseName);
return getDefault().knowledgeBase(kbase).classLoader(kieContainer.getClassLoader())
.registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
}
示例15: newDefaultKieSessionWithPseudoClock
import org.kie.api.runtime.KieContainer; //导入依赖的package包/类
@Override
public KieSession newDefaultKieSessionWithPseudoClock(final KieModule project) {
KieContainer kieContainer = buildInfoService.getBuildInfo(project).getKieContainer();
//If a KieContainer could not be built there is a build error somewhere; so return null to be handled elsewhere
if (kieContainer == null) {
return null;
}
//We always need a pseudo clock
final SessionConfiguration conf = SessionConfiguration.newInstance();
conf.setClockType(ClockType.PSEUDO_CLOCK);
return kieContainer.getKieBase().newKieSession(conf, null);
}