sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1537059 - in /sling/trunk/bundles: scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/
Date Wed, 30 Oct 2013 12:01:34 GMT
Author: justin
Date: Wed Oct 30 12:01:34 2013
New Revision: 1537059

URL: http://svn.apache.org/r1537059
Log:
SLING-3216 - an event is now posted when a BVP is registered or unregistered which causes
the script cache to be cleared

Modified:
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/BindingsValuesProvidersByContextImpl.java
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ContextBvpCollector.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/BindingsValuesProvidersByContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/BindingsValuesProvidersByContextImpl.java?rev=1537059&r1=1537058&r2=1537059&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/BindingsValuesProvidersByContextImpl.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/BindingsValuesProvidersByContextImpl.java
Wed Oct 30 12:01:34 2013
@@ -23,9 +23,11 @@ import static org.apache.sling.scripting
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.script.ScriptEngineFactory;
 
@@ -33,14 +35,18 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.api.BindingsValuesProvider;
 import org.apache.sling.scripting.api.BindingsValuesProvidersByContext;
 import org.apache.sling.scripting.core.impl.helper.SlingScriptEngineManager;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
@@ -53,6 +59,10 @@ public class BindingsValuesProvidersByCo
 
     private final Map<String, ContextBvpCollector> customizers = new HashMap<String,
ContextBvpCollector>();
     public static final String [] DEFAULT_CONTEXT_ARRAY = new String [] { DEFAULT_CONTEXT
};
+
+    private static final String TOPIC_CREATED = "org/apache/sling/scripting/core/BindingsValuesProvider/CREATED";
+    private static final String TOPIC_MODIFIED = "org/apache/sling/scripting/core/BindingsValuesProvider/MODIFIED";
+    private static final String TOPIC_REMOVED = "org/apache/sling/scripting/core/BindingsValuesProvider/REMOVED";
     
     private ServiceTracker bvpTracker;
     private ServiceTracker mapsTracker;
@@ -62,7 +72,10 @@ public class BindingsValuesProvidersByCo
     
     @Reference
     private SlingScriptEngineManager scriptEngineManager;
-    
+
+    @Reference(policy = ReferencePolicy.DYNAMIC)
+    private EventAdmin eventAdmin;
+
     private abstract class ContextLoop {
         Object apply(ServiceReference ref) {
             final Object service = bundleContext.getService(ref);
@@ -150,11 +163,17 @@ public class BindingsValuesProvidersByCo
 
         return results;
     }
-    
+
     private String [] getContexts(ServiceReference reference) {
         return PropertiesUtil.toStringArray(reference.getProperty(CONTEXT), new String[]
{ DEFAULT_CONTEXT });
     }
 
+    private Event newEvent(final String topic, final ServiceReference reference) {
+        Dictionary<Object, Object> props = new Properties();
+        props.put("service.id", reference.getProperty(Constants.SERVICE_ID));
+        return new Event(topic, props);
+    }
+
     public Object addingService(final ServiceReference reference) {
         if(bundleContext == null) {
             synchronized (pendingRefs) {
@@ -166,6 +185,9 @@ public class BindingsValuesProvidersByCo
             @Override
             protected void applyInContext(ContextBvpCollector c) {
                 c.addingService(reference);
+                if (eventAdmin != null) {
+                    eventAdmin.postEvent(newEvent(TOPIC_CREATED, reference));
+                }
             }
         }.apply(reference);
     }
@@ -175,6 +197,9 @@ public class BindingsValuesProvidersByCo
             @Override
             protected void applyInContext(ContextBvpCollector c) {
                 c.modifiedService(reference, service);
+                if (eventAdmin != null) {
+                    eventAdmin.postEvent(newEvent(TOPIC_MODIFIED, reference));
+                }
             }
         }.apply(reference);
     }
@@ -190,6 +215,9 @@ public class BindingsValuesProvidersByCo
             @Override
             protected void applyInContext(ContextBvpCollector c) {
                 c.removedService(reference, service);
+                if (eventAdmin != null) {
+                    eventAdmin.postEvent(newEvent(TOPIC_REMOVED, reference));
+                }
             }
         }.apply(reference);
     }

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ContextBvpCollector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ContextBvpCollector.java?rev=1537059&r1=1537058&r2=1537059&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ContextBvpCollector.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ContextBvpCollector.java
Wed Oct 30 12:01:34 2013
@@ -92,9 +92,7 @@ class ContextBvpCollector {
         Object serviceId = ref.getProperty(Constants.SERVICE_ID);
         if (genericBindingsValuesProviders.remove(serviceId) == null) {
             for (Map<Object, BindingsValuesProvider> coll : langBindingsValuesProviders.values())
{
-                if (coll.remove(service) != null) {
-                    return;
-                }
+                coll.remove(serviceId);
             }
         }
     }

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java?rev=1537059&r1=1537058&r2=1537059&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
Wed Oct 30 12:01:34 2013
@@ -115,7 +115,8 @@ import org.slf4j.LoggerFactory;
          value={"org/apache/sling/api/resource/Resource/*",
                     "org/apache/sling/api/resource/ResourceProvider/*",
                     "javax/script/ScriptEngineFactory/*",
-                    "org/apache/sling/api/adapter/AdapterFactory/*"})
+                    "org/apache/sling/api/adapter/AdapterFactory/*",
+                    "org/apache/sling/scripting/core/BindingsValuesProvider/*"})
 })
 @Reference(name="Servlet", referenceInterface=javax.servlet.Servlet.class,
            cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
@@ -1079,6 +1080,9 @@ public class SlingServletResolver
                 // adapter factory added or removed: we always flush
                 // as adapting might be transitive
                 flushCache = true;
+            } else if (topic.startsWith("org/apache/sling/scripting/core/BindingsValuesProvider/"))
{
+                // bindings values provide factory added or removed: we always flush
+                flushCache = true;
             } else {
                 // this is a resource event
 



Mime
View raw message