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


Java KieSession类代码示例

本文整理汇总了Java中org.kie.api.runtime.KieSession的典型用法代码示例。如果您正苦于以下问题:Java KieSession类的具体用法?Java KieSession怎么用?Java KieSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KieSession类属于org.kie.api.runtime包,在下文中一共展示了KieSession类的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: testDeleteProcess

import org.kie.api.runtime.KieSession; //导入依赖的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

示例3: doTest

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
@Test
public void doTest() {
    try {
    	KieBase kbase = getKieBase(URL, USER, PASSWORD);
        RuntimeManager manager = getRuntimeManager(kbase);        
        RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
        KieSession ksession = runtime.getKieSession();
        ksession.startProcess("test.proc_ht");

        // "sales-rep" reviews request
        TaskService taskService = runtime.getTaskService();
		long taskId = taskService.getTasksAssignedAsPotentialOwner(TASK_USER, "en-UK").get(0).getId();
		taskService.claim(taskId, TASK_USER);
		taskService.start(taskId, TASK_USER);
		taskService.complete(taskId, TASK_USER, null);
		System.out.println("Process instance completed");
		manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:23,代码来源:HumanTaskTest.java

示例4: 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

示例5: test

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
@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("规则校验通过");
    }

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

示例6: test

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
@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("规则校验通过");
    }

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

示例7: 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

示例8: execute

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
@Override
public Room execute( Context ctx ) {
    KieSession session = ( KieSession ) ctx.getData().get( "session" );
    GameMessageService messageService = ( GameMessageService ) ctx.getData().get( "messageService" );

    QueryResults queryResults = session.getQueryResults( "WhereAmI", getPlayer().getName() );
    Iterator<QueryResultsRow> iterator = queryResults.iterator();
    Room room = null;
    while ( iterator.hasNext() ) {
        room = ( Room ) iterator.next().get( "$r" );
        break;
    }
    if ( room != null ) {
        session.insert( messageService.newGameMessage( getPlayer().getName(), "You are in " + room.getName() ) );
    }
    return room;
}
 
开发者ID:Salaboy,项目名称:drools-game-engine,代码行数:18,代码来源:WhereAmICommand.java

示例9: execute

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
@Override
public Void execute( Context ctx ) {
    KieSession session = ( KieSession ) ctx.getData().get( "session" );
    GameMessageService messageService = ( GameMessageService ) ctx.getData().get( "messageService" );
    FactHandle roomInFH = session.getFactHandle( roomIn );
    roomIn.getPeopleInTheRoom().remove( getPlayer().getName() );
    session.update( roomInFH, roomIn );
    QueryResults queryResults = session.getQueryResults( "getRoomByName", door.getLeadsTo() );
    Iterator<QueryResultsRow> iterator = queryResults.iterator();
    Room roomTo = null;
    while ( iterator.hasNext() ) {
        roomTo = ( Room ) iterator.next().get( "$r" );
        break;
    }
    if ( roomTo != null ) {
        FactHandle roomToFH = session.getFactHandle( roomTo );
        roomTo.getPeopleInTheRoom().add( getPlayer().getName() );
        session.update( roomToFH, roomTo );
        session.insert( messageService.newGameMessage( getPlayer().getName(), "Player moved from  " + roomIn.getName() + " to " + roomTo.getName() ) );
    } else {
        session.insert( messageService.newGameMessage( getPlayer().getName(), "ERROR: Door cannot be used because the room:   " + door.getLeadsTo() + " was not found. " ) );
    }
    return null;
}
 
开发者ID:Salaboy,项目名称:drools-game-engine,代码行数:25,代码来源:UseDoorCommand.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: insertIntoSession

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
private void insertIntoSession(KieSession sessionStatefull, CostCalculationRequest request) {
    sessionStatefull.insert(request);
    if (request.getOrder() != null) {
        sessionStatefull.insert(request.getOrder());
        for (OrderLine orderLine : request.getOrder().getOrderLines()) {
            sessionStatefull.insert(orderLine);
            sessionStatefull.insert(orderLine.getProduct());
        }
    }
    if (request.getTrip() != null) {
        sessionStatefull.insert(request.getTrip());
        for (Step step : request.getTrip().getSteps()) {
            sessionStatefull.insert(step);
            sessionStatefull.insert(step.getStepStart());
            sessionStatefull.insert(step.getStepEnd());
        }
    }
}
 
开发者ID:nheron,项目名称:droolscourse,代码行数:19,代码来源:TestExecercice.java

示例15: writeObject

import org.kie.api.runtime.KieSession; //导入依赖的package包/类
public static byte[] writeObject(Marshaller marshaller, KieSession kieSession) {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(outputStream);) {
        /*
         * It seems that the Marshaller does not persist the actual SessionClock, which is a problem when using the PseudoClock, so we
         * persist the SessionConfiguration, Environment and clock time to be able to execute the pseudo-clock (if it's used).
         */
        KieSessionConfiguration kieSessionConfiguration = kieSession.getSessionConfiguration();
        oos.writeObject(kieSessionConfiguration);

        marshaller.marshall(outputStream, kieSession);

        byte[] bytes = outputStream.toByteArray();

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Size of session is: " + bytes.length);
        }
        return bytes;
    } catch (IOException ioe) {
        String errorMessage = "Unable to marshall KieSession.";
        LOGGER.error(errorMessage, ioe);
        throw new RuntimeException(errorMessage, ioe);
    }
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:25,代码来源:KieSessionByteArraySerializer.java


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