for loop

For Loop

Version: 17.07

Supported Since: 17.07

What is a For Loop processor?

For loop processor can be used to execute the same flow for a fixed number of iterations. This processor behaves similar to standard for loops which are available commonly in any programming language. Even though this processor supports only fixed number of iterations, user has the flexibility to determine the number of iterations at runtime or at design time.

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.

forloop ico labled

Out Ports

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.

Parameters

Fixed Counter *

Basic

If fixed counter is selected, loop will be iterated over a fixed number of iterations which should be defined at design time. Else processing element can be configured to extract iteration count from the payload at runtime.

Iterations *

Basic

This parameter will be available if loop is configured in Fixed Counter mode. This parameter determines the number of iterations of the loop at design time.

Iteration count variable

Basic

Variable will be created in the message context by this name, and on each iteration variable will be updated by the current iteration count. If this variable is not specified, processor will not set or update the iterations count.

Be careful on nested for loops to specify distinct variable names for each loop.

Predicate Type *

Basic

This parameter will be available if loop is configured in Runtime iteration determination mode(Fixed Counter = false).The type of predicate to be used for the evaluation. The following predicate types are supported.

  • HEADER - A transport header value from the message will be used in the predicate

  • PROPERTY - A message property will be used in the predicate

  • CONTENT - An extracted XPath value from the message payload will be used in the predicate

  • VARIABLE - A scope variable from the message context will be used in the predicate

Variable Name *

Basic

The interpretation of this parameter’s value depends on the selected predicate type.

  • HEADER - Variable Name is the name of the transport header to be used in the predicate

  • PROPERTY - Variable Name is the key of the message property to be used in the predicate

  • CONTENT - The XPath to extract the value the from message payload

  • VARIABLE - Variable Name is the key of the scope variable to be used in the predicate

Processing element always expects a variable of type Integer and processor will fail, if the specified variable can’t be casted to an Integer.

Namespaces

Basic

If the predicate type is CONTENT (where an XPath value is used for the condition), this parameter specifies an optional map (defined as a resource) with namespace prefixes (as keys) and namespaces (as values) used within the XPath expression

Sample Use case

In the following use case, the requirement is to call a rest end point of a stock exchange. Below service is exposed by a stock broker and the flow will be initiated by a buyer by sending an initial request to the NIO HTTP Listener(of stock broker). Assume that, due to the higher demand, the stock exchange tries to perform only a limited number of operations per unit time and drops all other requests. Objective of this setup is to retry 3 times, if request dropped from stock exchange’s end, before sending status as failed to the buyer.