[Enterprise Extensions only]

Writing your own strategies

The process of triggering a rule or set of rules is controlled by a set of strategy objects. Four strategies are used each time a rule is triggered:

  1. Finding strategy: The finding strategy accesses the persistent datastore to find the set of rules matching the search criteria passed on the trigger call. The search criteria are based on the rule ID information passed on the trigger call. The set of rules found is passed to the filtering strategy.

  2. Filtering strategy: The filtering strategy can change the set of rules that were found by the finding strategy. The set of rules returned is the set that will actually be fired by the firing strategy.

  3. Firing strategy: The firing strategy fires the rules found by the finding strategy, possibly modified by the filtering strategy. It gathers up the results of the individual rules and these results are passed to the combining strategy.

  4. Combining strategy: The combining strategy takes the results from firing the rules and combines them in some fashion to produce the final result of the trigger.

TriggerPoint object has its own set of strategies that can be changed independent of any other TriggerPoint object. There is a set of default strategies that are used by the TriggerPoint if none are explicitly set.

For each of the four strategies you are allowed to set different strategies for classifier rules and for non-classifier rules. The strategies set for classifier rules are to be used when the BRBeans framework is triggering a classifier rule. The strategies for non-classifier rules are used in all other cases.

It is also possible to set three different sets of filtering strategies:

  1. one to be used if no rules are found
  2. one to be used if exactly one rule is found
  3. one to be used if more than one rule is found
This capability can be used to set up filtering strategies that will throw exceptions if the expected number of rules is not found.

Strategy classes must implement one of the strategy interfaces provided by BRBeans in the com.ibm.websphere.brb package:

  1. FindingStrategy
  2. FilteringStrategy
  3. FiringStrategy
  4. CombiningStrategy

The user is also allowed to write his or her own strategy implementations to perform special functions not performed by the predefined implementations. This should be done with care since part of the functionality of the BRBeans framework is actually being replaced when you write a custom strategy. One simple example of writing a custom strategy is creating a new firing strategy that logs every rule that is fired.

The basic requirement for a strategy implementation is that it implements the appropriate strategy interface.

The filtering and combining strategies are particularly simple. For these, a class should be created that implements either FilteringStrategy or CombiningStrategy and implements either the filterRules method (for FilteringStrategy) or the combineResults method (for CombiningStrategy) to perform the required functions. At runtime, an instance of the new class should be created and passed to the TriggerPoint object using the appropriate set method so that the new strategy is used when rules are triggered using that TriggerPoint.

The finding and firing strategies are somewhat more complicated to customize since they provide more function than the simple filtering and combining strategies. Default finding and firing strategy implementations are provided that define a general outline of the steps necessary to perform the function. We recommend subclassing these when customizing your own strategies, and then overriding the desired methods on the default implementation to provide the new behavior.

Refer to either the BRBeans Javadoc or the source code for the default implementations in com.ibm.websphere.brb.strategyfor more details.