Add a comment


Re: A really simple but powerful rule engine

OK, there is already support for such composite rules. Create SubRule instances and refer to them in the main Rules. SubRules have no "outcome" and so will never be returned by the engine. There is a test which you can look at: https://github.com/maxant/rules/blob/master/rules/src/test/java/ch/maxant/rules/blackbox/AbstractEngineTest.java.

See these two tests: testSubrules() and testSubrulesWithActions().

Both those tests contain a composite rule which is selected only when subrule number 1 returns true and subrule number 2 returns false.

As for externalising the rules - you do not need to redeploy or even restart the application! You only need to write a few lines of code which creates new engines. Any services/components which use your engines should then throw away their references to old engines and start using new engines. If you are using Spring, write a @Configuration which creates @Beans: http://stackoverflow.com/questions/24014919/understanding-spring-configuration-class-usage. If you are using Java EE CDI the best would be to create a method which produces rule engine instances - see http://stackoverflow.com/questions/16534728/please-explain-the-produces-annotation-in-cdi. If you are using plain Java, then create a rule engine factory (http://howtodoinjava.com/2012/10/23/implementing-factory-design-pattern-in-java/).

Each time the rules change (or for example every two hours), the configuration/producer/factory should start instantiating rule engines based on the freshly read rules.

Does that help more?

Re: A really simple but powerful rule engine

HTML : b, strong, i, em, blockquote, br, p, pre, a href="", ul, ol, li, sub, sup
E-mail address
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).