sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1532351 - in /sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl: Constants.java JMXResourceProvider.java MBeanResource.java
Date Tue, 15 Oct 2013 14:19:41 GMT
Author: cziegeler
Date: Tue Oct 15 14:19:40 2013
New Revision: 1532351

URL: http://svn.apache.org/r1532351
Log:
SLING-3176 : ValueMap of jmx resource should contain mbean attributes

Modified:
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java?rev=1532351&r1=1532350&r2=1532351&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
Tue Oct 15 14:19:40 2013
@@ -45,4 +45,4 @@ public abstract class Constants {
     public static final String TYPE_MBEAN = "sling:mbean";
 
     public static final String TYPE_MBEANS = "sling:mbeans";
-}
+}
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java?rev=1532351&r1=1532350&r2=1532351&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
Tue Oct 15 14:19:40 2013
@@ -142,7 +142,7 @@ public class JMXResourceProvider impleme
                 }
             } else {
                 if (info.pathInfo == null ) {
-                    return new MBeanResource(resourceResolver, this.convertObjectNameToResourcePath(info.objectName),
path, info.mbeanInfo, info.objectName);
+                    return new MBeanResource(this.mbeanServer, resourceResolver, this.convertObjectNameToResourcePath(info.objectName),
path, info.mbeanInfo, info.objectName);
                 }
                 if ( info.pathInfo.equals("mbean:attributes") ) {
                     return new AttributesResource(resourceResolver, path);
@@ -231,7 +231,7 @@ public class JMXResourceProvider impleme
                                     final MBeanInfo info = mbeanServer.getMBeanInfo(on);
                                     final String path = convertObjectNameToResourcePath(on);
                                     final int sep = path.lastIndexOf('/');
-                                    this.next = new MBeanResource(parent.getResourceResolver(),
path, parent.getPath() + "/" + path.substring(sep + 1), info, on);
+                                    this.next = new MBeanResource(mbeanServer, parent.getResourceResolver(),
path, parent.getPath() + "/" + path.substring(sep + 1), info, on);
                                 } catch (final IntrospectionException e) {
                                     // ignore
                                 } catch (final InstanceNotFoundException e) {

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java?rev=1532351&r1=1532350&r2=1532351&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
Tue Oct 15 14:19:40 2013
@@ -21,8 +21,14 @@ package org.apache.sling.jmx.provider.im
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
 import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 
 import org.apache.sling.api.resource.AbstractResource;
 import org.apache.sling.api.resource.ResourceMetadata;
@@ -44,11 +50,16 @@ public class MBeanResource extends Abstr
 
     private final String resourceType;
 
-    public MBeanResource(final ResourceResolver resolver,
+    /** The mbean server. */
+    private final MBeanServer mbeanServer;
+
+    public MBeanResource(final MBeanServer mbeanServer,
+            final ResourceResolver resolver,
             final String resourceType,
             final String path,
             final MBeanInfo info,
             final ObjectName objectName) {
+        this.mbeanServer = mbeanServer;
         this.resourceResolver = resolver;
         this.path = path;
         this.info = info;
@@ -116,6 +127,25 @@ public class MBeanResource extends Abstr
         result.put(Constants.PROP_CLASSNAME, this.info.getClassName());
         result.put(Constants.PROP_OBJECTNAME, this.objectName.getCanonicalName());
 
+        final MBeanAttributeInfo[] attribs = this.info.getAttributes();
+        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);
+                }
+            } catch (final AttributeNotFoundException e) {
+                // ignore
+            } catch (final InstanceNotFoundException e) {
+                // ignore
+            } catch (final MBeanException e) {
+                // ignore
+            } catch (final ReflectionException e) {
+                // ignore
+            }
+        }
+
         return result;
     }
 }



Mime
View raw message