File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Looking for something more lightweight than a rules engine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Looking for something more lightweight than a rules engine" Watch "Looking for something more lightweight than a rules engine" New topic

Looking for something more lightweight than a rules engine

Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Back in a different geological epoch I built a lot of expert systems. I'm a little rusty, but I think I can say that the system I used the most (TIRS), was a "frame-based" kind of system. Maybe not truly frame-based, but at least kind of frame-based. By "frame-based" I mean a system where you could create class-like templates (frames) and then instantiate them. Then, you could write "rules" that could take the general form:

if there exists an instance of frame X and
if there exists an instance of frame Y and
if there exists an instance of frame Z such that
X.a == Y.e and
X.b == Z.m and
Y.f == Z.n

then do stuff...

Sometimes it felt almost like weird, in-memory SQL queries.

Anyway, I have a Java app. where I need to create a lot of rules (maybe 25 to 50 rules?), like the one I showed above. A really horrible way to do it is to create nested loops (foreach X, Y, Z). I've written a few of those "rules" and they kind of make me throw up in my mouth a little

In my case, I think it's okay to hard code the order in which these rules will "fire" (be executed).

So the question is, is there a cleaner, fairly lightweight way to implement rules like this as a part of a larger Java app?

I remember looking at Jess a long time ago and feeling like it was very capable, but also probably not very lightweight from either a performance or "brain investment" perspective. Maybe I'm wrong about that?

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I know nothing about Rules Engines but I did fine a list of rules engines written in Java. Might help you find something "lighter".

GenRocket - Experts at Building Test Data
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Thanks Gregg,

I guess I posted this here because I'm wondering whether there is some sort of OO or patterns approach to this kind of design that I'm not familiar with. I'd really rather not go down any sort of "rules engine" approach if I can help it. These so-called "rules" are going to have to be executed thousands of times during an interaction.
Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
I feel like I'm carrying coals to Newcastle here (or owls to Athens)...

Buschmann et al. discuss the Blackboard Architectural Pattern in Pattern-Oriented Software Architecture � A System of Patterns Volume 1 (POSA1) (pp.75-95) which may be applicable in this case.

However it would be difficult in a case like this to tell where you cross the line towards building your own microworld expert system/rules engine - at which point using a more general pre-existing implementation would make more sense.
M Easter
Ranch Hand

Joined: Feb 11, 2007
Posts: 133
I recently caught a presentation on JESS at a Java conference. At first blush, I would consider a rules engine.

The 2 dominant ones seem to be JESS and Drools. JESS is based on older technology, and uses a Lisp-like syntax for the rules. However, the speaker said that it can execute 80K rules/second, so performance may not be a problem.

On the other hand, here is an entry-level article on Drools:

On the _other_, other hand, I too have wondered about basic OO pattern that might work in simple instances. Imagine a Predicate interface like so:

A CompositePredicate could chain together individual predicates, where each one contains a given "rule". Things get a bit muddy here but I'm thinking of the composite pattern combined with a "filter" pattern. It is hard to tell if this would fit your situation.

M Easter
Software Composer -
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
josql is an interesting api that allows you to query in memory Objects. Not really a rules engine, but powerful... - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
So far so cool!

That joSQL thingy looks pretty interesting. I'm open for more ideas, and I'll keep you all posted.
Naveen K Garg
Ranch Hand

Joined: Nov 28, 2005
Posts: 105
Hi Bert,

I have used JBoss Rules in couple of Java Application. The results are quite good. I would strongly suggest to use this as it also have a small memory footprint.

I agree. Here's the link:
subject: Looking for something more lightweight than a rules engine
It's not a secret anymore!