You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/10/23 10:02:00 UTC
svn commit: r1534947 - in
/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl:
AttributeResource.java JMXResourceProvider.java MapResource.java
Author: cziegeler
Date: Wed Oct 23 08:01:59 2013
New Revision: 1534947
URL: http://svn.apache.org/r1534947
Log:
SLING-3200 : Avoid duplicated requests to mbeans when creating resources
Modified:
sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.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/MapResource.java
Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java?rev=1534947&r1=1534946&r2=1534947&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java (original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java Wed Oct 23 08:01:59 2013
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
@@ -188,24 +189,22 @@ public class AttributeResource extends A
current = (Map<String, Object>)child;
}
- return new MapResource(this.getResourceResolver(), this.getPath(), current);
+ return new MapResource(this.getResourceResolver(), this.getPath(), current, this);
}
return null;
}
- private Map<String, Object> convertData() {
- try {
- final Object value = attrValue;
+ private volatile Map<String, Object> convertedValue;
- if ( value instanceof TabularData ) {
- return convertObject((TabularData)value);
- } else if ( value instanceof CompositeData ) {
- return convertObject((CompositeData)value);
+ private Map<String, Object> convertData() {
+ if ( convertedValue == null ) {
+ if ( attrValue instanceof TabularData ) {
+ convertedValue = convertObject((TabularData)attrValue);
+ } else if ( attrValue instanceof CompositeData ) {
+ convertedValue = convertObject((CompositeData)attrValue);
}
- } catch (final Exception ignore) {
- // ignore and return null
}
- return null;
+ return convertedValue;
}
private Map<String, Object> convertObject(final TabularData td) {
@@ -292,7 +291,7 @@ public class AttributeResource extends A
return result;
}
- public Iterator<Resource> getChildren(String subPath) {
+ public Iterator<Resource> getChildren(final String parentPath, final String subPath) {
final Map<String, Object> childStructure = this.convertData();
if ( childStructure != null ) {
Map<String, Object> current = childStructure;
@@ -309,13 +308,6 @@ public class AttributeResource extends A
current = (Map<String, Object>)child;
}
}
- final Iterator<Map.Entry<String, Object>> removeIter = current.entrySet().iterator();
- while ( removeIter.hasNext() ) {
- final Map.Entry<String, Object> c = removeIter.next();
- if ( !(c.getValue() instanceof Map) ) {
- removeIter.remove();
- }
- }
if ( current.size() == 0 ) {
return null;
}
@@ -323,18 +315,33 @@ public class AttributeResource extends A
return new Iterator<Resource>() {
+ private Map.Entry<String, Object> next = this.seek();
+
+ private Map.Entry<String, Object> seek() {
+ while ( childIter.hasNext() ) {
+ final Map.Entry<String, Object> c = childIter.next();
+ if ( c.getValue() instanceof Map ) {
+ return c;
+ }
+ }
+ return null;
+ }
+
public void remove() {
throw new UnsupportedOperationException("remove");
}
public Resource next() {
- final Map.Entry<String, Object> props = childIter.next();
-
- return new MapResource(getResourceResolver(), getPath() + '/' + props.getKey(), (Map)props.getValue());
+ final Map.Entry<String, Object> props = next;
+ if ( props == null ) {
+ throw new NoSuchElementException();
+ }
+ next = seek();
+ return new MapResource(getResourceResolver(), parentPath + '/' + props.getKey(), (Map)props.getValue(), AttributeResource.this);
}
public boolean hasNext() {
- return childIter.hasNext();
+ return next != null;
}
};
}
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=1534947&r1=1534946&r2=1534947&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 Wed Oct 23 08:01:59 2013
@@ -309,7 +309,7 @@ public class JMXResourceProvider impleme
return new AttributeResource(parent.getResourceResolver(),
parent.getPath() + "/" + attr.getName(),
infoMap.get(attr.getName()),
- attr,
+ attr.getValue(),
parentResource);
}
@@ -318,7 +318,13 @@ public class JMXResourceProvider impleme
}
};
} else if ( info.pathInfo.startsWith("mbean:attributes/") ) {
- final AttributeResource parentResource = (AttributeResource)parent;
+ final AttributeResource parentResource;
+ if ( parent instanceof AttributeResource ) {
+ parentResource = (AttributeResource)parent;
+ } else {
+ parentResource = ((MapResource)parent).getAttributeResource();
+ }
+
final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
final int pos = attrPath.indexOf('/');
final String subPath;
@@ -328,7 +334,7 @@ public class JMXResourceProvider impleme
subPath = attrPath.substring(pos + 1);
}
- return parentResource.getChildren(subPath);
+ return parentResource.getChildren(parent.getPath(), subPath);
}
}
Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java?rev=1534947&r1=1534946&r2=1534947&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java (original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java Wed Oct 23 08:01:59 2013
@@ -38,7 +38,13 @@ public class MapResource extends Abstrac
private final ResourceMetadata metadata = new ResourceMetadata();
- public MapResource(final ResourceResolver resolver, final String path, final Map<String, Object> props) {
+ private final AttributeResource parent;
+
+ public MapResource(final ResourceResolver resolver,
+ final String path,
+ final Map<String, Object> props,
+ final AttributeResource parent) {
+ this.parent = parent;
this.resolver = resolver;
this.path = path;
this.properties = new HashMap<String, Object>();
@@ -49,6 +55,10 @@ public class MapResource extends Abstrac
}
}
+ public AttributeResource getAttributeResource() {
+ return this.parent;
+ }
+
/**
* @see org.apache.sling.api.resource.Resource#getPath()
*/