Java Code Examples for org.kie.api.runtime.KieSession#destroy()

The following examples show how to use org.kie.api.runtime.KieSession#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestController.java    From drools-examples with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping("/address")
public void test(int num){
    Address address = new Address();
    address.setPostcode(generateRandom(num));
    KieSession kieSession = ReloadDroolsRulesService.kieContainer.newKieSession();

    AddressCheckResult result = new AddressCheckResult();
    kieSession.insert(address);
    kieSession.insert(result);
    int ruleFiredCount = kieSession.fireAllRules();
    kieSession.destroy();
    System.out.println("触发了" + ruleFiredCount + "条规则");

    if(result.isPostCodeResult()){
        System.out.println("规则校验通过");
    }

}
 
Example 2
Source File: TestController.java    From drools-examples with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping("/address")
public void test(int num){
    Address address = new Address();
    address.setPostcode(generateRandom(num));
    KieSession kieSession = kieContainer.newKieSession();

    AddressCheckResult result = new AddressCheckResult();
    kieSession.insert(address);
    kieSession.insert(result);
    int ruleFiredCount = kieSession.fireAllRules();
    kieSession.destroy();
    System.out.println("触发了" + ruleFiredCount + "条规则");

    if(result.isPostCodeResult()){
        System.out.println("规则校验通过");
    }

}
 
Example 3
Source File: TestController.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping("/address")
public String test(int num) {
    Address address = new Address();
    String postCode = generateRandom(num);
    System.out.println("post code : " + postCode);
    address.setPostcode(postCode);
    KieSession kieSession = kieContainer.newKieSession();

    AddressCheckResult result = new AddressCheckResult();
    kieSession.insert(address);
    kieSession.insert(result);
    int ruleFiredCount = kieSession.fireAllRules();
    kieSession.destroy();
    System.out.println("触发了" + ruleFiredCount + "条规则");

    if (result.isPostCodeResult()) {
        System.out.println("规则校验通过");
    }

    return postCode + "触发了" + ruleFiredCount + "条规则";

}
 
Example 4
Source File: DroolsUtils.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
/**
 * @param fact         事实
 * @param agendaFilter 具体选用拿个规则进行处理
 */
public static void execute ( Object fact , AgendaFilter agendaFilter ) {
    KieContainer     kieContainer = getKieContainer();
    final KieSession kieSession   = kieContainer.newKieSession();
    // 事实
    kieSession.insert( fact );
    // 开始计算
    kieSession.fireAllRules( agendaFilter );
    // 销毁
    kieSession.destroy();
}