com.ibm.websphere.brb
Interface FilteringStrategy

All Known Implementing Classes:
AcceptAnyFilteringStrategy, AcceptFirstFilteringStrategy, AcceptLastFilteringStrategy, AcceptOneFilteringStrategy

public interface FilteringStrategy

The job of the FilteringStrategy is to take the list of rules which were found by the FindingStrategy and to filter out those rules which should not be fired. There are three sets of filtering strategies used in TriggerPoint:

  1. strategy for zero rules found
  2. strategy for one rule found
  3. strategy for multiple rules found
A different strategy can be used for each of these scenarios, along with different strategies for classifier and non-classifier rules. The zero rules strategy is invoked if no rules are found by the finding strategy, the one rule strategy is invoked if exactly one rule is found, and the multiple rules strategy is invoked if more than one rule is found. Multiple filtering strategies may be set using the following TriggerPoint methods: setMultipleRulesFilteringStrategy(), setNoRulesFilteringStrategy(), and setOneRuleFilteringStrategy(). To specify one of the predefined filtering strategies, use the static constants on this interface.

As an example, here is one common way to use filtering strategies. Suppose you want to ensure that exactly one rule is found on a TriggerPoint call. You would set all three strategies (zero rules, one rule, and multiple rules) for this TriggerPoint to FilteringStrategy.ACCEPT_ONE. This strategy throws an exception if the number of rules is not one.

Clients may implement their own filtering strategies to filter rules using a custom algorithm. This may be done by creating a class that implements the FilteringStrategy interface and providing an implementation for the filterRules method. Note that, since the filtering strategy is stored as part of the TriggerPoint and the TriggerPoint may be passed on a remote method call to the rule when it is fired, any FilteringStrategy implementation must implement the Serializable interface.


Field Summary
static FilteringStrategy ACCEPT_ANY
          Accepts any number of rules which are found and returns them unmodified.
static FilteringStrategy ACCEPT_FIRST
          Returns only the first rule which is given; if zero rules are given, throws a NoRulesFoundException.
static FilteringStrategy ACCEPT_LAST
          Returns only the last rule which is given; if zero rules are given, throws a NoRulesFoundException.
static FilteringStrategy ACCEPT_ONE
          Ensures that there is exactly one rule which is found.
 
Method Summary
 IRule[] filterRules(TriggerPoint tp, IRule[] rules)
          Filter out the rules which should not be fired and returns an array containing only rules that should be fired.
 

Field Detail

ACCEPT_ANY

public static final FilteringStrategy ACCEPT_ANY
Accepts any number of rules which are found and returns them unmodified.


ACCEPT_FIRST

public static final FilteringStrategy ACCEPT_FIRST
Returns only the first rule which is given; if zero rules are given, throws a NoRulesFoundException.


ACCEPT_LAST

public static final FilteringStrategy ACCEPT_LAST
Returns only the last rule which is given; if zero rules are given, throws a NoRulesFoundException.


ACCEPT_ONE

public static final FilteringStrategy ACCEPT_ONE
Ensures that there is exactly one rule which is found. If zero rules are given, throws a NoRulesFoundException; if multiple rules are found, throws a MultipleRulesFoundException.

Method Detail

filterRules

public IRule[] filterRules(TriggerPoint tp,
                           IRule[] rules)
                    throws BusinessRuleBeansException
Filter out the rules which should not be fired and returns an array containing only rules that should be fired. The rules passed in will never be null; if zero rules were found, an empty array will be passed. Exceptions may be thrown if an unexpected number of rules were found.

Parameters:
tp - the trigger point which is used to make this call
rules - a list of rules, possibly empty, which this method can modify and return; will not be null
Returns:
An array of Rules which should be fired. If there are no rules to be fired, an array of length zero will be returned.
Throws:
BusinessRuleBeansException - if any exceptions occur