Custom event creation best practice
-
Dear Mango Users and Developers,
DISCLAIMER: Not sure whether this is the right place for my thread, but the section "Mango 1.12.5 and earlier" does not have a development subsection. Please move it to 'general discussion' if needed.
I am using a legacy version of Mango M2M 1.12.2 and would like to enhance the event handler (+listener?) to handle acknowledge events that would be triggered if a user acknowledges an alarm (by pressing the green check-mark).
I am trying it along the lines of the 'active' and 'inactive' events in the event handlers menu. I looked into various classes, e.g. EventHandlerVO, EventHandlersDwr, EventHandlerRT and related ones. I can already save an 'acknowledge' action in the event handlers .js interface.
As a next step I need to create the 'acknowledge' event. I searched for an example of event generation, but could not find any. Could anyone point me to an example where an event is triggered? Where to begin?
A gentle shove is much appreciated :)
Best Regards,
Michael Bach -
Hi Michael,
I personally would not generate a new event upon an event acknowledgement. That feels a bit much like the snake eating its own tail. Instead, i would be inclined to add a new notification to the event itself.
Currently, an event is raised and in many cases returns to normal (or goes inactive). I would add to this a notification for when the event is acknowledged. The event handlers would need to be enhanced to handle this notification, but i believe it's the better way to go.
-
Hi Matthew,
I see your point with the snake :) The acknowledgement would most certainly cause a point (preferably to be chosen by the user) to be set in a meta data source so I thought of the SET_POINT type event approach. As an aside, it would be nice to have the acknowledgement listed in the event log...
Regarding implementation of your notification approach, would you add the notification to the event as a string or integer - that would then be tested by the event handler? Is there a notification mechanism implemented in Mango Automation 2.x where I could have a look at how experts would solve such a problem? Could you give me any hint implementation-wise?
Thanks for your comment, much appreciated.
Best Regards,
Michael -
It's certainly not a small job. You would want to route acks from wherever they occur (MiscDwr and EventDwr come to mind) to the event manager, so that it can look up the instances. This would be a bit of work because events can RTN without being ack'ed, and so would not necessarily be in memory. The EventHandler will need to have a new notification method, which the event manager would call. Then all of the event handler implementations would need to be enhanced. Finally, the UI for each event handler would need to include the new notification.
-
Hum. I get the picture. Thanks for the explanation! I do not think I could make it in a reasonable amount of time though. While your suggestion is a generic one, I just need to set a point on an ack event...
In the meantime, I succeeded with another approach in adding an 'acknowledged' action to the EventHandlerVO (in the fashion of active and inactive actions) including saving (serialization). Next step would be to set the associated data point (in case of SET_POINT action) with a DWR method called from ackEvent() through the onclick in the green checkmark div.
The further processing: eventId -> dataPointId associated with event -> eventHandler associated with event and dataPointId (how?) -> call SET_POINT actions derived from matching event handlers.
The missing link is: How to test whether an event handler is associated with a given data point and a given event? Could you point me in the right direction?
-
My last post was kind of confused - must be because it was just before lunch break...
I got it to work by now, though. I used the EventManager and my existing acknowledge actions. The 'missing link' was my misunderstanding that the private EventManager.setHandlers() is not a 'simple' setter, but instead creates the runtimes from EventHandlerVO's for a given EventInstance. With it, I was able to generate a Map<Integer, List<EventHandlerRT>> that maps events to their handlers. The acknowledge actions of the EventHandlerRT's matching a given eventId are then run in the manner of the existing actions.
I do not know whether my approach is a wise one - it works atm, but untested.
Thanks for the event manager hint Matthew.
Best Regards,
Michael