Handling System Events

Because addons that use the system script environment do not have access to user interface elements, they must have some way of determining when they need to execute the logic they are written for. The primary means of supporting this need in the addon system is via system events. System events are events that are fired by a host application in response to some trigger, whether it is based on an action occurring in the host application (such as a user routing a request in the client) or the passage of a set interval of time. The best example of this is the Route system event that is available in the client. The route event is triggered every time a request is routed in the client and no applicable entry is found in the routing table. This allows addon developers to create system addons which provide fine-tuned, customizable routing logic.

Addons can take advantage of system events by doing two things inside of a system addon. First, the addon developer must provide a method that can be called whenever a given event is triggered. For example, you might write a "ProcessRoute" method for processing the Route event referenced above. Second, the addon must register for the event by calling the RegisterSystemEventHandler method. Generally, this will be done inside the Init method, but this is not required. An example of both steps is given below.

Handling Events Sample