Registering an event listener enables the listener to receive callbacks from the Enterprise 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.
At runtime, the Enterprise 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 org.glassfish.flashlight.client.ProbeClientMediator.registerListener method in the class that represents your add-on component. In the method invocation, pass the listener object as a parameter.
The registerListener method returns a collection of ProbeClientMethodHandle objects. To enable a listener to turn on or turn off monitoring, pass this collection to your listener class. In your listener class, invoke methods of the ProbeClientMethodHandle objects to turn on and turn off monitoring.
To turn on monitoring, invoke the enable method. If monitoring is turned on, a functional implementation of methods in is generated when the event provider is registered.
To turn off monitoring, invoke the disable method. If monitoring is turned off, a nonoperational implementation of methods in is generated when the event provider is registered.
For information about how to register an event provider, see Registering an Event Provider.
This example shows the code for registering the event listener TxListener for the add-on component that is represented by the class TransactionManagerImpl.
Code for the following methods of the TxListener class is beyond the scope of this example:
The TxListener constructor
The setProbeListenerHandles method
... import org.glassfish.flashlight.client.ProbeClientMediator; ... public class TransactionManagerImpl { @Inject private ProbeClientMediator pcm; ... TxListener txL = new TxListener(txmNode); Collection<ProbeClientMethodHandle> handles = pcm.registerListener(txL); txL.setProbeListenerHandles(handles); ... }