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:;. -jar SwingSet2.jar

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
Comments:

Nice to see the blog. Waiting for some more :)

Posted by Vaibhav on July 23, 2007 at 01:40 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

kannan

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