I want to show performance statistics for particular request type. When Controller class gets the HTTP Request from browser, it then marshals request xml in to a request object. From request object I can get request type.
Is it possible to inject JMX MBeans for particular request type and broadcast it to JConsole?
Asked
Active
Viewed 149 times
0

Himanshu Yadav
- 13,315
- 46
- 162
- 291
1 Answers
1
Is it possible to inject JMX MBeans for particular request type and broadcast it to JConsole?
Jconsole does polling of statistics and you can't "broadcast" a request type that you define since that class won't be in the Jconsole jar.
What you can do is keep a count of the request types in a map and then return a String[]
of type -> count
string output if you like. Something like:
public String[] getResultTypeCount() {
List<String> list = new ArrayList<String>();
for (Map.Entry<String, Integer> entry : typeMap.entrySet()) {
list.add(entry.getKey() + " => " + entry.getValue());
}
return list.toArray(new String[list.size()]);
}
You might want to look into JMX notifications.

Gray
- 115,027
- 24
- 293
- 354
-
Can I register Request class to JConsole? – Himanshu Yadav Apr 23 '13 at 17:59
-
No @HimanshuYadav. You have to use classes that are built into the JDK. – Gray Apr 23 '13 at 18:05
-
Let me rephrase my question. I can create a JMX Bean for the request object. Is it possible to register JMX Bean for particular request types? – Himanshu Yadav Apr 23 '13 at 18:09
-
Yes, sure @HimanshuYadav. You can call `mbeanExporter.registerManagedResource(object, name);` anytime you want to register on demand objects for a particular request type. – Gray Apr 23 '13 at 18:14
-
You might consider using my SimpleJMX library which makes it pretty easy: http://256.com/sources/simplejmx/ – Gray Apr 23 '13 at 18:15
-
Great! And It will give me what I am expecting. Right? Or would it behave in a different way? – Himanshu Yadav Apr 23 '13 at 18:16
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28764/discussion-between-gray-and-himanshu-yadav) – Gray Apr 23 '13 at 18:17