Cache OM Tutorial : Update the Event Preprocessor to Load the Rete Network

Update the Event Preprocessor to Load the Rete Network
After each RTC, the data created in the agent is saved to the cache and removed from the Rete network. Before the next RTC, therefore, you must reload any data needed by any rules that will be triggered in the RTC. This is generally done using the event preprocessor rule function, as it is the presence of event data that triggers most rules.
Learning Points
What is a concept instance’s mode? Concepts can be set (globally or individually) as Memory Only, Cache Only, or Cache + Memory (cache plus memory). These modes refer to how the data is saved. Memory Only mode means the instances are not saved to the cache. See also BusinessEvents Cache Fundamentals to understand more about cache mode.
Loading data from cache into the Rete does not trigger rules  At least not in the way it would if the data was newly arriving in an event. In conjunction with other data, however, the presence of the loaded data can trigger rules, in the usual way.
More Information
In TIBCO BusinessEvents Architect’s Guide see the following:
Task B Update the Event Preprocessor
1.
In TIBCO BusinessEvents Studio, open the RuleFunctions > PreProcessor rule function.
2.
Click the Source tab at the bottom of the editor to work in the Source view. (In the Project Design Tutorial you worked in the Form view. You could stay in that view, but it’s good become familiar with both views).
3.
In the Scope section, replace Event request with Events.AccountOperations request. The section looks like this:

 
   scope {
      Events.AccountOperations request;
   }

 
The reason you have to narrow the scope is that the base Event class does not have an AccountId property, so it can’t be used in the function you’ll add in the next step.
4.

 
   body {
      // Replies to the request event, in order to close the HTTP request.
      // To keep it simple, uses the request event as the response.
      Event.replyEvent(request, request);
 
      // Attempts to load any existing matching account.
      Coherence.C_CacheLoadConceptByExtId(request.AccountId, false);
   }

 
The Coherence.C_CacheLoadConceptByExtId() function loads any matching items from the cache into the Rete network. In this case, it loads any concept whose ExtId matches the AccountId in the incoming event. The loading is done before the event is asserted, so the Rete network will contain any matching Account concepts. The BadCreateAccount rule then fires and as in the Project Design Tutorial, to prevent creation of duplicate accounts.
Summary and Next Steps
You have modified the basic FraudDetection project to load instances from the cache into the Rete network using an event preprocessor. This enables the project code to check for existing instances first, when creating new ones.
Next you will work in the Cluster Deployment Descriptor to create two agents of different types.