本文整理匯總了Java中org.kie.api.runtime.KieSession.setGlobal方法的典型用法代碼示例。如果您正苦於以下問題:Java KieSession.setGlobal方法的具體用法?Java KieSession.setGlobal怎麽用?Java KieSession.setGlobal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kie.api.runtime.KieSession
的用法示例。
在下文中一共展示了KieSession.setGlobal方法的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: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: testServiceCallInRHS
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testServiceCallInRHS() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
kSession.setGlobal("myDataProviderService", new MyDataProviderServiceImpl());
System.out.println(" ---- Starting testServiceCallInRHS() Test ---");
University university = new University("My Uni");
FactHandle univFactHandle = kSession.insert(university);
Assert.assertEquals(50, kSession.fireAllRules());
university.setName("My Uni (updated)");
kSession.update(univFactHandle, university);
Assert.assertEquals(50, kSession.fireAllRules());
System.out.println(" ---- Finished testServiceCallInRHS() Test ---");
kSession.dispose();
}
示例8: testUsingGlobalToTrackRulesFiring
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testUsingGlobalToTrackRulesFiring() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
List<String> rulesFired = new ArrayList<String>();
kSession.setGlobal("rulesFired", rulesFired);
System.out.println(" ---- Starting testUsingGlobalToTrackRulesFiring() Test ---");
Room room = new Room("living room", 10);
kSession.insert(room);
Person person = new Person("salaboy", 32, "[email protected]", "London", Gender.MALE);
kSession.insert(person);
Assert.assertEquals(1, kSession.fireAllRules());
Assert.assertTrue(rulesFired.contains("room and a person"));
System.out.println(" ---- Finished testUsingGlobalToTrackRulesFiring() Test ---");
kSession.dispose();
}
示例9: 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();
}
示例10: 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<Observation> observations = generateObservations(20);
for (Observation o : observations) {
kSession.insert(o);
}
Assert.assertEquals(20, kSession.fireAllRules());
System.out.println(" ---- Finished testSlowServiceInAGlobal() Test ---");
kSession.dispose();
}
示例11: 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();
}
示例12: testUsingGlobalToTrackRulesFiring
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void testUsingGlobalToTrackRulesFiring() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
List<String> rulesFired = new ArrayList<>();
kSession.setGlobal("rulesFired", rulesFired);
System.out.println(" ---- Starting testUsingGlobalToTrackRulesFiring() Test ---");
Patient patient = (Patient) new Patient()
.setId("Patient/1");
Condition condition = createDiabetesCondition(patient, "Condition/1");
kSession.insert(patient);
kSession.insert(condition);
Assert.assertEquals(1, kSession.fireAllRules());
Assert.assertTrue(rulesFired.contains("Identify Diabetic Patients"));
System.out.println(" ---- Finished testUsingGlobalToTrackRulesFiring() Test ---");
kSession.dispose();
}
示例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 ---");
Patient patient = (Patient) new Patient()
.setId("Patient/1");
Condition condition = createAsthmaCondition(patient, "Condition/1");
kSession.insert(patient);
kSession.insert(condition);
Assert.assertEquals(1, kSession.fireAllRules());
System.out.println(" ---- Finished testServiceInAGlobal() Test ---");
kSession.dispose();
}
示例14: 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();
}
示例15: correctHouseTest
import org.kie.api.runtime.KieSession; //導入方法依賴的package包/類
@Test
public void correctHouseTest() {
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" );
Key key = new Key( "Door A" );
roomA.getItems().add( key );
Door doorA = new Door( "Door A" );
kSession.insert( doorA );
roomA.getDoors().add( doorA );
kSession.insert( roomA );
house.getRooms().add( roomA );
kSession.insert( house );
// I need to insert all the items from the room
// This will be performed by rules on the game
for(Item i : roomA.getItems()){
kSession.insert( key );
}
int fired = kSession.fireAllRules();
assertEquals( 0, fired );
assertEquals( 0, errors.size() );
kSession.dispose();
}