Content spot exits
Content spot exits provide the ability to alter the default flow of processing of content spots, making it possible in the runtime environment to override the rule to process, the current user, and the results of rule processing.
Instances of the same exit class are instantiated for all content spots. The exit class interface name is public interface RuleExit.
The content spot exit class can provide the following actions:
- Access request and session information
- Set information in the personalization context, including changing the user
- Get the campaign name
- Get the rule name to be executed for campaign
- Override and specify the rule to be executed
- Bypass rule processing; no rule is processed.
After rule processing, the content spot exit class can provide the following actions:
- Add result items
- Remove result items
- Completely replace result items
RuleExit methods:
-
void aboutToExecuteRule(RuleTrigger contentSpot, RequestContext requestContext)
Get the results of the rule execution.
-
Object[] getFilteredResults(RuleTrigger contentSpot, RequestContext requestContext, Object[] originalResults)
Exit to allow for changing the results of the rule execution. originalResults: the original result array is supplied to the exit. filteredResults: the exit should return the original array if no changes are needed
RuleTrigger methods:
-
String getCampaignName()
Get the campaign name for the content spot.
-
String getRuleName()
Get the name of the rule to be executed in this spot. Can return null if the name is not yet established.
-
void setRuleName(String ruleName)
Set the name of the rule to be executed in this spot. If the name is set to null, no rule will be executed.
-
void setRuleExit(RuleExit ruleExit instance)
Set the rule exit for this particular content spot instance.
The RuleTrigger
also supports a static method that contains an instance of RuleExit
that is set up at initialization time. You can implement setRuleExit(RuleExit)
on a per-content spot basis to override only the content spots that you specify.
The class name of the default RuleExit
implementor is read from the PersonalizationService.properties file.
Example Usage Scenario
-
Specify a
RuleExit
class in PersonalizationService.properties, as shown:rulesEngine.defaultRuleExit=com.ibm.websphere.personalization.RuleExitSample ...
-
At startup time, the Personalization run-time environment creates an instance of that class (
aRuleExit
in this scenario) and caches it in a privateRuleTrigger
static method - As each content spot is triggered, the Personalization rule engine determines the rule name to be used
aRuleExit.aboutToExecuteRule()
is invoked, passing the spot and the request context-
aRuleExit
has several options:- Access request context information (includes HTTP request and session)
- Get the campaign and rule names
- Specify a request user ID
- Change the rule name to be executed
- Bypass the rule by setting the rule name to null
-
The rule is executed
aRuleExit.getFilteredResults()
is invoked; the rule exit modifies results as required, then returns the updated set- The updated results are stored