Questions concerning JBoss-Rules (JBR)

A few disclaimers first:

  • "JBoss" is copyrighted, trademarked and other legally restrictive things...
  • I'm not employed by JBoss and I do not offer certified JBoss consultancy.

What's the difference between insert and assert?

Up to JBR 4.03 the keyword to add facts to workingMemory was assert. It has been renamed to insert in release 4.03.

How do I get facts back from WorkingMemory?

You called workingMemory.fireAllRules(), and now you want your facts (aka: your business objects) back. Quite understandable, but don't worry: You never lost them to working memory. Clever as many JBR features, working memory only keeps references to the facts you asserted or inserted. You can safely continue with your normal stuff and use your objects (facts) as if nothing happened.

But: Rules might have created new facts, which your business code might need to know about. In such cases you can query working memory to return an Iterator or QueryResults of facts. It then remains as a programming exercise to retrieve the ones your interested in... Look at the WorkingMemory API for further info.

Does JBR recognize when my business objects (facts) are modified?

Yes or no, depending on how you added the facts to working memory. In prior versions of JBR or Drools, one had to call a 'modify' method to inform the engine about changes. Nowadays you tell JBR to add a PropertyChangeListener to your facts upon 'insert/assert'.

How to I trace which rules fire?

Add a DebugEventListenerto your RuleBase or your WorkingMemory. Be warned, though. Such listeners might create loads of output. It differs from the normal stacktrace, as the precious line you really need will unlikely be the topmost one...

Add the following line to your code (where session is your workingMemory).

session.addEventListener(new DebugAgendaEventListener());