SLING-3176 : ValueMap of jmx resource should contain mbean attributes
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1532424 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java b/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
index 21aa8e3..d479f45 100644
--- a/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
+++ b/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
@@ -19,8 +19,11 @@
package org.apache.sling.jmx.provider.impl;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import javax.management.Attribute;
+import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
@@ -128,22 +131,33 @@
result.put(Constants.PROP_OBJECTNAME, this.objectName.getCanonicalName());
final MBeanAttributeInfo[] attribs = this.info.getAttributes();
+ final String[] names = new String[attribs.length];
+ int index = 0;
for(final MBeanAttributeInfo i : attribs) {
- Object value = null;
- try {
- value = this.mbeanServer.getAttribute(this.objectName, i.getName());
- if ( value != null ) {
- result.put(i.getName(), value);
+ names[index] = i.getName();
+ index++;
+ }
+ AttributeList values = null;
+ try {
+ values = this.mbeanServer.getAttributes(this.objectName, names);
+ if ( values != null ) {
+ final Iterator iter = values.iterator();
+ while ( iter.hasNext() ) {
+ final Attribute a = (Attribute)iter.next();
+ final Object value = a.getValue();
+ if ( value != null ) {
+ result.put(a.getName(), value);
+ }
}
- } catch (final AttributeNotFoundException e) {
- // ignore
- } catch (final InstanceNotFoundException e) {
- // ignore
- } catch (final MBeanException e) {
- // ignore
- } catch (final ReflectionException e) {
- // ignore
}
+ } catch (final AttributeNotFoundException e) {
+ // ignore
+ } catch (final InstanceNotFoundException e) {
+ // ignore
+ } catch (final MBeanException e) {
+ // ignore
+ } catch (final ReflectionException e) {
+ // ignore
}
return result;