Help

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

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

4 comments:
 
15. Sep 2009, 04:45 CET | Link
Gilson

Hi Tihomir,

you're doing an amazing job and we are looking forward to use these new features in our project, that's why I ask you just a few questions:

  • When will this branch be merged into the main trunk?
  • What is the target version of these modifications?
  • Is its release already scheduled?

10Q

Gilson

ReplyQuote
 
15. Sep 2009, 05:10 CET | Link

Hello Gilson, thank you for your interest in the new features!

To answer your questions:

1) The current Drools5 branch will be merged to trunk for Seam3 soon. 2) We will do a beta release after we complete further testing of all new features added. 3) We should have this beta release during the autumn..that is the best guess I can give you now.

Thanks.

 
16. Sep 2009, 00:30 CET | Link
Flavio Costa | flavio.cdc(AT)gmail.com

Why isn't this branch going to be merged in Seam 2.2.x? AFAIK Seam 3 is still far from being released and it's a complete different codebase (based on CDI).

 
16. Sep 2009, 04:51 CET | Link

Hello Flavio,

these are new features and as such will only be included in something like Seam3, not Seam 2.2.1. We do not plan to have a Seam 2.3 release.

Thanks.

Post Comment