本文整理汇总了Java中org.kie.api.KieBase.newKieSession方法的典型用法代码示例。如果您正苦于以下问题:Java KieBase.newKieSession方法的具体用法?Java KieBase.newKieSession怎么用?Java KieBase.newKieSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kie.api.KieBase
的用法示例。
在下文中一共展示了KieBase.newKieSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: helloDroolsTest
import org.kie.api.KieBase; //导入方法依赖的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();
}
示例2: setup
import org.kie.api.KieBase; //导入方法依赖的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);
}
示例3: newShoppingCart
import org.kie.api.KieBase; //导入方法依赖的package包/类
@Override
public String newShoppingCart() throws BusinessException {
String cartId = UUID.randomUUID().toString();
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
KieBase kBase = kContainer.newKieBase(conf);
KieSession kSession = kBase.newKieSession();
kSession.registerChannel("outboundChannel", new Channel() {
@Override
public void send(Object o) {
System.out.println(o);
}
});
shoppingCarts.put(cartId, kSession);
return cartId;
}
示例4: testCallService
import org.kie.api.KieBase; //导入方法依赖的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());
}
示例5: runFaultBoundaryProcess
import org.kie.api.KieBase; //导入方法依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_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);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例6: testCallService
import org.kie.api.KieBase; //导入方法依赖的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());
}
示例7: runFaultBoundaryProcess
import org.kie.api.KieBase; //导入方法依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_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);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例8: testSelect
import org.kie.api.KieBase; //导入方法依赖的package包/类
@Test
public void testSelect() throws Exception {
KieHelper kieHelper = new KieHelper();
kieHelper.addResource(new ClassPathResource(PROCESS_DEFINITION, getClass()), ResourceType.BPMN2);
KieBase kbase = kieHelper.build();
KieSession kieSession = kbase.newKieSession();
kieSession.getWorkItemManager().registerWorkItemHandler("CamelSql", handler);
String sqlQuery = "select * from TEST";
Map<String, Object> params = new HashMap<String, Object>();
params.put("Query", sqlQuery);
params.put("DataSource", "myDs");
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kieSession.startProcess("camelSqlProcess", params);
List<Map<String, Object>> result = (List<Map<String, Object>>)wpi.getVariable("QueryResult");
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
int id = (Integer)result.get(0).get("ID");
String name = (String)result.get(0).get("NAME");
Assert.assertEquals(1, id);
Assert.assertEquals("test", name);
}
示例9: determinePersonsAge
import org.kie.api.KieBase; //导入方法依赖的package包/类
private static Person determinePersonsAge(Person person, KieBase kieBase) {
//KieSession is an interface to the drools engine
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(person);
kieSession.fireAllRules();
kieSession.dispose();
return person;
}
示例10: updateConditions
import org.kie.api.KieBase; //导入方法依赖的package包/类
public void updateConditions(String expiration, Collection<FullTrigger> activeTriggers) {
expression = new Expression(expiration, activeTriggers);
log.debugf("Rules: \n %s", expression);
stop();
KieBaseConfiguration kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieBaseConfiguration.setOption( EventProcessingOption.STREAM );
KieBase kieBase = new KieHelper().addContent(expression.getDrl(), ResourceType.DRL).build(kieBaseConfiguration);
KieSessionConfiguration kieSessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
kieSessionConf.setOption( ClockTypeOption.get( "realtime" ) );
kieSession = kieBase.newKieSession(kieSessionConf, null);
results = new ArrayList<>();
kieSession.setGlobal("results", this);
kieSession.setGlobal("log", log);
if (log.isDebugEnabled()) {
kieSession.addEventListener(new CepAgendaEventListener());
kieSession.addEventListener(new CepRuleRuntimeEventListener());
}
log.debugf("Clock time [%s] ", kieSession.getSessionClock().getCurrentTime());
kieSession.getKieBase().getKiePackages().stream().forEach(p -> log.debugf("Rules: %s", p.getRules()));
executor.submit(() -> {
log.info("Starting fireUntilHalt()");
kieSession.fireUntilHalt();
log.info("Stopping fireUntilHalt()");
});
}
示例11: determineSLA
import org.kie.api.KieBase; //导入方法依赖的package包/类
private static SLACriteria determineSLA(SLACriteria slCri, KieBase kieBase) {
//KieSession is an interface to the drools engine
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(slCri);
kieSession.fireAllRules();
kieSession.dispose();
return slCri;
}
示例12: readMasterCatalogDT
import org.kie.api.KieBase; //导入方法依赖的package包/类
public SLACriteria readMasterCatalogDT(SLACriteria slaCriteria){
KieBase kieBase = dtableManager.getKieBase();
KieSession session = kieBase.newKieSession();
session.insert(slaCriteria);
session.fireAllRules();
System.out.println("Values Read From Decision Table:"+slaCriteria.getPercentage() + slaCriteria.getTime());
return slaCriteria;
}
示例13: approvePerson
import org.kie.api.KieBase; //导入方法依赖的package包/类
@Test
public void approvePerson() {
System.out.println("APPROVE PERSON TEST");
KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
KieBase kb = kc.getKieBase("workingmemorypersistencetest");
KieSession ksession = kb.newKieSession();
ksession.insert(new Person(20, "John"));
ksession.insert(new Person(15, "Marc"));
ksession.insert(new Person(30, "Mary"));
ksession.insert(new Person(12, "Brad"));
ksession.insert(new Person(17, "Deb"));
ksession.fireAllRules();
ksession.dispose();
}
示例14: runFaultResultProcess
import org.kie.api.KieBase; //导入方法依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_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);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultResult");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}
示例15: runFaultEventProcess
import org.kie.api.KieBase; //导入方法依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_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);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}