The Seam Drools5 Branch contains additions to Seam for interactions with the Drools5 API. Here I will show how the existing numberguess example was changed to use Drools5:
We first define the org.drools.KnowledgeBase and add a single rule resource of type DRL (.drl). This new style of adding resources allows us to add any type of rule resources to the KnowledgeBase (which was not previously possible) and also follows the Drools5 API style (kbuilder.add(ResourceFactory.newClassPathResource("numberguess.drl"), ResourceType.DRL);)
<drools:knowledge-base name="kbase" knowledge-builder-config="kbuilderconfig.properties" knowledge-base-config="kbaseconfig.properties"> <drools:rule-resources> <value>classpath;numberguess.drl;DRL</value> </drools:rule-resources> <drools:event-listeners> <value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</value> </drools:event-listeners> </drools:knowledge-base>
We then create the org.drools.runtime.StatefulKnowledgeSession passing in the reference to our kbase
:
<drools:stateful-knowledge-session name="ksession" knowledge-base="#{kbase}" knowledge-session-config="ksessionconfig.properties" audit-log="/home/tsurdilo/Desktop/ksession"> <drools:event-listeners> <value>org.drools.event.rule.DebugAgendaEventListener</value> <value>org.drools.event.rule.DebugWorkingMemoryEventListener</value> </drools:event-listeners> </drools:stateful-knowledge-session>
The pageflow definition stays the same:
<bpm:jbpm> <bpm:pageflow-definitions> <value>pageflow.jpdl.xml</value> </bpm:pageflow-definitions> </bpm:jbpm>
We have to change the handler here to a handler which knows how to work with org.drools.runtime.StatefulKnowledgeSession:
<handler class="org.jboss.seam.drools.KnowledgeDecisionHandler">
And that's it, the numberguess example works as before. It is important to mention one more change made:
the Drools5 API no longer exposes the setGlobalResolver method on org.drools.runtime.StatefulKnowledgeSession and org.drools.runtime.StatelessKnowledgeSession. This is mainly so that other APIs would not abuse this. Instead we now have to add a delegate, for example:
ksession = knowledgeBase.getValue().newStatefulKnowledgeSession(ksessionconfig, null); ksession.getGlobals().setDelegate(new SeamDelegate());
Next I will show an example using Drools Fusion