Version: 17.07
Supported Since: 17.07
ForEach loop processor can be used to iterate over the elements of a Java’s Collection or a Map. This processor behaves similar to the Java 8’s forEach with a Consumer in case of a Collection iteration and Java 8’s forEach with a BiConsumer in case of a Map iteration.
This loop internally uses Java method calls (leading to recursion), hence may not be suitable for arbitrarily large loops (e.g. those spanning more than 500 cycles): |
You may run into a StackOverflowError
if the loop outgrows Java’s available stack space.
The actual limit depends on the amount of stack allocated in each cycle, comprising factors such as
number of elements in the loop body and the local (non-heap) object allocations in each cycle.
Application level resources (e.g. opened streams and file handles, file-store file entries leased for current message) allocated within the loop body may not get released until the whole loop terminates (because the same message and message context are reused across all iterations), leading to resource exhaustion.
In order to use this processing element, you must first select the Flow Control dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Flow Control dependency. |
Loop termination out |
Once the conditions are met to terminate the loop, message context will leave the loop through this port |
In loop flow port |
If the conditions are met to continue looping, message context will be passed through this port. The flow which starts from this port will act similar to the body of a standard for loop. |
On Exception |
The message context will be sent to this out port if any exception occurred while looping. However, if an exception thrown during the in loop flow, the loop will be terminated and continue through the exception flow of the corresponding element. |
Design of the flow should re connect back to the For Loop processor’s In Port in order to maintain the looping functionality. |
Collection Variable name * |
Basic |
Variable name of the context scope variable, which holds the java Collection or Map |
Collection Type |
Basic |
Type of the Java collection. It can be one of the following. |
Iterating Variable Name |
Basic |
This variable behaves differently in two cases of Collection types
|
Variable to assign the value corresponding to the key |
Basic |
This parameter is applicable only in the case of Map. The in loop flow can access the value of the current <key,value> pair of java map from this variable. |