Apama 10.3.1 | Apama Documentation | 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 statement
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.
statement
Specifies an EPL statement. Specify a single statement or enclose multiple statements in braces. The from statement coassigns each stream output item to the specified variable and executes the statement or 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 statement or 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 statement
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.
statement
Specifies an EPL statement. You can specify a single statement or you can enclose multiple statements in braces. The from statement coassigns each stream output item to the specified variable and executes the statement or block once for each output item.
If you want the statement to be executed once per lot rather than once per item coassign the results to a sequence. See Coassigning to sequences in stream listeners.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.