general question: how to interface JMX code with application code?
Hello,
Thank you for answering my questions in my other thread. It makes sense that remote invocation (like access from JConsole) would need class definitions to be available for classes imported from the server. Also, using standard Java classes is a valid point.
Still, I'm now puzzled on how to use JMX to present server data that is dynamic? For example, I have a map of elements which is maintained on the server and is updated constantly. Entries are added and removed. I'd like to be able to present the snapshot of the map data via JMX to JConsole client.
My first approach was to add an attribute of type TabularData to an MBean registered with MBeanServer. I provided my own implementation of TabularData interface, that queried underlying map when it was created (the MBean was creating new TabularData object whenever the getter method for the attribute was called). But that approach got me back where I started - with a ClassNotFound exception for application-specific items stored in the map.
Even though I was only trying to get String representation of map entries, that representation was created when the getter method was called (for TabularData attribute), and for that the class definition was needed.
So now I'm thinking if perhaps I should reverse the approach: instead of trying to query my application from JMX bean, maybe I should somehow update the MBean content (or unregister and register again) every time there is a change made to the underlying map? That way the bean would contain a snapshot of current map status, presented by Java String classes (not application related classes), and JConsole could look at the data without class cast exceptions. All the plumbing required to create the String representation of map items would be done in map change handler, inside the application.
Would that be a better approach to using JMX? I would appreciate any comments/suggestions on this problem.
Regards,
Mark

