Chapter 9 Working With Rules and Functions : Understanding and Working With Functions

Understanding and Working With Functions
The functions registry includes various catalogs of functions provided with the product, and each catalog organizes functions into various related categories. You can use functions in rule conditions and actions and in rule function bodies.
You can also create custom functions. Custom functions appear in a custom function catalog. For information about custom functions, see TIBCO BusinessEvents Language Reference.
All catalogs appear in tabs on the right side of the rule editor.
Function Catalogs
This section lists the main categories in each functions catalog (but not sub-categories). See TIBCO BusinessEvents Functions Reference for full details.
Standard Functions
The standard function catalog include the following categories:
BusinessWorks functions are used in ActiveMatrix BusinessWorks integration projects. See Chapter 12, In-Process ActiveMatrix BusinessWorks Integration
Channel functions return information about destinations, and can resume and suspend a destination.
Cluster functions help with multi-engine functionality
Coherence functions are for use with Cache object management.
Date functions allow you to compare two DateTime values using only the date portion of the value.
DateTime functions allow you to perform these date/time related tasks and more: add units of time to a dateTime, compare, retrieve, and format dates and times.
Engine functions allow you to retrieve information about the engine, for example, available memory or the number of rules fired.
Event functions allow you to assert, create, and send simple events and perform other event-related tasks, for example, return the default destination URI of a simple event.
The Exception function enables you to create an exception.
File functions provide various useful functions used when working with files.
Instance functions allow you to create and delete concept instances and perform other instance-related tasks, for example, return an instance given an internal ID.
Math functions allow you to perform advanced mathematical operations.
Number functions allow you to perform type conversions from and to numbers and return the maximum and minimum values for a numeric type.
String functions allow you to perform comparisons, searches, conversions, and other operations with strings.
System functions allow you to send messages to a debug log, retrieve global variables, retrieve system properties, and write data to a file.
IO functions allow the writing and closing of specific files.
Temporal functions allow you to examine and perform calculations on values stored in a property’s history. For information about using temporal functions, see Temporal Functions.
VRF functions (that is, Virtual Rule Function functions) allow you to work with decision tables imported from Decision Manager. See VRF Functions for details.
XPath functions allow you to evaluate XPath expressions.
RDBMS Functions
Database functions are provided for working with database concepts. See Chapter 7, Working With Database Concepts for more on database concepts.
CEP Query Functions
Query functions are used with the query language for querying data in the cache. See TIBCO BusinessEvents Language Reference for details.
RMS Functions
RMS (Rules Management Server) functions are not visible by default. They are used only to customize the default behavior of the rules management server.
To make this function catalog visible to TIBCO Designer, ensure that cep-rms.jar is in your classpath. This JAR file is located in BE_HOME/rms/lib.
See TIBCO BusinessEvents Decision Manager for more details.
Ontology Functions
Ontology functions are generated by BusinessEvents based on the concepts, events, and rules in your project. There are three types of ontology functions:
Constructors — Allow you to create a simple event or concept instance.
Time events — Allow you to create and schedule a time event. See Chapter 4, Working With Time Events.
Rule functions — Allow you to invoke a rule function. See Working With Rules and Functions.
The Ontology Functions area uses the same folder structure as the project (or rather, a subset of that structure). The example below shows the constructor functions on the right and the corresponding concept, event, rule function on the left.
Tool Tips
When you float the curser over a function in the registry, BusinessEvents displays the description and syntax in a tool tip next to the curser:
 
You can create your own tool tips for custom functions. See the TIBCO BusinessEvents Language Reference for detailed information.
Decorations Indicating Where Functions can be Called
Functions are decorated with small letters that indicate where you can call the function.
Action-Only Functions
These functions are only for use in actions. Some of these functions have side effects, for example they can change values. Other functions are limited to actions for other reasons. These action-only functions are identified by a small a at the bottom right of the f. For example: .
Mapper Functions
Functions that bring up the XSLT mapper and XPath builder are identified by a small m at the upper left of the f, for example: . Some functions are both action functions and mapper functions; they are identified with both the m and the a, for example: . See Using XSLT Mapper Functions.
Functions That Can Be Used in Decision Manager
Functions that can be used in Decision Manager are marked with a green b, for example. The b stands for BUI or business user interface, which is what Decision Manager provides for BusinessEvents.
Functions That Can Be Used in Queries
Functions that can be used in queries are marked with a blue q. Such functions are often also available for use in the BUI and so are also marked with a b, , for example. You can call such functions in a query string. See TIBCO BusinessEvents Language Reference for details on use of the query language, available in TIBCO BusinessEvents Enterprise Suite only.
VRF Functions
The VRF category of functions (within the Standard Functions) provide flexibility when you are working with virtual rule function implementations. The functions are available in the Standard catalog and also in Decision Manager.
Virtual rule functions are used with Decision Manager. See Decision Manager and Rules Management Server and Virtual Rule Functions and Decision Manager for more information.
These functions enable you to do the following:
The functions are as follows:
getVRFImplByName()
getVRFImplNames()
getVRFImpls()
invokeAllVRFImpls()
invokeVRFImpl()
invokeVRFImplByName()
invokeVRFImpls()
Common arguments used in the above functions are described in Table 14, Common Arguments for VRF Functions.
VRF Function Arguments
The VRF functions use various subsets of the following common arguments:
The universal resource identifier (URI) for the virtual rule function. This is typically the full path to the virtual rule function within the project directory. For example, in the CreditCardApplication example, the virtual rule function Person_VirtualRuleFunction() has the following URI:
An object representing a virtual rule function implementation. This argument is required when invoking specific virtual rule function implementations.
The name of a decision table (also known as a virtual rule function implementation). For example, in the CreditCardApplication example, the virtual rule function BankUser_VirtualRuleFunction has an implementation (decision table) called bankUser.
The implName argument is used to retrieve a corresponding implementation object, or to execute an implementation.
The arguments to be passed to one or more virtual rule function implementations on invocation. These objects consist of the concepts, events, scorecards, and so on. that are needed by the implementation or implementations. For example, the processApplication implementation in the CreditCardApplication example project requires concepts of type Application, BankUser, and CreditCardApplication to be passed as arguments. In order to invoke the processApplication implementation, an instance of each concept type must be passed in the args array.
This argument is used only for the invokeVRFImpls function. When invoking multiple implementations, the return value of each implementation is stored in this array. The array will contain a null entry for each implementation that does not return a value.
 
Temporal Functions
The set of standard functions that come with TIBCO BusinessEvents includes functions that allow you to perform calculations on numeric values sampled over time. These functions are called temporal functions and they work exclusively with concept properties that store numeric values. Temporal functions make use of the history ring buffer to sample a property’s values over time.
All temporal functions include these parameters, illustrated in Figure 8:
property — The name of the property for which you want to sample values.
stime — The time from which you want to begin sampling values (the start time) measured in milliseconds since 00:00:00 UTC on January 1, 1970.
etime — The time at which you want to stop sampling values (the end time) measured in milliseconds since 00:00:00 UTC on January 1, 1970.
sample_rate — The number of milliseconds between samples.
bound_by_stime — A flag indicating whether the start-time is flexible:
True indicates that if the start time you provide is earlier than the time stamp for the oldest available value, you want to perform the calculation starting with the oldest available value.
False indicates that if the start time you provide is earlier than the time stamp for the oldest available value, you want to abort the calculation.
Figure 8 Temporal Functions Parameters