Rules and Rule Functions : Overview of Rules and Rule Functions

Overview of Rules and Rule Functions
This chapter explains how to work with the rule editor to create rules and rule functions. It also explains some specific uses for rule functions.
To learn how rules are executed at runtime and for other background information see TIBCO BusinessEvents Architect’s Guide, especially the section Understanding Conflict Resolution and Run to Completion Cycles.
See Also
Chapter 4, Rules and Functions in TIBCO BusinessEvents Architect’s Guide
Chapter 24, Diagrams for information on using rule dependency and sequence diagrams.
Form-based and Source Rule Editors
When you work with rules and rule functions, you can choose how to work:
You can switch between editors and changes made in one editor are reflected in the other one. You can’t switch from the source editor to the form editor if there are validation errors in the code.
Rule Components
A BusinessEvents rule has three components:
Declaration — Use the declaration to declare which concepts and events the rule will depend on, and the names by which instances of these entities can be referred to in the conditions and actions. Aliases must be valid identifiers. Declaring multiple terms of the same type allows the rule to consider multiple instances of the corresponding Entity.
Conditions — Each statement in the condition must evaluate to a boolean value. All of these statements must be true for the rule’s action to be executed. Assignments and calls to certain functions are disallowed in the condition.
Actions — List of statements that will be executed, when the rule is fired, for each combination of terms that matches all the conditions.
Using Events in Rules
This section explains aspects of using events in rules.
Explicitly Assert Events Created in Rules
At runtime, event instances that are created using rules are not automatically asserted. You must explicitly assert such events, for example using the Event.assertEvent() function.
Events that are created from incoming messages, on the other hand, are automatically asserted.
Specifying Default and Non-Default Destinations
BusinessEvents includes two functions that allow you to send simple events out to another application: Event.sendEvent() and Event.routeTo().
Event.sendEvent() automatically sends the event to its default destination.
Event.routeTo takes a destination as an argument, ignoring the event’s default destination.
With routeTo you can direct an event to a destination on a different channel from the event’s default destination. You can also override the properties of the destination, for example, the subject.
You cannot, however, override the properties of the channel itself, for example, the network field in a Rendezvous channel.
Scheduling Events
You can schedule events to be sent at a certain time.
First you create a scheduler using the function Cluster.createScheduler(); then you use the function Cluster.scheduleEvent to schedule an event to be sent at a certain time:
void createScheduler(String schedulerName, long pollInterval, long refreshAhead)
void scheduleEvent(String schedulerName, String workKey, SimpleEvent et, long scheduledTime)
For example:
Cluster.createScheduler("AccScheduler",10000,10000);
Cluster.scheduleEvent("AccScheduler", myworkKey, Events/MyEvent, 50000
The work key is the name of the scheduled task (event), used to identify it later, for exampl to cancel it. You also specify a time in milliseconds. It is the number of milliseconds after the function is called that the event will be sent.
Effect of Cache Only Cache Mode
When using Cache Only cache mode for one or more entities, you must consider how to handle the cache-only entities when you write rules and preprocessor rule functions. See Working With Cache Modes and Loading Cache-Only Objects into the Rete Network in TIBCO BusinessEvents Architect’s Guide.