Function terminates before the end of the logic that is before its call

Hello all,
in the function TriggerEmailAlarmMessage() there is a log message at the end of that function, why is that messages showing up before the logic that is before that function call?

if (newAlarms = true) {
				string machineName := new string;
				string deviceId := new string;
				boolean deviceFound := false;
				integer i := 0;

				// Searching x the machine name that is used x representing the object in user interfaces.
				FindManagedObject request := new FindManagedObject;
				request.reqId := Util.generateReqId();
				request.deviceId := "1523844618";
				monitor.subscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
				on FindManagedObjectResponse(reqId=request.reqId) as response
				and not FindManagedObjectResponseAck(request.reqId) 
				{
					// Extract information from the document
					AnyExtractor ex := AnyExtractor.create(response.managedObject.params["emailConfiguration"]);

					// Loop trough all the machines
					while (true) {
						sequence<any> deviceIds := ex.getSequenceOr([i].toString() + ".childDevicesIds", new sequence<any>);
						if (deviceIds = (new sequence <any>)) {
							break;
						}

						integer j := 0;
						while (j < deviceIds.size()) {
							if (ex.getString([i].toString() + ".childDevicesIds" + [j].toString()) = second32Bit.source) {
								integer tempCounter := 0;

								// Get list of email
								sequence<any> emailList := ex.getSequence([i].toString() + ".email");
								while tempCounter < emailList.size() {
									string emailRead := ex.getString([i].toString() + ".email" + [tempCounter].toString());
									emailReceivers.append(emailRead);
									tempCounter := tempCounter + 1;
								}

								// Get list of emailCC
								sequence<any> emailListCC := ex.getSequence([i].toString() + ".emailCC");
								tempCounter := 0;
								while tempCounter < emailListCC.size() {
									string emailReadCC := ex.getString([i].toString() + ".emailCC" + [tempCounter].toString());
									emailCC.append(emailReadCC);
									tempCounter := tempCounter + 1;
								}

								// Get machine name
								machineName := ex.getString([i].toString() + ".name");

								// Set flag because we found the device in the list
								deviceFound := true;

								// Exit the j while loop;
								break;
							}
							j := j + 1;
						}

						if deviceFound = true {
							// Exit for the while 1 loop
							break;
						}
						i := i + 1;
					}
					TriggerEmailAlarmMessage(second32Bit.source, machineName,INDEX_ERROR_FOUND);
				}
				on FindManagedObjectResponseAck(request.reqId) 
				as requestCompleted
				{
					// Request is completed and we can unsubscribe from this channel
					monitor.unsubscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
				}
				send request to FindManagedObject.SEND_CHANNEL;
				TriggerEmailAlarmMessage(second32Bit.source, machineName,INDEX_ERROR_FOUND);
			}

Hi Gabriele,

this is due to the event-based nature of EPL. Any line starting with "on " is an event listener. The code inside of the following blocks is not executed right away but only if the matching event is received.

In your code, you prepare a FindManagedObject request and then you configure two event listeners. One to react to FindManagedObjectResponse (which will be sent for each found MO) and FindManagedObjectResponseAck (which will be sent once you have received the last MO).

Then, you actually send out the request (line starting with “send request” and then call TriggerEmailAlarmMessage. So any logging in that action will be executed before any of the events for the listeners are received thus these will not have been executed yet.

Best regards,
Harald

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.