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 :)

29. Nov 2012, 04:05 CET | Link

Any chance you can post CEP example with Maven project that works to illustrate the concepts?

24. Jun 2014, 15:18 CET | Link

If you are looking at the availability of the medical malpractice insurance policies, you might well appreciate that there are several different types with each of these varying in the type of coverage provided to the medical professional.

24. Jun 2014, 15:20 CET | Link

Accumulating cans is extremely often a period consuming job if you don't have assist. Fortunately there are numerous aluminum containers recycling company ideas that will help you make the procedure much easier. You ought to make a summary of the various community occasions that might be able to supply a person with bare aluminum containers.

24. Jun 2014, 22:38 CET | Link

They will buy or sell on the forex trading demo without giving much thought to why they are putting the trade on. How most people start out trading is to open a free forex practice account at a broker most forex brokers these days have a demo account available. Then the aspiring trader starts to play around on the practice account treating trading as a game.

30. Jul 2014, 08:57 CET | Link

Replica osservare gli acquisti sono per l'aumento per diversi motivi. orologi Replica originali iniziano a essere sempre più alto prezzo, così coloro che dopo avrebbe offerto un Rolex ora non può. Inoltre, replica orologi sono ora molto più sensibile e molto come le loro controparti reali, in modo gli acquirenti non realmente sentono gli orologi sono puramente imitazione.

30. Aug 2014, 03:54 CET | Link

Best friend successive good years, Gucci Shoes Factory, winter spent in Sanya, Monster Beats Outlet, so winter home, seems to be nowhere in sight, North Jackets Outlet, both a little rusty, Nike Air Max Shoes, but also very cordial, Burberry Outlet Online, forward to tonight, feather-like snow, MCM Bags Outlet, drifts underground, Coach Black Friday, looking at that the floc, Louis Vuitton Outlet, fly like snow Ling, Michael Kors Outlet Online, eloquent, Polo Outlet Online, flying in the sky, Cheap Canada Goose, limp walk downs, strange things, Marc Jacobs Outlet Online, I float thinking lianpian, North Outlet Online, poetic heart wenqing, not help surging surging, Coach Factory Outlet, so I borrowed the winter, Ralph Lauren UK, snows research ink, Longchamp Sacs Sortie, into the mind of inactivity, Michael Kors Outlet, the white snow everywhere, Monster Beats By Dre, wrapped in some different, Ralph Lauren Outlet, kind of scenery, Oakley Sunglaases Outlet, wherever the wind in the faces, of the people, Michael Kors Bags Outlet, who are very Huddled, could not help.

01. Sep 2014, 21:28 CET | Link

I think there are quite a lot of viewers who really pressure cleaning palm beach like to show them this. Everyone was very happy with the many other singers involved

08. Sep 2014, 07:36 CET | Link

If you have a hard time getting your eyeliner to stay put, you can apply eyeshadow after you put on eyeliner. You should lightly put your shadow over your eyeliner with a cotton ball. This will seal the application of eyeliner and it will last longer and not run. penis advantage program

08. Sep 2014, 11:00 CET | Link

When you are using products for your hair make sure that you apply them directly to the hair and not on the scalp. This is important because adding hair products to your scalp can clog the pores of your head, which could lead to hair damage and/or loss of hair. revitol hair removal cream

08. Sep 2014, 11:36 CET | Link

Arnold Schwarzenegger was an icon in the field of body building. His buff, tanned body is the ideal of many around the world, but that doesn't mean that an Adonis figure is easy to achieve! Read on to find simple hints and ideas which will help you to get the body you desire. somanabolic muscle maximizer

18. Sep 2014, 13:02 CET | Link

An individual's choice of college, major and educational path can have an extremely significant impact on future earning prospect and overall career satisfaction. Therefore, it is important to gain a thorough understanding of the entire world of higher education and what it has to offer. The information that follows below provides the fundamentals necessary to get tao of badass pdf started.

11. Oct 2014, 14:46 CET | Link

Nice google.

24. Oct 2014, 09:34 CET | Link

Thank you very much for posting and sharing this great article. It is so interesting for me boneka full body

16. Dec 2014, 23:39 CET | Link

Awesome post! Personally I like your site. . I am so impressed to read your content. I am looking forward for the next valuable and informative concept in your blog. Overall outstanding post. Carry on.

creditos rapidos online