Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Using output from streams
 
Using output from streams
 
Listener variables and streams
Coassigning to sequences in stream listeners
A stream listener passes output items from a stream to procedural code. You use a from statement to create a stream listener. The from statement has two forms.
The first form of the from statement creates a stream listener that takes items from an existing stream. For example:
from sA as a {
   /* Code here executes whenever an item is available from sA. */
}
The second form of the from statement contains a stream query definition, which creates a new stream query. The stream listener takes items from the output stream of the query. For example:
from a in sA select a as a {
   /* Code here executes whenever the query produces output. */
}
The syntax for the first form of the from statement is as follows:
[listener:= ] from streamExpr coassignment block
Syntax Element
Description
listener
Optional. You can specify a listener variable to refer to the stream listener that the from statement creates. You can declare a new listener variable or a use an existing listener variable.
streamExpr
Specifies any expression of type stream except a stream query. This can be, for example, a stream variable or a stream source template. If you want to specify a stream query, use the other form of the from statement.
coassignment
You must coassign the stream output into a variable. You can either use the as operator to implicitly declare the variable in the scope of the following statement or the : assignment operator to coassign to a local or global variable of the same type as the stream output that has already been declared.
For details about the characters you can specify, see Identifiers.
The output from a stream is referred to as a lot. Like an auction lot, a stream output lot can contain one or more items. If the stream output is a lot that contains more than one item, the from statement coassigns each item, in turn, to the variable. See Working with lots that contain multiple items.
A from statement cannot specify multiple coassignments.
block
Specifies a block of EPL statements, enclosed in braces. The from statement coassigns each stream output item to the specified variable and executes the block once for each output item.
If the stream output is a lot that contains more than one item, and you want to execute the block just once for the lot rather than once for each item in the lot, coassign the result to a sequence. See Coassigning to sequences in stream listeners.
The syntax for the second form of the from statement is as follows:
[listener:=] StreamQueryDefinition coassignment block
Syntax Element
Description
listener
Optional. You can specify a listener variable to refer to the stream listener that the from statement creates. You can declare a new listener variable or a use an existing listener variable.
StreamQueryDefinition
Specifies a stream query. See Defining stream queries.
coassignment
You must coassign the stream output into a variable. You can either use the as operator to implicitly declare the variable in the scope of the following statement or the : assignment operator to coassign to a local or global variable of the same type as the stream output that has already been declared.
For details about the characters you can specify, see Identifiers.
If the query outputs lots that contain more than one item, the from statement coassigns each item in the lot, in turn, to the variable. See Working with lots that contain multiple items.
A from statement cannot specify multiple coassignments.
block
Specifies a block of EPL statements, enclosed in braces. The from statement coassigns each stream output item to the specified variable and executes the block once for each output item.
If the stream output is a lot that contains more than one item, and you want to execute the block just once for the lot rather than once for each item in the lot, coassign the result to a sequence. See Coassigning to sequences in stream listeners.