当前位置: 首页>>代码示例>>Java>>正文


Java KieContainer类代码示例

本文整理汇总了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);
}
 
开发者ID:edgexfoundry,项目名称:support-rulesengine,代码行数:15,代码来源:RuleEngine.java

示例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());
    }
 
开发者ID:barrykalok,项目名称:spring-boot-drools-example,代码行数:21,代码来源:RuleService.java

示例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();

}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:19,代码来源:DroolsScoreExample.java

示例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;
}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:26,代码来源:ReloadDroolsRulesService.java

示例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();

}
 
开发者ID:Salaboy,项目名称:drools-game-engine,代码行数:24,代码来源:E_NoCDIRulesTest.java

示例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);
}
 
开发者ID:sabre1041,项目名称:iot-ocp,代码行数:25,代码来源:BaseTest.java

示例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();
	}
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:18,代码来源:KieScannerTest.java

示例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");
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:19,代码来源:ProcessPersistenceTest.java

示例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();
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:20,代码来源:MavenArtifactTest.java

示例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();
	}
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:18,代码来源:KieScannerRemoteTest.java

示例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));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:PatchedRuntimeEnvironmentBuilder.java

示例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());
}
 
开发者ID:jeichler,项目名称:junit-drools,代码行数:26,代码来源:DroolsTestSupport.java

示例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();
}
 
开发者ID:gratiartis,项目名称:qzr,代码行数:18,代码来源:HrMaxQuizService.java

示例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));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:19,代码来源:PatchedRuntimeEnvironmentBuilder.java

示例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);
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:17,代码来源:SessionServiceImpl.java


注:本文中的org.kie.api.runtime.KieContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。