A Closer Look at the Java Rules Engine API (JSR 94)
by Benoy Jose
Introduction
The most frustrating part of a project is change and the sad
reality is that change is inevitable. I cannot think of any
project that was built the way it was originally designed
without any changes made to the original. The problem of change
becomes more evident in complex projects involving a lot of
business logic, which keeps changing based on external
circumstances. Sometimes the business rules have changed
even before the project goes into production causing untold, mass
rework to accommodate the changes. A good example is the
insurance industry, new laws or market economics force changes,
which cannot be foreseen and planned for during design. The
solution for a dynamic environment like the above is to have a
rules engine. Rule engines allow the business users to change
rules without affecting the overall running of an application.
The rules are defined separately from the application, and the
logic to deal with the rules is built in during design. The rule
engine takes care of applying the rules and the associated
actions on the rules.
Now that we realize that there could be a need to have a rules
engine to cater to changing business needs the problem is to
choose one. Just like application servers and other softwares
there are numerous rule engines in the market (Jrules, Ilog,
JESS to name a few). Some of the factors that might have
deterred companies from implementing a rules engine could be cost,
lack of standards and compatibility with the existing
frameworks. Most of these rule engines are proprietary and have
their own proprietary APIs, which makes them less flexible to
integrate with external applications. So a decision to abandon a
particular product and pick another one would mean rewriting
most if not all of the application code including application
logic and API calls. Also, the cost of some of these
rule engines could be cost-prohibitive. Another aspect worth noting
is the lack of standards in the rule engine industry. JSR 94 is
an attempt to standardize rule engine implementations for the
Java language. The specification defines guidelines to provide a
common API for use in rule engines. The JSR only provides
guidelines for the rule administration APIs and rule runtime
APIs. It does not define any guidelines for how the rules and
actions need to be defined and what language will be used to
define the rules. It does not provide technical guidelines on
how the rule engine would read and evaluate rules. The
specification leaves all the above questions to the discretion
of the vendor implementing the rules engine.
Architecture
The architecture of the Rules Engine Specification is divided
into two main sections, the Runtime client API and the rules
administration API. Rules. The administrator API has classes to
load rules and their associated actions as execution sets. It also
maintains them. Rules can be loaded from external resources like
URIs, Input streams, XML streams and readers. The administrator
API provides for registering and de-registering execution sets
and doing other maintenance functions on execution sets. The
Administrative API is defined in the javax.rules.admin package
of the Rules Engine API. Defining the rules using the admin
package helps to control the access and running of rules by
clients. The admin package can help to define the permissions on
execution sets so that unauthorized users would be denied access
to some controlled rules.
The Runtime API provides classes and methods to rule engine
clients so that they can run the rules and get results. The
rules registered using the rules admin API are the only rules
accessible to the runtime clients. The Runtime API helps runtime
users to acquire rule sessions and execute rules within the
session. The methods and classes of the Runtime API are defined
in the javax.rules package.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|