which method to choose for jmx communication
I am developing a monitoring management java application using jmx api.I have seen examples in internet and be able to make remote calls from client application to server.My question ath this point is what will be best practise for communication parameters of remote method(s) between client and server.for instance, i can use some开发者_如何学JAVA collection object like hashtable and turn back again a hashmap as response.Another aproach can be generating a string on client side and parsing it at server side.Another aproach can be generating different serialiable objects at both side and passing its xml represantations may be(I'didnt try this so not sure about its technical possibility). Which approach(considerin method signatures below) will be best and adaptable for different input/output pair.
1)Hashmap methodCollection(Hashmap);
2)String methodRawString(String); 3)String methodObjectToXML(String inputObjectXML) ;It depends on your task. Theoretically custom serializable classes (value objects) are better and easier approach. But in this case you should be sure that you have exactly the same version of these classes on both sides (client and server).
If you cannot guarantee this and your data model is relatively simple, i.e. can be represented as primitives and collections (or maps) of primitives, use maps and collections.
The formatted strings (XML, JSON etc) is the most portable and the hardest way. You have to generate and parse XML, handle different versions of your format etc. But you will never get serialization exception and will be theoretically able to support cross version comparability.
With JMX, there are the MXBean features which are very interesting: you can have quite complex objects on the server without deploying any JAR on the client side. There is a good article here: http://java.sun.com/developer/technicalArticles/J2SE/mxbeans/.
Also, there is http://www.jolokia.org/ which is a JMX/HTTP bridge that provides REST/JSON access to your JMX beans. Very useful if the client side is not a Java app (a shell script for instance).
Jolokia has a sophisticated way for serializing objects in both directions. In the downstream (from server to client), every object can be serialized into a JSON object. For the upstream (from client to server for ojbects used in as method arguments or values in write operations), serializing is a bit more limited, however maps and list collections can be easily used when the type of the elements are basic ones (strings, number, boolean, other maps or lists). So, Jolokia is quite nice for typeless JMX remoting.
Yet another solution would be to restrict yourself to OpenTypes which are available on both sides without extra type information. With OpenType you can also easily model collections (TabularData). For the translation from an arbitrary Java-Object to an OpenType the MXBean framework is indeed very helpful (although the translation from a map results in a rather complex TabularData
format).
精彩评论