com.ibm.websphere.brb.strategy
Class DefaultClassifierFindingStrategy

java.lang.Object
  |
  +--com.ibm.websphere.brb.strategy.DefaultClassifierFindingStrategy
All Implemented Interfaces:
FindingStrategy, java.io.Serializable

public class DefaultClassifierFindingStrategy
extends java.lang.Object
implements FindingStrategy, java.io.Serializable

The default FindingStrategy which is used to find classifier rules. No other types of rules are found by this FindingStrategy. Clients wishing to write their own finding strategies can use it as the basis for implementing various kinds of finding strategies. The client programmer should subclass DefaultClassifierFindingStrategy to implement a custom strategy. Normally new behavior should be implemented by overriding one or more of the following methods: parseRuleIdInfo, findRulesInCache, findRulesInDatabase, and addRulesToCache. The default findRules method should usually be adequate. Note that, since the finding 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 FindingStrategy implementation must implement the Serializable interface.

See Also:
Serialized Form

Fields inherited from interface com.ibm.websphere.brb.FindingStrategy
DEFAULT_CLASSIFIER, DEFAULT_NONCLASSIFIER
 
Constructor Summary
DefaultClassifierFindingStrategy()
           
 
Method Summary
 void addRulesToCache(IRule[] rulesToAdd, java.lang.String folderName, java.lang.String ruleName, TriggerPoint tp, java.util.Date asOfDate)
          Add the specified rules to the cache.
 IRule[] findRules(TriggerPoint tp, java.lang.Object ruleIdInfo, java.lang.Object classificationInfo, java.util.Date asOfDate)
          This implementation of the findRules method searches for classifier rules matching the specified criteria.
 IRule[] findRulesInCache(java.lang.String folderName, java.lang.String ruleName, TriggerPoint tp, java.util.Date asOfDate)
          Look in the cache for classifier rules with the specified name in the specified folder that are in effect on the specified date.
 IRule[] findRulesInDatabase(java.lang.String folderName, java.lang.String ruleName, TriggerPoint tp, java.util.Date date)
          Look in the database for classifier rules with the specified name in the specified folder that are in effect on the specified date.
 java.lang.String[] parseRuleIdInfo(java.lang.Object ruleIdInfo, java.lang.String baseFolderName)
          Uses the rule ID information object passed into the finding strategy to determine the fully-qualified names of the rules to be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultClassifierFindingStrategy

public DefaultClassifierFindingStrategy()
Method Detail

addRulesToCache

public void addRulesToCache(IRule[] rulesToAdd,
                            java.lang.String folderName,
                            java.lang.String ruleName,
                            TriggerPoint tp,
                            java.util.Date asOfDate)
                     throws BusinessRuleBeansException

Add the specified rules to the cache. The rules will be associated with the specified folder name, rule name, and asOfDate. This implementation simply calls a helper method to add the rules to the BRBeans-supplied cache. Users may add to or otherwise change this behavior by overriding this method. If this method is overridden, the findRulesInCache method may also need to be overridden.

Parameters:
rulesToAdd - Array of rules to add to cache.
folderName - The rules will be associated with this folder name in the cache.
ruleName - The rules will be associated with this rule name in the cache.
tp - The TriggerPoint used to make this call.
asOfDate - The rules will be associated with this asOfDate in the cache. If null, then the current date and time is used.
Throws:
BusinessRuleBeansException - If any errors occur.

findRules

public IRule[] findRules(TriggerPoint tp,
                         java.lang.Object ruleIdInfo,
                         java.lang.Object classificationInfo,
                         java.util.Date asOfDate)
                  throws BusinessRuleBeansException
This implementation of the findRules method searches for classifier rules matching the specified criteria. Only classifier rules are found. This method controls the overall flow of events for the finding strategy. The events consist of the following steps:
  1. Parse the rule ID information object to produce a list of rule names to search for (parseRuleIdInfo method).
  2. If caching is enabled, try to find the rules in the cache (findRulesInCache method).
  3. If rules are not found in cache, try to find the rules in the database (findRulesInDatabase method).
  4. If caching is enabled, add whatever rules were found to the cache (addRulesToCache method).
