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 2009/07/02 12:00:38 UTC

svn commit: r790531 - /sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java

Author: cziegeler
Date: Thu Jul  2 10:00:37 2009
New Revision: 790531

URL: http://svn.apache.org/viewvc?rev=790531&view=rev
Log:
SLING-1027 : Flush cache when script engine factories come or go or when adapter factories come or go.

Modified:
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java

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=790531&r1=790530&r2=790531&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 Thu Jul  2 10:00:37 2009
@@ -97,7 +97,9 @@
  * @scr.service interface="ErrorHandler"
  * @scr.reference name="Servlet" interface="javax.servlet.Servlet"
  *                cardinality="0..n" policy="dynamic"
- * @scr.property name="event.topics" value="org/apache/sling/api/resource/*"
+ * @scr.property name="event.topics" values.1="org/apache/sling/api/resource/*"
+ *                                   values.2="javax/script/ScriptEngineFactory/*"
+ *                                   values.3="org/apache/sling/api/adapter/AdapterFactory/*"
  *               private="true"
  */
 public class SlingServletResolver implements ServletResolver,
@@ -769,17 +771,31 @@
      */
     public void handleEvent(Event event) {
         if ( this.cache != null ) {
-            // if the path of the event is a sub path of a search path
-            // we flush the whole cache
             boolean flushCache = false;
-            final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
-            final String[] searchPaths = this.scriptResolver.getSearchPath();
-            int index = 0;
-            while ( !flushCache && index < searchPaths.length ) {
-                if ( path.startsWith(searchPaths[index]) ) {
-                    flushCache = true;
+
+            // we may receive different events
+            final String topic = event.getTopic();
+            if ( topic.startsWith("javax/script/ScriptEngineFactory/") ) {
+                // script engine factory added or removed: we always flush
+                flushCache = true;
+            } else if ( topic.startsWith("org/apache/sling/api/adapter/AdapterFactory/") ) {
+                // adapter factory added or removed: we always flush
+                // as adapting might be transitive
+                flushCache = true;
+            } else {
+                // this is a resource event
+
+                // if the path of the event is a sub path of a search path
+                // we flush the whole cache
+                final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
+                final String[] searchPaths = this.scriptResolver.getSearchPath();
+                int index = 0;
+                while ( !flushCache && index < searchPaths.length ) {
+                    if ( path.startsWith(searchPaths[index]) ) {
+                        flushCache = true;
+                    }
+                    index++;
                 }
-                index++;
             }
             if ( flushCache ) {
                 this.cache.clear();