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


Java KieSession.dispose方法代碼示例

本文整理匯總了Java中org.kie.api.runtime.KieSession.dispose方法的典型用法代碼示例。如果您正苦於以下問題:Java KieSession.dispose方法的具體用法?Java KieSession.dispose怎麽用?Java KieSession.dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.kie.api.runtime.KieSession的用法示例。


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

示例1: execute

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
public void execute(Object object) {
  try {
    KieSession ksession = kbase.newKieSession();
    if (!getRulenames().isEmpty()) {
      if (executor != null) {
        ksession.setGlobal("executor", executor);
        ksession.setGlobal("logger", logger);
        ksession.insert(object);
        int rulesFired = ksession.fireAllRules();
        logger.debug("Number of rules fired on event: " + rulesFired);
        if (rulesFired > 0) {
          logger.info("Event triggered " + rulesFired + "rules: " + (Event) object);
        }
      } else
        logger.error("Command Executor not available - no command sent for event: " + object);
    } else {
      logger.debug("No rules in the system - skipping firing rules");
    }
    ksession.dispose();
  } catch (Exception e) {
    logger.error("Error during rules enging processing:  " + e.getMessage());
  }
}
 
開發者ID:edgexfoundry,項目名稱:support-rulesengine,代碼行數:24,代碼來源:RuleEngine.java

示例2: execute

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

