本文整理匯總了Java中org.kie.api.runtime.KieSession.fireAllRules方法的典型用法代碼示例。如果您正苦於以下問題:Java KieSession.fireAllRules方法的具體用法?Java KieSession.fireAllRules怎麽用?Java KieSession.fireAllRules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kie.api.runtime.KieSession
的用法示例。
在下文中一共展示了KieSession.fireAllRules方法的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());
}
}
示例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();
}
示例3: 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("規則校驗通過");
}
}
示例4: 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("規則校驗通過");
}
}
示例5: 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;
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: testQuery
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testQuery() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
System.out.println(" ---- Starting testQuery() Test ---");
List<Person> generatePersons = generatePersons(100);
for (Person p : generatePersons) {
kSession.insert(p);
}
kSession.fireAllRules();
QueryResults queryResults = kSession.getQueryResults("all persons older than", 50);
for (QueryResultsRow row : queryResults) {
System.out.println(" >>> Result : " + row.get("$p"));
}
System.out.println(" ---- Finished testQuery() Test ---");
kSession.dispose();
}
示例11: doTestResources
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
private Throwable doTestResources(String xml) {
try {
ClassLoader loader = getClass().getClassLoader();
SwitchYardModel switchyardModel = _puller.pull(xml, loader);
RulesComponentImplementationModel implementationModel = (RulesComponentImplementationModel)switchyardModel.getComposite().getComponents().get(0).getImplementation();
ServiceDomain serviceDomain = new ServiceDomainManager().createDomain();
QName serviceName = new QName("test");
KnowledgeRuntimeManagerFactory runtimeManagerFactory = new KnowledgeRuntimeManagerFactory(loader, serviceDomain, serviceName, implementationModel);
KnowledgeRuntimeManager runtimeManager = runtimeManagerFactory.newRuntimeManager(KnowledgeRuntimeManagerType.SINGLETON);
RuntimeEngine runtimeEngine = runtimeManager.getRuntimeEngine();
KieSession session = runtimeEngine.getKieSession();
session.insert(this);
session.fireAllRules();
runtimeManager.disposeRuntimeEngine(runtimeEngine);
runtimeManager.close();
return null;
} catch (Throwable t) {
return t;
}
}
示例12: doTest
import org.kie.api.runtime.KieSession; //導入方法依賴的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();
}
}
示例13: doTest
import org.kie.api.runtime.KieSession; //導入方法依賴的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();
}
示例14: doTest
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void doTest() throws InterruptedException {
//System.setProperty("kie.maven.settings.custom", value)
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();
}
}
示例15: execute
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
public static void execute( KieContainer kc ) {
// From the container, a session is created based on
// its definition and configuration in the META-INF/kmodule.xml file
KieSession ksession = kc.newKieSession("HelloWorldKS");
// Once the session is created, the application can interact with it
// In this case it is setting a global as defined in the
// org/drools/examples/helloworld/HelloWorld.drl file
ksession.setGlobal( "list",
new ArrayList<Object>() );
// The application can also setup listeners
ksession.addEventListener( new DebugAgendaEventListener() );
ksession.addEventListener( new DebugRuleRuntimeEventListener() );
// To setup a file based audit logger, uncomment the next line
// KieRuntimeLogger logger = ks.getLoggers().newFileLogger( ksession, "./helloworld" );
// To setup a ThreadedFileLogger, so that the audit view reflects events whilst debugging,
// uncomment the next line
// KieRuntimeLogger logger = ks.getLoggers().newThreadedFileLogger( ksession, "./helloworld", 1000 );
// The application can insert facts into the session
final Message message = new Message();
message.setMessage( "Hello World" );
message.setStatus( Message.HELLO );
ksession.insert( message );
// and fire the rules
ksession.fireAllRules();
// Remove comment if using logging
// logger.close();
// and then dispose the session
ksession.dispose();
}