Sun GlassFish Enterprise Server v3 Prelude Add-On Component Development Guide

Subscribing to Events From Event Provider Classes

To receive events from event provider classes, a listener must subscribe to the events. Subscribing to events also specifies the provider and the type of events that the listener will receive.

To subscribe to events from event provider classes, write one method in your listener class to process each type of event. To specify the provider and the type of event, annotate the method with the org.glassfish.flashlight.client.ProbeListener annotation. In the @ProbeListener annotation, specify the provider and the type as follows:

"component-name:provider-name:app-name:event-type"

Note –

The @ProbeListener annotation is an unstable interface and is subject to change.


component-name

The name of add-on component that is to send the event. This parameter must match the parameter that is defined when the event provider is registered. See Registering an Event Provider.

provider-name

The name of the provider. This parameter must match the parameter that is defined when the event provider is registered. See Registering an Event Provider.

application-name

The name of the application that the add-on component represents. This parameter must match the parameter that is defined when the event provider is registered. See Registering an Event Provider.

event-type

The type of the event. This type is defined in the event provider interface. For more information, see Identifying the Event Type.

In the method body, provide the code to update monitoring statistics in response to the event.


Example 5–4 Subscribing to Events From Event Provider Classes

This example shows the code for subscribing to events of type begin from the tx component. The provider of the component is TxManager. The body of the begin method contains code to increase the transaction count txcount by 1 each time that an event is received.

The definition of the begin event type is shown in Example 5–1.

The code for sending begin events is shown in Example 5–3.

...
import org.glassfish.flashlight.client.ProbeListener;
...
public class TxListener {
    AtomicInteger txCount = ....;

    @ProbeListner("tx:TxManager::begin")
    public void begin(String txId) {
      txCount++;
    }
  }