當前位置: 首頁>>代碼示例>>Java>>正文


Java KieServices類代碼示例

本文整理匯總了Java中org.kie.api.KieServices的典型用法代碼示例。如果您正苦於以下問題:Java KieServices類的具體用法?Java KieServices怎麽用?Java KieServices使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KieServices類屬於org.kie.api包,在下文中一共展示了KieServices類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initKie

import org.kie.api.KieServices; //導入依賴的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: createKJar

import org.kie.api.KieServices; //導入依賴的package包/類
public static byte[] createKJar(ReleaseId releaseId, List<String> drls) {
    KieServices kieServices = KieServices.Factory.get();
    KieFileSystem kfs = kieServices.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    drls.forEach(drl -> kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl));
    KieBuilder kb = kieServices.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        for (Message result : kb.getResults().getMessages()) {
            System.out.println(result.getText());
        }
        return null;
    }
    InternalKieModule kieModule = (InternalKieModule) kieServices.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
 
開發者ID:barrykalok,項目名稱:spring-boot-drools-example,代碼行數:17,代碼來源:RuleEngineUtil.java

示例3: testDeleteProcess

import org.kie.api.KieServices; //導入依賴的package包/類
@Test
public void testDeleteProcess() {

	RuntimeManager manager = createRuntimeManager("approval.bpmn");
	RuntimeEngine engine = getRuntimeEngine(null);
	KieSession ksession = engine.getKieSession();
	KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
	ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler());

	TaskService taskService = engine.getTaskService();

	long processInstanceId = startProcess(ksession, taskService);

	callDelete(taskService);

	assertProcessInstanceCompleted(processInstanceId);

	System.out.println("Process instance completed");
	log.close();

	manager.disposeRuntimeEngine(engine);
	manager.close();
}
 
開發者ID:awizen,項目名稱:gangehi,代碼行數:24,代碼來源:ApprovalProcessTest.java

示例4: loadDrools

import org.kie.api.KieServices; //導入依賴的package包/類
private void loadDrools() {
	try {
		logger.info("Initializing Drools rule engine");
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		addDrls(kbuilder);

		KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
		config.setOption(ClockTypeOption.get("pseudo"));

		logger.debug("Compiling rules");
		kSession = kbuilder.newKieBase().newKieSession(config, null);
		homeioSessionClock = new HomeioSessionClock(kSession.getSessionClock());

		initGlobals();

		droolsInitialized = true;

		logger.debug("Successfully initialized Drools rule engine");

	} catch (Exception e) {
		logger.error("Exiting because of an exception during the Drools initialization ", e);
		new RuntimeException("Exiting because of an exception during the Drools initialization");
	}
}
 
開發者ID:IncQueryLabs,項目名稱:smarthome-cep-demonstrator,代碼行數:26,代碼來源:DroolsEventBusClient.java

示例5: loadContainerFromString

import org.kie.api.KieServices; //導入依賴的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

示例6: createKieFileSystemWithKProject

import org.kie.api.KieServices; //導入依賴的package包/類
/** 
 * 創建默認的kbase和stateful的kiesession 
 * 
 * @param ks 
 * @param isdefault 
 * @return 
 */  
public static KieFileSystem createKieFileSystemWithKProject(KieServices ks, boolean isdefault) {  
    KieModuleModel kproj = ks.newKieModuleModel();  
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase").setDefault(isdefault)  
            .setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);  
    // Configure the KieSession.  
    kieBaseModel1.newKieSessionModel("KSession").setDefault(isdefault)  
            .setType(KieSessionModel.KieSessionType.STATEFUL);  
    KieFileSystem kfs = ks.newKieFileSystem();  
    kfs.writeKModuleXML(kproj.toXML());  
    return kfs;  
}
 
開發者ID:lansheng228,項目名稱:kie-dynamic-rule,代碼行數:19,代碼來源:DroolsUtils.java

示例7: helloDroolsTest

import org.kie.api.KieServices; //導入依賴的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

示例8: buildRelease

import org.kie.api.KieServices; //導入依賴的package包/類
private static void buildRelease(ReleaseId releaseId, Resource pomResource, Resource kmodule, String... resources) {
    if (releases.contains(releaseId)) {
        ks.getRepository().removeKieModule(releaseId);
    }
    KieServices kieServices = KieServices.Factory.get();

    KieFileSystem kfs = kieServices.newKieFileSystem();

    kfs.write("pom.xml", pomResource);

    kfs.write("src/main/resources/META-INF/kmodule.xml", kmodule);

    for (String res : resources) {
        Resource resource = new ClassPathResource(res);
        kfs.write("src/main/resources/" + res, resource);
    }

    hasErrors(kieServices.newKieBuilder(kfs).buildAll().getResults());

    releases.add(releaseId);
}
 
