Chapter 3 Cache Object Management Tutorial : Check for Existence of Accounts Before Creating

Check for Existence of Accounts Before Creating
In the basic Fraud Detection project (see Chapter 2, Project Design Tutorial), one or optionally two Account instances are created on startup using startup rule functions.
Startup rule functions execute on all active agents as they start up, unless you use application logic to perform a check before taking action.
Three instances of the agent will now be deployed in three engines, so you must ensure that the Account instance or instances are created only once (otherwise runtime exceptions will occur).
To do so, you will modify the InitializeAccounts rule to use a try catch block. The block will prevent concepts from being created if they already exist.
Learning Points
Caching and Engine Concurrency (multi-engine)  The design of your project must take multi-engine features and cache object management into account.
How entities are shared between agents  In a multi-engine configuration:
Event instances are clustered between agents—they are not shared. That is, each event instance is present on only one agent in a group.
Scorecards are not shared between agents. Each inference agent maintains its own set of scorecards and the values in each agent can differ.
Avoiding concurrent changes  As needed by the project, take care when making changes that affect the ontology instances to prevent another agent in the group from making concurrent changes. Read Designing With Multiple Active Inference Agents in TIBCO BusinessEvents User’s Guide for more details.
Task F Add Checks in the InitializeAccounts Rule
1.
With the FDCache project open in TIBCO Designer, open the InitializeAccounts rule function.
2.
   //Create Account concept instance ActA
Add the following line:

 
   try {

 
3.
System.debugOut("############### Created account ActA ################");
Add the following lines:

 
} catch (Exception e1) {
// No action - the account is just not created if it exists.
}

 
4.

 
try {
//Create Account concept instance ActB using XSLT Mapper
Instance.createInstance("/Concepts/Account");
System.debugOut(
    "############### Created account ActB ################");
} catch (Exception e2) {
// No action - the account is just not created if it exists.
}

 
Note that you cannot copy the line beginning Instance.createInstance from the above code sample into the rule editor. If you have not created the account ActB, you can skip this step. If you want to add a second concept now, see Optional Exercise: Create a Concept Instance Using a Standard Function for instructions on adding a concept instance using the Instance.createInstance() function.
5.
Click Apply.
6.
Click the FDCache resource and select the Configuration tab.
7.
In the File Location field, Specify a location and name for the EAR file. The tutorial uses C:\temp\FDCache.ear.
8.
Click Apply. Click Save. Click Build Archive.
You should see the message "Enterprise Archive File has built correctly." If you do not, validate your project to identify and correct any errors and try again.