java.jmx

Details

Type:
Defect

Status:
Resolved

Priority:
Minor

Resolution:
Completed

Affects Version/s:
None

Fix Version/s:
None

Component/s:
None

Labels:

None

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.

Nick Bailey
added a comment - 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?

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.

Nick Bailey
added a comment - 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?