Red Hat

In Relation To Tihomir Surdilovic

In Relation To Tihomir Surdilovic

jBPM5 - Web-based BPMN2 authoring in Guvnor

Posted by Tihomir Surdilovic    |    Feb 4, 2011    |    Tagged as

We have completed big parts of the integration between Guvnor and the Oryx web-based business process editor. Our primary use cases supported by this integration are:

- Viewing existing jBPM5 processes in Guvnor

- Prototyping new jBPM5 processes in Guvnor.

Please note that we are still working on full round-tripping support between the web-based Oryx editor and our BPMN2 support provided through the eclipse plugin.

Oryx is a web-based editor for modeling business processes hosted at Google Code. Oryx is also backed by Signavio, who provides a professionally maintained version. Within Guvnor we integrate with the BPMN2 process designer provided from the Oryx branch which is maintained by Antoine Toulme. The goal of this branch is to apply upstream patches to the Oryx project and it's latest version can be downloaded from github.

To start learning about web-based BPMN2 authoring in Guvnor click on the video link below:

The integration code is currently in the droolsjbpm project master on github. Next step is to download the designer- from here and deploy it alongside your Guvnor war. No further configuration is necessary. Start up your server and you can start playing with authoring BPMN2 processes in Guvnor.

JUDCon2010 Berlin - Applying Drools in Assistive Technology

Posted by Tihomir Surdilovic    |    Oct 14, 2010    |    Tagged as
Here are the slides for my talk at this years JUDCon in Berlin. I was unfortunately not able to make it there in person, however Skype worked out great. Having to get up at 4am to test the connection was the hardest part ;)

The main topic of the talk was on how to apply Drools in Assistive Technology which is considered a non-typical technology field. It shows some of my past research and work in the area of assistive mouse-cursor control and shows how Drools as a fully fledged integration platform can further enhance the overall needs of current assistive technology devices and systems now and in the future.

If you are interested in Drools and Assistive Technology have a look and let me know what you think.

Be aware of using double-quotes when writing Drools Decision Tables

Posted by Tihomir Surdilovic    |    Nov 21, 2009    |    Tagged as

This is a small thing that I ran into when writing Decision Tables using OpenOffice:

Let's say in a CONDITION column you want to write the following pattern:

section : Section(type == "$param") from company.sectionList

If you type this into the column (without cut/paste) it will look like:

section : Section(type == “$param”) from company.sectionList 

The difference here is the double quotes generated by OpenOffice. If you do not change all of them and try to load your Decision Table with for example:

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();
kbuilder.add(ResourceFactory.newClassPathResource("mydecisiontable.xls"), ResourceType.DTABLE, config);

you will get the following type of exception:

[8,29]: [ERR 101] Line 8:29 no viable alternative at input ''
[8,39]: [ERR 101] Line 8:39 no viable alternative at input ''
[9,29]: [ERR 101] Line 9:29 no viable alternative at input ''
[9,37]: [ERR 101] Line 9:37 no viable alternative at input '' 

...just something small to consider when debugging your Drools Decision Tables. Note that Decision Table support was added to Seam since 2.2.0.CR1

Moving to Seam 3

Posted by Tihomir Surdilovic    |    Oct 12, 2009    |    Tagged as Seam

I am starting to move all Drools5 integration code to the Seam 3 drools module and will update the previous posts with correct links as soon as they are available. There will be no further development against the Seam 2.2.Drools5 branch.

Seam and Drools Fusion example

Posted by Tihomir Surdilovic    |    Sep 24, 2009    |    Tagged as Seam

Drools Fusion is the module responsible for adding event processing capabilities into the Drools5 platform. It defines a set of goals for support of Complex Event Processing:

  • Support Events, with their propper semantics, as first class citizens.
  • Allow detection, correlation, aggregation and composition of events.
  • Support processing of Streams of events.
  • Support temporal constraints in order to model the temporal relationships between events.
  • Support sliding windows of interesting events.
  • Support a session scoped unified clock.
  • Support the required volumes of events for CEP use cases.
  • Support to (re)active rules.
  • Support adapters for event input into the engine (pipeline).

Seam integration with Drools5 aims to provide full integration with Drools5 Fusion as well as provide Seam-specific convenient ways of interacting with the Fusion module.

In order to show an example of this integration, again, we are going to be dealing with the Numberguess example. This Numberguess example is depicted through a game where users have nine tries to guess a random number between 1 and 100. Each guess triggers a pageflow which in turns calls upon Drools to make a decision (win, lose, or keep guessing) until either the correct number is guessed or nine tries are reached upon which the game ends.

For the Fusion example, we are going to change the game a little. Instead of having nine tries to guess the correct number, the users are going to have one minute to make the right guess. So let's get started:

1. The first change to integrate Fusion in our Numberguess example is in the rules themselves. The GameCount rule is the focal point of the changes and needs to be looked at:

