"end"; final KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbConf.setOption(EqualityBehaviorOption.EQUALITY); final KieSession ksession = kbase.newKieSession(); ksession.setGlobal("list", list); ksession.fireAllRules(); assertTrue(list.contains("OK")); ksession.dispose();
@Test public void testSequentialConfiguration() { // setting the option using the type safe method config.setOption( SequentialOption.YES ); // checking the type safe getOption() method assertEquals( SequentialOption.YES, config.getOption( SequentialOption.class ) ); // checking the string based getProperty() method assertEquals( "true", config.getProperty( SequentialOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( SequentialOption.PROPERTY_NAME, "false" ); // checking the type safe getOption() method assertEquals( SequentialOption.NO, config.getOption( SequentialOption.class ) ); // checking the string based getProperty() method assertEquals( "false", config.getProperty( SequentialOption.PROPERTY_NAME ) ); }
config.getProperty( "drools.ruleBaseUpdateHandler" ) ); config.setProperty( "drools.ruleBaseUpdateHandler", "somethingElse" ); config.getProperty( "drools.ruleBaseUpdateHandler" ) ); config.setProperty( "drools.ruleBaseUpdateHandler", null ); config.getProperty( "drools.ruleBaseUpdateHandler" ) ); config.setProperty( "drools.ruleBaseUpdateHandler", "" ); config.getProperty( "drools.ruleBaseUpdateHandler" ) );
"end\n"; KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM ); KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); ksconf.setOption( ClockTypeOption.get( "pseudo" ) ); ksconf.setOption( TimerJobFactoryOption.get("trackable") ); KieSession ksession = kBase.newKieSession( ksconf, null ); ksession.setGlobal( "list", list ); EntryPoint aep = ksession.getEntryPoint( "a-ep" ); aep.insert( new A() ); PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock(); timeService.advanceTime( 3, TimeUnit.SECONDS );
"end"; final KieBaseConfiguration kbconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconfig.setOption(EventProcessingOption.STREAM); final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption(ClockTypeOption.get("REALTIME")); final KieSession ksession = kbase.newKieSession(conf, null); ksession.setGlobal("list", list); ksession.fireAllRules(); () -> { for (int j = 0; j < FACTS_PER_POLL; j++) { ksession.insert(new MyFact());
private int processStocks(int stockCount, AgendaEventListener agendaEventListener, String drlContentString) throws Exception { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption(EventProcessingOption.STREAM); KieBase kbase = loadKnowledgeBaseFromString(kconf, drlContentString); KieSessionConfiguration ksessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); ksessionConfig.setOption(ClockTypeOption.get("pseudo")); ksessionConfig.setProperty("keep.reference", "true"); final KieSession ksession = kbase.newKieSession(ksessionConfig, null); ksession.addEventListener(agendaEventListener); PseudoClockScheduler clock = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock(); 100 * stIndex, 100 * stIndex); ksession.insert(st); Thread.sleep( 100 );
config.setOption( EventProcessingOption.STREAM ); ksconf.setOption( ClockTypeOption.get( "pseudo" ) ); ksconf.setOption( TimerJobFactoryOption.get("trackable") ); KieSession ksession = kBase.newStatefulKnowledgeSession( ksconf, null ); ksession.setGlobal( "list", list ); EntryPoint aep = ksession.getEntryPoint( "a-ep" ); aep.insert( new A() ); PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock> getSessionClock(); timeService.advanceTime( 3, TimeUnit.SECONDS );
"end\n"; KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM ); KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); ksconf.setOption( ClockTypeOption.get( "pseudo" ) ); ksconf.setOption( TimerJobFactoryOption.get("trackable") ); KieSession ksession = kBase.newKieSession( ksconf, null ); ksession.insert( new A() ); ksession.insert( new B() ); ksession.fireAllRules(); assertEquals( 2, ksession.getObjects().size() );
@Test public void testIdentityWithResize() { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( EqualityBehaviorOption.IDENTITY ); KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kconf); KieSession ksession = kbase.newKieSession(); for ( int i = 0; i < length; i++) { String s = getPropertyName(i); FactHandle handle = ksession.insert( s ); objects.add( s ); handles.add( handle ); String s = objects.get(i); FactHandle handle = handles.get( i ); assertEquals( s, ksession.getObject( handle ) ); assertSame( handle, ksession.getFactHandle( s ) );
"end\n"; KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( EventProcessingOption.STREAM ); KieSession ksession = kbase.newKieSession(); ksession.addEventListener( new DefaultAgendaEventListener() { public void matchCreated( MatchCreatedEvent event ) { i.incrementAndGet(); ksession.insert( new SimpleEvent() ); ksession.fireAllRules();
final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconf.setOption(EventProcessingOption.STREAM); final KieBase kbase = loadKnowledgeBaseFromString(kbconf, str); final KieSession ksession = kbase.newKieSession(); final EntryPoint ep = ksession.getEntryPoint("X"); final List list = new ArrayList(); ksession.setGlobal("list", list); ecs.submit(() -> { try { ksession.fireUntilHalt(); return true; } catch (final Exception e) {
"\n"; final KieBaseConfiguration kbconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconfig.setOption(EventProcessingOption.STREAM); final KieSession session = kbase.newKieSession(); final EntryPoint ep01 = session.getEntryPoint("ep01"); session.insert(hiwaesdk); final long LIMIT = 20; session.halt(); session.dispose();
config.setOption( EventProcessingOption.STREAM ); ksconf.setOption( ClockTypeOption.get( "pseudo" ) ); ksconf.setOption( TimerJobFactoryOption.get("trackable") ); KieSession ksession = kBase.newStatefulKnowledgeSession( ksconf, null ); ksession.insert( new A() ); ksession.insert( new B() ); ksession.fireAllRules(); assertEquals( 2, ksession.getObjects().size() );
public static void main(String[] args) throws InterruptedException { KieServices kieServices = KieServices.Factory.get(); KieBaseConfiguration config = kieServices.newKieBaseConfiguration(); config.setOption(EventProcessingOption.STREAM); KieContainer container = kieServices.getKieClasspathContainer(); // KieBase kieBase = container.getKieBase("test-cep"); KieBase kieBase = container.newKieBase("test-cep",config); KieSession kieSession = kieBase.newKieSession(); Person p1 = new Person(1,"Tom"); Person p2 = new Person(2,"Lucy"); kieSession.insert(p1); Thread.sleep(3000); kieSession.insert(p2); int count = kieSession.fireAllRules(); System.out.println("Fire " + count + " rules!"); } }
@Before public void setUp() throws Exception { baseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); // use stream mode to enable proper event processing (see Drools Fusion 5.5.0 Doc "Event Processing Modes") baseConfig.setOption( EventProcessingOption.STREAM ); kbase = KnowledgeBaseFactory.newKnowledgeBase(baseConfig); // config sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); // use a pseudo clock, which starts at 0 and can be advanced manually sessionConfig.setOption( ClockTypeOption.get("pseudo") ); // create and return session session = kbase.newKieSession(sessionConfig, null); clock = session.getSessionClock(); }
@Test public void testMarshallWithNot() throws Exception { String str = "import " + getClass().getCanonicalName() + ".*\n" + "rule one\n" + "when\n" + " A()\n" + " not(B())\n" + "then\n" + "System.out.println(\"a\");\n" + "end\n" + "\n" + "rule two\n" + "when\n" + " A()\n" + "then\n" + "System.out.println(\"b\");\n" + "end\n"; KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM ); KieBase kBase = loadKnowledgeBaseFromString(config, str); KieSession ksession = kBase.newKieSession(); ksession.insert( new A() ); MarshallerFactory.newMarshaller( kBase ).marshall( new ByteArrayOutputStream(), ksession ); }
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( DeclarativeAgendaOption.ENABLED ); session.fireAllRules(); for ( Object o : session.getObjects() ) { System.out.println( ">>> " + o );
final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconf.setOption(EventProcessingOption.STREAM); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbconf ); ks.insert( entityOne ); ks.insert( entityTwo ); ksession2 = marshaller.unmarshall(bais, ks.getSessionConfiguration(), ks.getEnvironment()); Collection items = ksession2.getFactHandles(); Assert.assertTrue( items.size() == 2 );
@Test public void testGetFactHandleEqualityBehavior() throws Exception { final KieBaseConfiguration kbc = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbc.setOption(EqualityBehaviorOption.EQUALITY); final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(kbc)); final KieSession ksession = createKnowledgeSession(kbase); final CheeseEqual cheese = new CheeseEqual("stilton", 10); ksession.insert(cheese); final FactHandle fh = ksession.getFactHandle(new CheeseEqual("stilton", 10)); assertNotNull(fh); }
final KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconf.setOption(EventProcessingOption.STREAM); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbconf ); ks.insert( entityOne ); ks.insert( entityTwo );