Kannan's Weblog
JMX + assistive technologies for visualizing AWT events
Jean-Francois Denise has written an excellent blog for visualizing AWT events on a targetted application at:
http://blogs.sun.com/jmxnetbeans/entry/jmx2awt_mbean
The approach requires a very small modification in the targetted application in order to deploy the MBean:
AWTEvents mbean = AWTEvents.getDefault();
ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,new ObjectName(":type=AWTEvents");
If the targetted application is not to be touched at all but still achieve the same goal as in the above blog, assistive technologies could be used:
So assuming I write a JMX agent as below:
import javax.management.*;
import java.lang.management.*;
public class AWTEventAgent {
private MBeanServer mbs = null;
public AWTEventAgent() {
// Create an MBeanServer and HTML adaptor (J2SE 1.4)
mbs = ManagementFactory.getPlatformMBeanServer();
// Unique identification of MBeans
AWTEvents mbean = AWTEvents.getDefault();
ObjectName beanName = null;
try {
// Uniquely identify the MBeans and register them with the MBeanServer
beanName = new ObjectName("AWTEventAgent:type=AWTEvents");
mbs.registerMBean(mbean, beanName);
} catch(Exception e) {
e.printStackTrace();
}
}
}
Compile the file and launch your targetted application say SwingSet2.jar for e.g as below:
D:\jdk1.6.0\demo\jfc\SwingSet2>java -Djavax.accessibility.assistive_technologies=AWTEventAgent -Xbootclasspath/p:
The above syntax is on Windows and a similar approach on other platforms (Solaris/Linux) using the appropriate path separator could be done.
Note that we use the system property -Djavax.accessibility.assistive_technologies which points to the AWTEventAgent class and it needs to be loaded on startup by specifying the Xbootclasspath to its location.
In jdk 6.0 and onwards, it should be possible to load the above agent in the targetted application using attach on demand feature at run time. I will try to come out with a sample code for it shortly.
Thanks,
Kannan
Posted at 10:43PM Mar 11, 2007 by Kannan Balasubramanian in Sun | Comments[1]
Posted by Vaibhav on July 23, 2007 at 08:40 PM IST #