Taking inspiration from the Pizza language, could we layer a rule language and features ontop of an existing language - instead of by it's side:
http://pizzacompiler.sourceforge.net
While this could be done for any JVM language, Java9 will be the focus here. Annotations, and CDI, are an essential part of making this work declaratively.
http://java.dzone.com/articles/cdi-di-p1
RuleModule is a Class that has rule members and can be instantiated and fire rules.
@RuleModule // name is inferred from java class
@RuleModule("Short name")
Injectable member fields would replace "globals" and would be injected by CDI, which would allow for creation and injectino of complex object graphs.
@RuleModule
public class SomeClassName {
@Inject // Injected by CDI
void SomeService service;
int counter;
void someMethod() {
counter++; // just demonstrating these are methods with member var access, not pure functions
}
@LongName("Long description names go here, rule names now must be valid java names, obeying same conventions nested classes" )
rule RuleName when {
$a : Alarm()
} then {
service.call( $a );
sometMethod();
}
}
KieBase is the new name for KnowledgeBase. We can allow declarative assocation of RuleModules in a number of potential ways.
@RuleModules( {MyModule1.class, MyModule2.class, MyModule3.class } )
@KieBase
public abstract class MyKieBaseClass implements KieBase {
}
The above would create a KieBase that consisted of 3 KieModules. It's abstract, because the code generation will add in the rest of KieBase implementation.
Comments