Oracle GlassFish Server 3.0.1 Add-On Component Development Guide

Registering an Event Listener

Registering an event listener enables the listener to receive callbacks from the GlassFish Server event infrastructure. The listener can then collect data from events and update monitorable objects in the object tree. These monitorable objects form the basis for monitoring statistics.

Registering an event listener also makes a component and its statistics monitorable objects by adding statistics for the component to the monitorable object tree.

At runtime, the GlassFish Server event infrastructure registers listeners for an event provider when the event provider is started and unregisters them when the event provider is shut down. As a result, listeners have no dependencies on other components.

To register a listener, invoke the static org.glassfish.external.probe.provider.StatsProviderManager.register method in the class that represents your add-on component. In the method invocation, pass the following information as parameters:

Example 5–7 Registering an Event Listener

This example shows the code for registering the event listener TxListener for the add-on component that is represented by the class TransactionManagerImpl. The statistics that are defined in this listener are associated with the web-container configuration element. The listener is registered under the server/applications node. The path from this node to the statistics in the event listener is tx/txapp.

Code for the constructor of the TxListener class is beyond the scope of this example.

import org.glassfish.external.probe.provider.StatsProviderManager;
import org.glassfish.external.probe.provider.PluginPoint
public class TransactionManagerImpl {
    StatsProviderManager.register("web-container", PluginPoint.APPLICATIONS, 
        "tx/txapp", new TxListener());