示例3: validateCandidate

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Transactional(readOnly = false)
@RequestMapping(value = "/{container}", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public
@ResponseBody
ValidateCandidateResponse validateCandidate(@PathVariable("container") String container, @Valid @RequestBody ValidateCandidateRequest req) {
    KieSession session = ruleService.getKieSession(container);

    RulePlaceholder candidate = new RulePlaceholder(req.getDetail());

    session.insert(candidate);
    session.fireAllRules();
    session.dispose();

    candidate.getResult().forEach((k, v) -> {
        logger.info(k + " : " + v);
    });

    ValidateCandidateResponse resp = new ValidateCandidateResponse();
    resp.setDetail(candidate.getResult());
    resp.setAnswer(candidate.getResult().size() == 0);

    return resp;
}
 
開發者ID:barrykalok,項目名稱:spring-boot-drools-example,代碼行數:24,代碼來源:ValidateController.java

示例4: helloDroolsTest

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

示例5: houseWithNoRoomsTest

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void houseWithNoRoomsTest() {

    KieSession kSession = kBase.newKieSession();

    ArrayList<String> errors = new ArrayList<String>();
    kSession.setGlobal( "errors", errors );
    House house = new House( "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,代碼行數:19,代碼來源:A_StatelessConformanceTest.java

示例6: roomWithoutAHouseAndDoorsTest

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void roomWithoutAHouseAndDoorsTest() {
    KieSession kSession = kBase.newKieSession();

    ArrayList<String> errors = new ArrayList<String>();
    kSession.setGlobal( "errors", errors );
    Room roomA = new Room( "Room A" );
    kSession.insert( roomA );

    int fired = kSession.fireAllRules();
    assertEquals( 2, fired );
    assertEquals( 2, errors.size() );
    assertThat(errors, Matchers.containsInAnyOrder("Warn: there is room ( " + roomA.getName() + " ) but there is no house", 
            "Warn: Your Room ( " + roomA.getName() + " ) has no Doors"));
    
    
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-game-engine,代碼行數:19,代碼來源:A_StatelessConformanceTest.java

示例7: lockedDoorWithNoKeyRulesTest

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void lockedDoorWithNoKeyRulesTest() {
    KieSession kSession = kBase.newKieSession();

    ArrayList<String> errors = new ArrayList<String>();
    kSession.setGlobal( "errors", errors );
    House house = new House( "Mansion" );

    Room roomA = new Room( "Room A" );
    Door doorA = new Door( "Door A" );
    kSession.insert( doorA );
    roomA.getDoors().add( doorA );
    kSession.insert( roomA );
    house.getRooms().add( roomA );
    kSession.insert( house );

    int fired = kSession.fireAllRules();
    assertEquals( 1, fired );
    assertEquals( 1, errors.size() );
    assertThat(errors, Matchers.contains("Warn: There is no key for this Door ( " + doorA.getName() + " )"));

    kSession.dispose();

}
 
開發者ID:Salaboy,項目名稱:drools-game-engine,代碼行數:25,代碼來源:A_StatelessConformanceTest.java

示例8: testPatientWithBloodPressureObservations

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testPatientWithBloodPressureObservations() {

    printGeneratedDRL( ClinicalRulesJUnitTest.class.getResourceAsStream( "/rules/clinical-decision-table.xls" ), System.out );

    Assert.assertNotNull( kBase );
    KieSession kSession = kBase.newKieSession();

    kSession.insert( generatePatients( 1 ).get( 0 ) );

    List<Observation> observations = generateObservations( "headache", 4 );
    for ( Observation observation : observations ) {
        kSession.insert( observation );
    }

    Assert.assertEquals( 2, kSession.fireAllRules() );

    QueryResults queryResults = kSession.getQueryResults( "getAllRecommendations", ( Object ) null );
    for ( QueryResultsRow row : queryResults ) {
        Recommendation r = ( Recommendation ) row.get( "$r" );
        System.out.println( " >>> Result : " + r );
    }

    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:26,代碼來源:ClinicalRulesJUnitTest.java

示例9: testSlowServiceInAGlobal

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testSlowServiceInAGlobal() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();

    kSession.setGlobal("myService", new SlowMyServiceImpl());
    System.out.println(" ---- Starting testSlowServiceInAGlobal() Test ---");

    List<Person> persons = generatePersons(20);
    for (Person p : persons) {
        kSession.insert(p);
    }

    Assert.assertEquals(20, kSession.fireAllRules());
    System.out.println(" ---- Finished testSlowServiceInAGlobal() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:18,代碼來源:WrongServiceRulesJUnitTest.java

示例10: testCallService

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:23,代碼來源:BPMServiceTests.java

示例11: testPatientAndAnObservation

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testPatientAndAnObservation() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testPatientAndAnObservation() Test ---");
    
    kSession.insert(new Patient()
        .setId("Patient/1")
    );
    kSession.insert(new Observation()
        .setId("Observation/1")
    );
    
    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientAndAnObservation() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:18,代碼來源:MultiConditionRulesJUnitTest.java

示例12: testYoungEnrolledStudentsGetBusTicketDiscount

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testYoungEnrolledStudentsGetBusTicketDiscount() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testEnrolledStudentsGetFreeBusTickets() Test ---");
    
    Person person = new Person("John", 29, "[email protected]", "London", Gender.MALE);
    kSession.insert(person);
    
    University university = new University("My uni");
    university.setEnrolled(Arrays.asList(person));
    
    kSession.insert(university);
    
    Assert.assertEquals(2, kSession.fireAllRules());
    System.out.println(" ---- Finished testEnrolledStudentsGetFreeBusTickets() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:19,代碼來源:SimpleInferenceRulesJUnitTest.java

示例13: testServiceInAGlobal

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testServiceInAGlobal() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    
    kSession.setGlobal("myService", new MyServiceImpl());
    System.out.println(" ---- Starting testServiceInAGlobal() Test ---");
    Room room = new Room("living room", 10);
    
    List<Person> persons = generatePersons(20);
    room.setPersons(persons);
    kSession.insert(room);

    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testServiceInAGlobal() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:18,代碼來源:UsingGlobalsRulesJUnitTest.java

示例14: testObservationAndPatient

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testObservationAndPatient() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testObservationAndPatient() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    kSession.insert(patient);
    
    Observation observation = (Observation) new Observation().setId("Observation/1");
    kSession.insert(observation);

    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testObservationAndPatient() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:17,代碼來源:NonFactsRulesJUnitTest.java

示例15: testServiceCallInRHS

import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testServiceCallInRHS() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();

    kSession.setGlobal("myConditionsProviderService", new MyConditionsProviderServiceImpl());
    System.out.println(" ---- Starting testServiceCallInRHS() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    FactHandle patientHandle = kSession.insert(patient);

    Assert.assertEquals(50, kSession.fireAllRules());
    
    //A modification of the patient will execute the service 
    patient.addName(new HumanNameDt().addFamily("Richards"));
    kSession.update(patientHandle, patient);
    Assert.assertEquals(50, kSession.fireAllRules());
    
    System.out.println(" ---- Finished testServiceCallInRHS() Test ---");
    kSession.dispose();
}
 
開發者ID:Salaboy,項目名稱:drools-workshop,代碼行數:22,代碼來源:WrongServiceRulesJUnitTest.java


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