An array of found rules is built up and returned after all rule names have been processed. Any unexpected errors will result in a BusinessRuleBeansException being thrown.

When implementing a custom finding strategy, if this method is overridden, care should be taken that the new implementation fulfills the method's contract. Normally the overall sequence of events defined in this implementation should be adequate and clients should override one or more of the methods listed above in the four steps to implement a custom finding strategy.

Specified by:
findRules in interface FindingStrategy
Following copied from interface: com.ibm.websphere.brb.FindingStrategy
Parameters:
tp - the trigger point which is used to make this call
ruleIdInfo - an object that can be used to identify the rules to be found; normally a fully-qualified name or an array of fully-qualified names
classificationInfo - an object that can be used to determine the classification of the rules to be found, or null for unclassified rules
asOfDate - rules returned should be in effect as of this date; null means use the current date and time
Returns:
An array of Rules which match the search criteria. If no rules are found, an array of length zero will be returned.
Throws:
BusinessRuleBeansException - if any exceptions occur

findRulesInCache

public IRule[] findRulesInCache(java.lang.String folderName,
                                java.lang.String ruleName,
                                TriggerPoint tp,
                                java.util.Date asOfDate)
                         throws BusinessRuleBeansException

Look in the cache for classifier rules with the specified name in the specified folder that are in effect on the specified date. The rules must also be marked as ready. The specified asOfDate may be null which means to look for rules that are in effect at the current date and time.

Note that there are two "no rules found in cache" conditions that must be distinguished:

This implementation simply calls a helper method to find rules in the BRBeans-supplied cache. Users may add to or otherwise change this behavior by overriding this method. If this method is overridden, the addRulesToCache method may also need to be overridden.

Parameters:
folderName - Search for rules in this folder.
ruleName - Search for rules with this name.
tp - The TriggerPoint used to make this call.
asOfDate - Rules found should be in effect on this date. If null, rules in effect at the current date and time should be found.
Returns:
An array containg all rules in the cache matching the search criteria. If an entry is in the cache indicating that there are no rules matching the search criteria, then a zero-length array is returned. If there is no entry in the cache for the search criteria, then null is returned.
Throws:
BusinessRuleBeansException - If any errors occur.

findRulesInDatabase

public IRule[] findRulesInDatabase(java.lang.String folderName,
                                   java.lang.String ruleName,
                                   TriggerPoint tp,
                                   java.util.Date date)
                            throws BusinessRuleBeansException

Look in the database for classifier rules with the specified name in the specified folder that are in effect on the specified date. The rule must also be marked as ready.

This implementation simply calls a helper method to find rules in the database. Users may add to or otherwise change this behavior by overriding this method.

Parameters:
folderName - Search for rules in this folder.
ruleName - Search for rules with this name.
tp - The TriggerPoint used to make this call.
date - Search for rules that are effective on this date.
Returns:
An array containg all rules in the database matching the search criteria. If no rules are found matching the search criteria, then a zero-length array is returned.
Throws:
BusinessRuleBeansException - If any errors occur.

parseRuleIdInfo

public java.lang.String[] parseRuleIdInfo(java.lang.Object ruleIdInfo,
                                          java.lang.String baseFolderName)
                                   throws BusinessRuleBeansException

Uses the rule ID information object passed into the finding strategy to determine the fully-qualified names of the rules to be found. The ruleIdInfo parameter can be any object that can be used to determine the rule names. It is exactly the rule ID information object passed on the TriggerPoint call. For the BRBeans-supplied finding strategies, this is required to be either a single String (find rules with this fully-qualified name) or a String[] or an Object[] containing Strings (find rules that have any of the fully-qualified names in the array). Any other types will result in a BusinessRuleBeansException being thrown. Users can override this method in their own finding strategies to take any type of parameter, as long as it can be used to produce an array of fully-qualified rule names.

Parameters:
ruleIdInfo - Object containing information to be used to produce an array of fully-qualified rule names. BRBeans-supplied finding strategies require that this is either a String, a String[], or an Object[] containing Strings.
baseFolderName - The base folder name that rule names should be relative to. If null, then rule names must be fully-qualified.
Returns:
An array of fully-qualified names of rules to be found.
Throws:
BusinessRuleBeansException - If any errors occur.