incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1506139 - in /sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl: RulesMBeans.java RulesResourceParserImpl.java
Date Tue, 23 Jul 2013 16:09:21 GMT
Author: bdelacretaz
Date: Tue Jul 23 16:09:20 2013
New Revision: 1506139

URL: http://svn.apache.org/r1506139
Log:
SLING-2977 - scripted rules also work as MBeans now

Modified:
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java?rev=1506139&r1=1506138&r2=1506139&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesMBeans.java
Tue Jul 23 16:09:20 2013
@@ -64,6 +64,7 @@ public class RulesMBeans {
     private String rulesPath;
     private RulesEngine engine;
     private List<ServiceRegistration> mBeansRegistrations;
+    private ResourceResolver resolver;
     
     @Activate
     public void activate(ComponentContext ctx) throws Exception {
@@ -72,39 +73,34 @@ public class RulesMBeans {
             throw new IllegalStateException("rulesPath is null, cannot activate");
         }
         
-        final ResourceResolver resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
-        try {
-            final Resource rulesRoot = resolver.getResource(rulesPath);
-            if(rulesRoot == null) {
-                throw new IllegalStateException("Resource not found, cannot parse Rules:
" + rulesPath);
-            }
+        resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
+        final Resource rulesRoot = resolver.getResource(rulesPath);
+        if(rulesRoot == null) {
+            throw new IllegalStateException("Resource not found, cannot parse Rules: " +
rulesPath);
+        }
 
-            // Parse Rules found under our configured root
-            engine = healthcheck.getNewRulesEngine();
-            final List<Rule> rules = parser.parseResource(rulesRoot); 
-            engine.addRules(rules);
-            
-            // And register MBeans for those Rules
-            mBeansRegistrations = new ArrayList<ServiceRegistration>();
-            final String RESOURCE_PATH_PROP = "sling.resource.path";
-            for(Rule r : rules) {
-                final Object rulePath = r.getInfo().get(RESOURCE_PATH_PROP);
-                if(rulePath == null) {
-                    // TODO this happens with scripted rules
-                    log.warn("Rule {} does not have a {} property, ignored", r, RESOURCE_PATH_PROP);
-                    continue;
-                }
-                final Dictionary<String, String> mbeanProps = new Hashtable<String,
String>();
-                mbeanProps.put("jmx.objectname", "org.apache.sling.healthcheck:type=rules,service="
+ rulePath);
-                final RuleDynamicMBean mbean = new RuleDynamicMBean(r);
-                mBeansRegistrations.add(ctx.getBundleContext().registerService(DynamicMBean.class.getName(),
mbean, mbeanProps));
-                log.debug("Registered {} with properties {}", mbean, mbeanProps);
+        // Parse Rules found under our configured root
+        engine = healthcheck.getNewRulesEngine();
+        final List<Rule> rules = parser.parseResource(rulesRoot); 
+        engine.addRules(rules);
+        
+        // And register MBeans for those Rules
+        mBeansRegistrations = new ArrayList<ServiceRegistration>();
+        final String RESOURCE_PATH_PROP = "sling.resource.path";
+        for(Rule r : rules) {
+            final Object rulePath = r.getInfo().get(RESOURCE_PATH_PROP);
+            if(rulePath == null) {
+                // TODO this happens with scripted rules
+                log.warn("Rule {} does not have a {} property, ignored", r, RESOURCE_PATH_PROP);
+                continue;
             }
-            log.info("Registered {} Rule MBeans", mBeansRegistrations.size());
-            
-        } finally {
-            resolver.close();
+            final Dictionary<String, String> mbeanProps = new Hashtable<String,
String>();
+            mbeanProps.put("jmx.objectname", "org.apache.sling.healthcheck:type=rules,service="
+ rulePath);
+            final RuleDynamicMBean mbean = new RuleDynamicMBean(r);
+            mBeansRegistrations.add(ctx.getBundleContext().registerService(DynamicMBean.class.getName(),
mbean, mbeanProps));
+            log.debug("Registered {} with properties {}", mbean, mbeanProps);
         }
+        log.info("Registered {} Rule MBeans", mBeansRegistrations.size());
     }
     
     @Deactivate
@@ -114,5 +110,7 @@ public class RulesMBeans {
         }
         log.info("Unregistered {} Rule MBeans", mBeansRegistrations.size());
         mBeansRegistrations = null;
+        resolver.close();
+        resolver = null;
     }
 }

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java?rev=1506139&r1=1506138&r2=1506139&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
Tue Jul 23 16:09:20 2013
@@ -91,7 +91,9 @@ public class RulesResourceParserImpl imp
         // If r adapts to a Sling script, use it to evaluate our Rule
         final SlingScript script = r.adaptTo(SlingScript.class);
         if(script != null) {
-            return new Rule(new ScriptSystemAttribute(requestProcessor, script), ScriptSystemAttribute.SUCCESS_STRING);
+            final Rule rule = new Rule(new ScriptSystemAttribute(requestProcessor, script),
ScriptSystemAttribute.SUCCESS_STRING);
+            rule.getInfo().put(RESOURCE_PATH_INFO, r.getPath());
+            return rule;
         }
 
         // else convert using available RuleBuilders if suitable



Mime
View raw message