rule GameCount
   	  gameStart : GameStart() from entry-point "Guess Stream" 
	  Guess( time after[1m,*] gameStart.time ) from entry-point "Guess Stream" 
      game.setMessage("Game time of 1 minute exceeded.");

The rule predicate pattern matches if the following is true:

a) there exists an event of type GameStart from the Guess Stream entry point (An entry point is for Drools a gate from which facts come, you can read much more about this in the docs)


b) there exists an event of type Guess where the temporal distance between the time of the event is over one minute of the time of the GameStart event (this basically means if the user makes a guess after 1 minute of the initial game start).

If the pattern is matched we set the game decision to lose and provide an appropriate message to the user on why they have lost the game.

2. Now that we have our rule, we are back in our Seam code and need to put it all together. As always first we need to declare our KnowledgeBase in components.xml:

<drools:knowledge-base name="kbase" knowledge-builder-config="" knowledge-base-config="">

Note the attribute knowledge-base-config which points to Drools has two processing modes, namely CLOUD and STREAM. The CLOUD processing mode is the default processing mode and should be familiar to all Drools users. The STEAM processing mode is the mode used when the application needs to process streams of events which is what we need for this example and we tell the engine that we want to use it by defining the property drools.eventProcessingMode in our properties file and setting it to stream.

Once this is done we need to create the StatefulKnowledgeSession:

<drools:stateful-knowledge-session name="ksession" knowledge-base="#{kbase}" knowledge-session-config=""

Note the attribute knowledge-session-config which points to Drools Fusion provides two clock implementations out of the box, namely Real Time Clock and Pseudo Clock. Pseudo clock is used for testing and the real time clock internally uses the system clock which we need for our example. We set this in our properties file by setting the property drools.clockType to realtime.

If you are still reading at this point you remember that in our GameCount rule we say that our events come from the Guess Stream entry point. So now we need to define this entry point into which we are going to feed all of our user guess events into:

<drools:working-memory-entry-point name="guessEntryPoint" 
       ksession="#{ksession}" entry-point-name="Guess Stream"/>    

The WorkingMemoryEntryPoint component is something we added for the Fusion integration with Seam and provides a convenient way to get a hold of a Drools entry point.

Last things to do now is to put it all together in our pageflow definition:

<decision name="drools">
      <handler class="org.jboss.seam.drools.KnowledgeDecisionHandler">

The new thing here is the ability to pass an entry point to KnowledgeDecisionHandler who knows to inserts events into this entry point. Currently I am working on adding support for multiple entry points to KnowledgeDecisionHandler which is useful when you have multiple event streams feeding events into the rule engine at the same time.

And that's it, with these changes users now have one minute to guess the right number...and it uses Drools Fusion :)

Numberguess example using Drools5 Templates

Posted by Tihomir Surdilovic    |    Sep 16, 2009    |    Tagged as

Before I dig into the a Fusion example, I wanted to show current integration with Drools5 Templates. Rule templates are helpful when you have a number of rules which follow some sort of pattern(s). In addition you can use templates when you have reoccurring hard-coded values in your rule patterns or actions. The Seam numberguess example is not the best example for rule templates however is good enough for a simple example.

If we look at base numberguess.drl DRL, we can see some hard-coded values, for example the guessCount is set to 9, the guess increment value is 1 and we also see hard-coded values for win and loose, all of which we want to externalize from our rule resource. This is what our new rule template can look like. If we look at rule Lose we can see some relevant changes:

rule Lose
      Game(guessCount == @{guesscount} )
      if ( decision.getOutcome()==null )

Please follow the Drools documentation on further explanation on the template syntax.

In order to expand our template, we must provide a data source. With Seam this expansion is driven by custom Seam components which implements the TemplateDataProvider interface that defines a single method:

   public Collection<Map<String,Object>> getTemplateData();

For this simple example we implement a template data provider with hard-coded values:

public class NumberGuessTemplateDataProvider implements TemplateDataProvider
   Collection<Map<String, Object>> templateData = new ArrayList<Map<String,Object>>();
   public void init()
      //  We use a Map which provides the values for substituting template parameters.
      // It should have a (String) key set matching all of the parameter names. 
      // Values can be from any class, as long as they provide a good toString() method
      Map<String, Object> m1 = new HashMap<String, Object>();
      m1.put("wintext", "win");  // substitutes the @{wintext} template parameter
      m1.put("losetext", "lose"); // substitutes the @{losetext} template parameter
      m1.put("guesscount", 9); // substitutes the @{guesscount} template parameter
      m1.put("increment", 1); // substitutes the @{increment} template parameter
   // getters and setters

Now all that is left is configuration in components.xml. First we define our KnowledgeBase:

<drools:knowledge-base name="kbase" knowledge-builder-config="" knowledge-base-config="">

Note here that we have only added the name of our template data provider to the rule-resource string...that's it. Last thing to do is to define our StatefulKnowledgeSession as shown in the previous post.

Seam Numberguess example with Drools5 API

Posted by Tihomir Surdilovic    |    Sep 15, 2009    |    Tagged as Seam

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