BadCreateAccount and CreateAccount Rules
In this task you create two rules, one called CreateAccount and one called BadCreateAccount.
Both rules can fire when a CreateAccount event is asserted into the Rete network. However, the BadCreateAccount rule has a higher priority, so it will fire before the CreateAccount rule.
The BadCreateAccount rule checks whether the account ID provided in the CreateAccount event matches the account ID of any Account instance already in the Rete network. One of the two following situations must occur:
- A matching ID exists in the Rete network: the BadCreateAccount rule prints a message to the console, and "consumes" — that is, deletes — the CreateAccount event. Because that event is consumed, the CreateAccount rule cannot fire.
- No matching ID exists in the Rete network: the BadCreateAccount rule does nothing, and then the CreateAccount rule fires, and creates the Account concept instance.
Learning Points
- What are rules and how are they created?
- Rules define actions to take when certain conditions are met. Rules are written in the TIBCO BusinessEvents rule language, which is similar to the Java language. Rules are declarative and are generally narrow in scope. A rule has three parts: the declaration (declare), the conditions (when), and the actions (then). As with rule functions, you can work in a source view, which displays the Java-like code, or in a form view.
- How are rules used at runtime?
- The rule engine checks all changes and additions to the Rete network and evaluates or reevaluates rules, using their declaration and conditions, as needed. Eligible rules are added to the rule agenda.
- What is the rule agenda
- A rule fires when it is at the top of the agenda. The engine determines the order of firing using rule declarations and conditions, and each rule’s priority and rank (if these features are used). As the contents of the Rete network change, the engine reevaluates rules and removes any that are no longer eligible to fire. See Understanding Conflict Resolution and Run to Completion Cycles in TIBCO BusinessEvents Architect’s Guide for details.
- How can you prioritize rule execution?
- The Priority setting is used by the runtime engine when determining the order in which rules are fired. Those with a number closer to one fire first. Within a set of rules that has the same priority, a ranking feature enables you to determine which fire before others. It uses a callback rule function that enables you to specify business logic to establish the rank. When there is no reason to force rules to execute in a particular order, leave the Priority and Rank fields set to the default and let the runtime engine determine rule order.
- How can you create concept instances?
- In this task you instantiate an object instance using its ontology function. Another way is using the Instance.CreateInstance() function. This function uses the XSLT mapper to map any of the scope variables (such as properties, attributes and event payloads) to the new instance properties. You can also create event instances in a similar way, using the Event.CreateEvent() function.
More Information
- See all references provided for Adding the InitializeScorecard Rule Function.
- Read about Runtime Inferencing Behavior in TIBCO BusinessEvents Architect’s Guide.
Copyright © Cloud Software Group, Inc. All rights reserved.