開發者ID:redhat-italy,項目名稱:hacep,代碼行數:22,代碼來源:KieAPITestUtils.java

示例9: processRules

import org.kie.api.KieServices; //導入依賴的package包/類
public Measure processRules(@Body Measure measure) {
	
	KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
			kieHost, kieUser,
			kiePassword);
	
	Set<Class<?>> jaxBClasses = new HashSet<Class<?>>();
	jaxBClasses.add(Measure.class);
	
	config.addJaxbClasses(jaxBClasses);
	config.setMarshallingFormat(MarshallingFormat.JAXB);
	RuleServicesClient client = KieServicesFactory.newKieServicesClient(config)
			.getServicesClient(RuleServicesClient.class);

       List<Command<?>> cmds = new ArrayList<Command<?>>();
	KieCommands commands = KieServices.Factory.get().getCommands();
	cmds.add(commands.newInsert(measure));
	
    GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
    getObjectsCommand.setOutIdentifier("objects");

	
	cmds.add(commands.newFireAllRules());
	cmds.add(getObjectsCommand);
	BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds,
			"DecisionTableKS");
	ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("iot-ocp-businessrules-service", myCommands);
			
	List responseList = (List) response.getResult().getValue("objects");
	
	Measure responseMeasure = (Measure) responseList.get(0);
	
	return responseMeasure;

}
 
開發者ID:sabre1041,項目名稱:iot-ocp,代碼行數:36,代碼來源:BusinessRulesBean.java

示例10: setup

import org.kie.api.KieServices; //導入依賴的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

示例11: buildSession

import org.kie.api.KieServices; //導入依賴的package包/類
/**
 * Load all .drl files
 *
 * if a rule does not compile an exception will be thrown indicating the problem
 *
 * @param path
 * @return - session containing all loaded rules
 * @throws Exception
 */
public KieSession buildSession() throws Exception {
  kieServices = KieServices.Factory.get();
  KieRepository kr = kieServices.getRepository();
  kfs = kieServices.newKieFileSystem();
  if(rules != null){
    loadFromList();
  }
  else{
    loadFromFiles();
  }
  kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
  Results results = kieBuilder.getResults();
  if( results.hasMessages( Message.Level.ERROR ) ){
      System.out.println( results.getMessages() );
      throw new IllegalStateException( results.getMessages() + "" );
  }
  kieContainer =
      kieServices.newKieContainer( kr.getDefaultReleaseId() );
  ksession = kieContainer.newKieSession();
  ksession.addEventListener(new RuleTracker());
  return ksession;
}
 
開發者ID:folio-org,項目名稱:raml-module-builder,代碼行數:32,代碼來源:Rules.java

示例12: DroolsRulesEngineImpl

import org.kie.api.KieServices; //導入依賴的package包/類
public DroolsRulesEngineImpl() {
    log.debug("Creating instance.");
    ks = KieServices.Factory.get();
    kc = ks.getKieClasspathContainer();
    kSession = kc.newKieSession(SESSION_NAME);

    if (log.isTraceEnabled()) {
        kSession.addEventListener(new DebugAgendaEventListener());
        kSession.addEventListener(new DebugRuleRuntimeEventListener());
    }

    minReportingIntervalData = new Integer(
            HawkularProperties.getProperty(MIN_REPORTING_INTERVAL_DATA,
                    MIN_REPORTING_INTERVAL_DATA_ENV,
                    MIN_REPORTING_INTERVAL_DATA_DEFAULT));

    minReportingIntervalEvents = new Integer(
            HawkularProperties.getProperty(MIN_REPORTING_INTERVAL_EVENTS,
                    MIN_REPORTING_INTERVAL_EVENTS_ENV,
                    MIN_REPORTING_INTERVAL_EVENTS_DEFAULT));
}
 
開發者ID:hawkular,項目名稱:hawkular-alerts,代碼行數:22,代碼來源:DroolsRulesEngineImpl.java

示例13: doTest

import org.kie.api.KieServices; //導入依賴的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

示例14: doTest

import org.kie.api.KieServices; //導入依賴的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

示例15: doTest

import org.kie.api.KieServices; //導入依賴的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


注:本文中的org.kie.api.KieServices類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。