Tap Examples

In this section:

This topic illustrates the use of various iWay Functional Language (iFL) statements.


Top of page

x
_IF Statement

The following examples use the _IF statement to filter messages and capture events.

In the second example, the _IF statement contains an optional third parameter. The third parameter supplies an expression that will be evaluated when the first parameter evaluates to false.



Example: _IF Statement
_IF
( 
     _cond(_xpath(//number),>,0),
     _expose(myevent,_xpath(//number),db,int)
)

where:

_cond(_xpath(//number,>,0)

Is an iFL function that checks a message for the value of the first occurrence of a number element (_xpath(//number)). It returns true if the value of the number element is greater than 0.

_expose(myevent,_xpath(//number),db,int)

Is an iFL function that is executed if the value of the first occurrence of the number element is greater than 0. The _expose() function captures the event named myevent and saves the element value as a fact in the in-memory database (db). The data type of the fact is int.



Example: _IF Statement With ELSE
_IF
( 
     _cond(_xpath(//number),>,0),
     _expose(gtzeroevent,_xpath(//number),db,int), 
     _expose(notgtzeroevent,_xpath(//number),db,int)
)

where:

_cond(_xpath(//number),>,0)

Is an iFL function that checks a message for the value of the first occurrence of a number element (_xpath(//number)). It returns true if the value of the number element is greater than 0.

_expose(gtzeroevent,_xpath(//number),db,int)

Is an iFL function that is executed if the value of the first occurrence of the number element is greater than 0 (that is, the first parameter evaluates to true). This _expose() function captures the event named gtzeroevent and saves the element value as a fact in the in-memory database (db). The data type of the fact is int.

_expose(notgtzeroevent,_xpath(//number),db,int)

Is an iFL function that is executed if the value of the first occurrence of the number element is not greater than 0 (that is, the first parameter evaluates to false). This _expose() function captures the event named notgtzeroevent and saves the element value as a fact in the in-memory database (db). The data type of the fact is int.


Top of page

x
Evaluating a Boolean Expression

If you supply only one parameter on an _IF statement, you can evaluate a Boolean expression.



Example: Evaluating a Boolean Expression

Top of page

x
Dynamic Event Discovery

You may not know the events that you need in order to infer a complex event or events. You can dynamically discover events by capturing data in a message and using the data values as part of the event name.

_expose(event._XPATH(//sale/salesrep/name),_XPATH(//sale/price),DB,float)

In the preceding example, the tap captures the name of the sales representative and uses it to construct the name of the event. The following string is the prefix for the event name:

event

For example, this technique dynamically creates an event named

event.bob

where:

bob
Is the name of the sales representative.

You can capture a sales event for every sales representative, without having to first create the event.


iWay Software