Deserializing TabularDataSupport

classic Classic list List threaded Threaded
4 messages Options
Ganesh Murthy Ganesh Murthy
Reply | Threaded
Open this post in threaded view
|

Deserializing TabularDataSupport

ActiveMQ via JMX offers a browseAsList() function (in org.apache.activemq.broker.jmx.DestinationView). This can be used to browse the contents of a queue. The browseAsTable() function returns a javax.management.openmbean.TabularData object. TabularDataSupport object has a Map called dataMap. I verified that in my case the dataMap is a LinkedHashMap. Before control returns from browseAsTable(), I am able to verify on the broker side that the order of the messages in the LinkedHashMap maintain insertion order.

When the TabularData is displayed in hawtio (which simply displays the data from jolokia), the order of the messages is random which means the order on the LinkedHashMap is lost. Is jolokia deserialization messing up the order on the messages?

The problem is happening also when I use jconsole to invoke browseAsTable.

Thanks in advance for your help.
roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Deserializing TabularDataSupport

Jolokia uses json-simple for the JSON representation of JMX (or other) objects. For TabularData the natural representation is JSONObject, but this is not ordered (and not sorted). It's simply a map. TabulatData is copied over into JSONObject and here the ordering gets lost. There is no easy way around this, sorry.

That TabularDataSupport uses a ordered Map is an implementation detail  and if you look into the JMX specs, there is no ordering implied at all (see e.g. `TabularData.keySet()`).  So its IMO pure luck that it uses a LinkedHasMap internally and you can't rely on that (other implementation of TabularData could choose another approach or even TabularData in a future Java version can change this without notice).

That's probably also the reason why jconsole exhibit the same behaviour.

The only reliable solution IMO would be if ActiveMQ exports its data as a list of e.g CompositeData or the client does some sorting on the keys (like a date) so that you at least could have some ordering.

sorry ...
... roland
... roland
Ganesh Murthy Ganesh Murthy
Reply | Threaded
Open this post in threaded view
|

Re: Deserializing TabularDataSupport

Thanks for the quick response.

I agree that the TabularData.keySet() does not mention anything about ordering -
http://docs.oracle.com/javase/7/docs/api/javax/management/openmbean/TabularData.html#keySet%28%29

If the JMX spec does change in the future to introduce support for ordering in TabularData, they will have to introduce other mechanisms by which software like Jolokia can reliably order the data upon deserialization.
roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Deserializing TabularDataSupport

Yeah, completely agreed. Jolokia will adapt to any future JMX version with its changes.

But please don't hold your breath.

... roland