A JMX MBean to visualize AWT events

Some MBean seem generic enough to be deployed in any Java application. Why not share them?

I recently developed an MBean that can be dropped in any Java application. It will export AWT events in the JMX world. Using JMX monitoring tools, you can visualize what is happening when the mouse is moved, a button is pressed and much more. The today MBean code is verbose and could be optimized but I think that it makes a start.

Your application doesn't need any particular modifications. Just download the MBean sources (Standard MBean class and interface), compile them and deploy the MBean in your application.

1 Deploying the MBean


This MBean follows the singleton pattern. A single MBean instance is deployed per application. Call AWTEvents.getDefault in order to access the singleton mbean. Then register it in an MBeanServer. Using JDK 5, you can use the platform MBeanServer.

     AWTEvents mbean = AWTEvents.getDefault();
     ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,new ObjectName(":type=AWTEvents");

Recompile and relaunch your application.

2 Monitoring thanks to JConsole


Connect JConsole to the running process. NetBeans users, have a look to JMX module documentation to see how to automatically connect JConsole to your running project.

Once JConsole is connected to your application, select MBeans Tab then AWTEvents mbean.
You should see something like:

JConsole 1

For each AWT event (Invocation, Action, Mouse, ...) an MBean attribute is exposed. It displays the number of time an event has occurred.


An interesting thing to visualize is the attribute value plotting. Double clicking on numerical values will make a plotter to be displayed.
If you double click on NumMouseMotionEvents attribute value and move mouse pointer on top of your application, you should visualize something like :
JConsole 2

You can do the same for any numerical attributes.

What about receiving a JMX notification when an AWT event occurs?
CurrentNotificationFilter, writable attribute, allows you to express for which AWT event a JMX notification is to be sent. To see the list of possible filters, double click on PossibleNotificationFilterValues attribute.

JConsole 3

You can provide multiple filters by using '|' as separator. Setting to all filter will make all AWT events to be translated into JMX Notifications.

JConsole 4

Select Notifications Tab to visualize received notifications. First subscribe then play with your app. You should received a lot of JMX Notifications.
JConsole 5

Want to stop the translation ? Select Operations Tab. From here you can start the translation, stop it or reset attribute counters.

JConsole 6
Have fun and be prepared to share your MBeans!

Jean-Francois
Comments:

Post a Comment:
Comments are closed for this entry.
About

jeanfrancoisdenise

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today