![]() |
|
BRBeans runtime behaviour can best be described by giving a simple example of a trigger point selecting, executing, and then responding to the results of a business rule.
The first step in triggering a rule is for the trigger point framework
to invoke a query method on the rule server to find the rules to be triggered.
The main item used for the query is the fully-qualified rule name. Other
items used in the query include start and end date, whether or not this is
a classifier, the classification of the rule, and whether or not the Rule
is
marked "ready". This query will return zero or more Rules. If there is at
least one Rule
, the trigger point will assemble the data that
will be sent as parameters to each Rule
. The trigger point will
then loop through the list of Rule
invoking the fire method on
each and passing the parameters. The results will be combined depending on
the combining strategy being used.
When the trigger point framework invokes fire on a Rule
, it
instantiates the RuleImplementor
and uses it to do the actual
work (to execute the rule algorithm or test). Once it has arrived at a result,
the RuleImplementor
returns that result. For constraint rules
(ones that arrive at a boolean true/false answer) the returned value is, by
convention, a ConstraintReturn. A ConstraintReturn is a data structure indicating
whether or not the constraint was satisfied, and if not, what went wrong.
For derivation rules (ones that calculate a single, generally non-boolean
value) the return value may be of any type. In the simplest case, the return
value from each RuleImplementor
is returned back to the trigger
point where it is analyzed to determine what action to take.
Here is an example of what happens when a rule is triggered:
A Rule
exists named maxTruckGrossWeight
. The
puspose of this rule is to check that the weight entered by a user for a particular
truck does not exceed the maximum allowed value. This Rule
contains
an initialization parameter list consisting of a single value of 42000 (meaning
a maximum gross weight of 42,000 lbs.). This Rule
is bound to
a RuleImplementor
class called MaxRuleImpl
. MaxRuleImpl
,
when invoked, tests the parameter it is passed against the initialization
list value and returns a ConstraintReturn
. The ConstraintReturn
will
be set to true if the passed parameter is less than or equal to the initialization
value. Otherwise, a ConstraintReturn
is set to false and some
information is added describing which values were compared and why the test
failed.
Here is what actually happens when this rule is triggered:
Rule
objects. In this case this sequence contains one Rule
, maxTruckGrossWeight
.Rule
object
and calls the fire method on the copy. If remote, the framework calls fire
on the EJB reference. The parameter list containing te enter weight is passed
on the fire method.maxTruckGrossWeight
rule (either the copy of the EJB
itself) creates an instance of the rule implementor class, maxRuleImpl
,
if it does not already have one. When a new rule implementor instance is
created, the rule calls its init method passing any initialization parameters
defined for the rule. In this case the initialization parameter list contains
the single value 42000. If the rule already has a rule implementor instance,
it will use that one and will not call the init method again.maxTruckGrossWeight
rule calls the fire method on the
rule implementor instance. The firing parameters passed on the trigger point
are passed to the rule implementor, possibly modified by any firing parameters
defined in the rule itself. In this case the firing parametering are passed
directly from the trigger point. maxRuleImpl
returns a ConstraintReturn
object
to the Rule
indicating the result of its comparison. This ConstraintReturn
is
returned to the trigger point framework and ultimately to the application.ConstraintReturn
and
takes appropriate action.Related concepts... | |
Parent: BRBeans framework runtime | |
Externalized business rules | |
Runtime exception handling | |
View PDF file... | |
To view a PDF file containing this article and related articles, click: | |
![]() | |
![]() |
![]() |