Sun GlassFish Enterprise Manager Monitoring Scripting Client 3.0 Installation and Quick Start Guide

ProcedureTo Register a Script as a Listener for an Event

Registering a script as listener for an event enables the script to listen for the event and to receive callbacks from the Monitoring Scripting Client when the script receives the event. The script can then collect data from the event. Registering a script as listener for an event also specifies the event callback function that is to be called when the event is received. For information about writing an event callback function, see Writing an Event Callback Function.

  1. Create an array of the event parameters to pass to the event callback function.

    This array may contain any number of the event's parameters in any order.

  2. Invoke the scriptContainer.registerListener method.

    In the invocation of the scriptContainer.registerListener method, pass the following information as parameters to the method:

    • The event ID of the event

    • The array of event parameters that you created in the previous step

    • The name of the event callback function that is to be called when the event is received


Example 1–4 Registering a Script as a Listener for an Event

This example registers a script as a listener for the event glassfish:web:jsp:jspLoadedEvent. When this event is received, the event parameter hostName is passed to the jspLoaded() event callback function. For clarity, the declaration of the event callback function jspLoaded() is also shown in this example.

function jspLoaded(hostName) {
    ...
}

params = java.lang.reflect.Array.newInstance(java.lang.String, 1);
params[0]="hostName";

scriptContainer.registerListener('glassfish:web:jsp:jspLoadedEvent', 
    params, 'jspLoaded');