Archive for November, 2005

JBoss shuts down unexpectedly

So JBoss has a habit of shutting down unexpectedly (but gracefully), which is a problem we haven’t faced with any other servers.

Many people on the JBoss forums report the same problem, but there aren’t any answers.

After a little investigation, it turns out the solution is to start your JVM with the -Xrs option, which will “reduce use of OS signals by Java/VM”.

Passing parameters in a Drools DSL

Another quote from an email I posted to the Drools user list I’m afraid. Will expand on my Drools DSL experiences when time allows.

> To give an example of what I need, in the rules mentioned below, what do
> I need to do to pass one/multiple parameter(s) to the method “killCell”
> and how should I define that in the xml and xsd.

You need to change the xsd to allow the killCell element to have text children elements. I’ve no idea if you’re familiar with XML Schema, but I usually point people to www.w3schools.com as that has some reasonable introductions into how to do this. If you don’t care how this works, then you can just replace the following line:

<xs:element name=”killCell”/>

with:

<xs:element name=”killCell” type=”xs:string” />

That should do it for the xsd — you’ll now be able to place text in your killCell element. Alternatively you could change your xsd to accept an attribute instead.

Having altered the xsd, the next step is to alter the Consequence, which for the conway example is org.drools.examples.conway.rules.dsl.KillCellConsequence. You’ll probably need to feed in a Declaration (a reference for accessing an object that has been asserted against the working memory), in which case the ConwayConsequenceFactory (in the same package) also needs to be altered, to pass the Declaration of your parameter into the Consequence (in the constructor could be easiest).

Then to act on the parameter, the invoke method (which is called every time the consequence is activated) should be changed. Using the Declaration set in construction, the actual object can be retrieved from the Tuple passed into the invoke method. What you do from this point is up to you.

I haven’t gone into too much detail about the Factory and the Consequence objects, because playing around with the Conway example will show you much more than words in an email could show you. Better just to point you to the right places and let you investigate from there.

Drools DSL

I plan on writing some more structured details on implementing a DSL with Drools when I get a chance, but for the moment, this is an email I sent to the Drools user list in response to a query about how Drools DSL works:

A ConditionFactory and ConsequenceFactory are used to create Condition
and Consequence objects. These objects have access to the
Configuration object, which is in concept an XML wrapper. So the XML
you see inside the tag is essentially the
configuration for the action.

Your custom Consquence object can inspect the Configuration (i.e. the
content of the action elements) and perform any arbitrary process on
it. In the house example, there is code that interprets that XML, and
programmatically sets the heating to be off in the room object
representing the lounge. How you do this is up to you, but the
natural implementation would be a Map of Room objects with a Heating
property. The Consequence does the programmatic work to translate the
XML to the object model.

Condition objects operate in the same way.

So the DSL is not necessarily the text of the elements but encompasses
the whole XML structure. There needn’t be any element text at all if
you wish, the elements and their attributes themselves could provide
everything you need to perform rule processing.

Obviously then, there is a certain amount of work in implementing a
DSL. And creating a DSL is not very well documented (I might add some
of my experiences now that I’ve actually created a non-trivial DSL).
But the benefit once the Condition, Consequence, and Factory objects
have been coded is that a relatively complex process can be translated
to rules using a rule structure of your choosing.

Drools seems to be getting more and more interest every day. I’m just new to it myself, but its easy to see how its extremely useful in the right scenario. Right now, it appears theres a lot of people trying to figure out if their uses for rules engines are valid.