org.kie.api.event.rule.DebugRuleRuntimeEventListener Java Examples
The following examples show how to use
org.kie.api.event.rule.DebugRuleRuntimeEventListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicEvalTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testDynamicAdd() { String test = "\nrule id3" + "\nwhen" + "\neval(0 < 1)" + // this eval works "\nthen" + "\ninsertLogical( \"done\" );" + "\nend"; loadPackages( ResourceFactory.newByteArrayResource( test.getBytes() ), ResourceType.DRL ); ((KnowledgeBaseImpl)session.getKieBase()).addPackages(kbuilder.getKnowledgePackages()); session.addEventListener( new DebugRuleRuntimeEventListener( ) ); int fired = session.fireAllRules(); // 1 System.out.println(fired); effects = session.getObjects(); assertTrue(effects.contains("done"), "fired"); // so the above works, let's try it again String test2 = "\nrule id4" + "\nwhen" + "\neval(0 == 0 )" + // this eval doesn't "\nthen" + "\ninsertLogical( \"done2\" );" + "\nend"; loadPackages(ResourceFactory.newByteArrayResource(test2.getBytes()), ResourceType.DRL); ((KnowledgeBaseImpl)session.getKieBase()).addPackages(kbuilder.getKnowledgePackages()); fired = session.fireAllRules(); // 0 System.out.println(fired); effects = session.getObjects(); assertTrue(effects.contains("done2"), "fired"); // fails }
Example #2
Source File: HelloWorldExample.java From drools-examples with Apache License 2.0 | 5 votes |
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(); }
Example #3
Source File: HelloWorldExample.java From tools-journey with Apache License 2.0 | 5 votes |
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<>()); // 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(); }
Example #4
Source File: SimpleRuleActivator.java From servicemix with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext context) throws Exception { KieServices ks = KieServices.Factory.get(); KieContainer kcont = ks.newKieClasspathContainer(getClass() .getClassLoader()); KieBase kbase = kcont.getKieBase("SimpleRuleKBase"); logger.info("KieSession newKieSession."); ksession = kbase.newKieSession(); ksession.addEventListener(new DebugAgendaEventListener()); ksession.addEventListener(new DebugRuleRuntimeEventListener()); Customer customer = customerPoor(); logger.info("KieSession fireAllRules. {}", customer); FactHandle fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); customer = customerNormal(); logger.info("KieSession fireAllRules. {}", customer); fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); customer = customerVip(); logger.info("KieSession fireAllRules. {}", customer); fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); }
Example #5
Source File: SimpleTest.java From servicemix with Apache License 2.0 | 5 votes |
/** * beforeClass. */ @BeforeClass public static void beforeClass() { KieServices ks = KieServices.Factory.get(); KieContainer kcont = ks.newKieClasspathContainer(); KieBase kbase = kcont.getKieBase("SimpleRuleKBase"); ksession = kbase.newKieSession(); ksession.addEventListener(new DebugAgendaEventListener()); ksession.addEventListener(new DebugRuleRuntimeEventListener()); }
Example #6
Source File: DynamicEvalTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testDynamicAdd2() { String test = "rule id3\n" + "when\n" + "eval(0 == 0)\n" + "String( this == \"go\" )\n" + // this eval works "then\n" + "insertLogical( \"done\" );\n" + "end\n" + "rule id5\n" + "when\n" + "eval(0 == 0)\n" + "Integer( this == 7 )\n" + // this eval works "then\n" + "insertLogical( \"done3\" );\n" + "end\n"; loadPackages( ResourceFactory.newByteArrayResource( test.getBytes() ), ResourceType.DRL ); ((KnowledgeBaseImpl)session.getKieBase()).addPackages(kbuilder.getKnowledgePackages()); session.addEventListener( new DebugRuleRuntimeEventListener( ) ); session.insert( "go" ); session.insert( 5 ); session.insert( 7 ); int fired = session.fireAllRules(); // 1 System.out.println(fired); effects = session.getObjects(); assertTrue(effects.contains("done"), "fired"); // so the above works, let's try it again String test2 = "\nrule id4" + "\nwhen" + "\neval(0 == 0 )" + // this eval doesn't "\nInteger( this == 5 )" + "\nthen" + "\ninsertLogical( \"done2\" );" + "\nend"; loadPackages(ResourceFactory.newByteArrayResource(test2.getBytes()), ResourceType.DRL); ((KnowledgeBaseImpl)session.getKieBase()).addPackages(kbuilder.getKnowledgePackages()); fired = session.fireAllRules(); // 0 System.out.println(fired); effects = session.getObjects(); assertTrue(effects.contains("done2"), "fired"); // fails for ( Object o : session.getObjects() ) { System.out.println( o ); } }
Example #7
Source File: TransactionEventServiceImpl.java From drools-workshop with Apache License 2.0 | 4 votes |
@PostConstruct public void after() { kSession.registerChannel("auditing", this); kSession.addEventListener(new DebugAgendaEventListener(System.out)); kSession.addEventListener(new DebugRuleRuntimeEventListener(System.out)); }