<< Back to previous view

[JMX-6] Result of clojure.java.jmx.Bean.getAttribute is not a javax.management.Attribute Created: 26/Jul/12  Updated: 26/Jul/13  Resolved: 28/Sep/12

Status: Resolved
Project: java.jmx
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Chris Jeris Assignee: Chris Jeris
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File 0001-Return-a-list-of-Attribute-objects-from-.getAttribut.patch     File java-jmx-attribute-patch    
Patch: Code and Test
Approval: Accepted

 Description   

The documentation suggests that you create a JMX bean (clojure.java.jmx.Bean) by calling clojure.java.jmx/create-bean on a reference to a map whose values are the actual values you want as attributes: for instance, (create-bean (ref {:calls-so-far 0})). However, if you do this, when you get the attribute out using .getAttribute the result is the actual state value, and not the javax.management.Attribute in question as the interface specifies. This also causes a ClassCastException when you try to call .getAttributes or anything else that tries to add the attributes to an AttributeList.

The attached patch fixes this problem by wrapping the state value in a call to Attribute. so that .getAttribute yields an Attribute, and modifies objects->data to descend into Attribute values accordingly. The tests work, and it works for my use case, but I do not know whether this is the right solution in general.



 Comments   
Comment by Nick Bailey [ 06/Aug/12 4:35 PM ]

Chris,

Thanks for submitting a patch for this. I'll be able to review it sometime in the next few days hopefully.

Comment by Nick Bailey [ 31/Aug/12 4:40 PM ]

Chris,

Sorry for the delay.

Whats the reason for the addition to objects->data? By that point we've already read the attribute list for a bean and are processing the attribute values right?

Comment by Jürgen Hötzel [ 11/Sep/12 4:25 AM ]

I don't see whats wrong in the implementation of the DynamicMbean interface:

 
({:name getAttribute,                                                                                              
  :return-type java.lang.Object,                                                                                   
  :declaring-class javax.management.DynamicMBean,                                                                  
  :parameter-types [java.lang.String],                                                                             
  :exception-types                                                                                                 
  [javax.management.AttributeNotFoundException                                                                     
   javax.management.MBeanException                                                                                 
   javax.management.ReflectionException],                                                                          
  :flags #{:public :abstract}})       

the return type is

 java.lang.Object
, not
 javax.management.Attribute

Comment by Nick Bailey [ 11/Sep/12 11:14 AM ]

The documentation there is somewhat vague. Perhaps that part of the api shouldn't be changed. It seems like at least the .getAttributes implementation at least is wrong though. The documentation for AttributeList is clear that only Attribute objects should be added to the AttributeList, but it looks like all current jvm implementations (or ones we test with) don't do a good job of actually enforcing that.

http://docs.oracle.com/javase/1.5.0/docs/api/javax/management/AttributeList.html

Do we know if any built in dynamic mbeans return Attribute objects or the actual values of a specific attribute?

Comment by Nick Bailey [ 18/Sep/12 10:45 PM ]

Ok, found better documentation here.

http://docs.oracle.com/cd/E19698-01/816-7609/6mdjrf83d/index.html

So getAttribute should be returning an attributes value rather than an actual attribute object. But as I mentioned before, getAttributes should be returning a list of Attribute objects.

Comment by Nick Bailey [ 18/Sep/12 10:46 PM ]

Going to go ahead and update the patch accordingly.

Comment by Nick Bailey [ 18/Sep/12 10:59 PM ]

Updated patch. Look good Chris Jeris?

Comment by Chris Jeris [ 28/Sep/12 4:16 PM ]

Looks good and works for my use case. Sorry for the delay – I appear not to have email notifications from this JIRA configured correctly.

Comment by Nick Bailey [ 28/Sep/12 9:59 PM ]

Committed.

Generated at Thu Apr 24 07:54:38 CDT 2014 using JIRA 4.4#649-r158309.