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:

1) components.xml

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="" knowledge-base-config="">


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=""

The pageflow definition stays the same:


2) pageflow.jpdl.xml

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

Back to top