You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/11/30 14:36:39 UTC

[sling-org-apache-sling-scripting-core] branch issues/SLING-8141 created (now 542d831)

This is an automated email from the ASF dual-hosted git repository.

radu pushed a change to branch issues/SLING-8141
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git.


      at 542d831  SLING-8141 - ScriptCacheImpl throws IllegalStateException on deactivate

This branch includes the following new commits:

     new 542d831  SLING-8141 - ScriptCacheImpl throws IllegalStateException on deactivate

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-scripting-core] 01/01: SLING-8141 - ScriptCacheImpl throws IllegalStateException on deactivate

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issues/SLING-8141
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git

commit 542d8318db3842dc1df95738d842be8e7a82132c
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Nov 30 15:36:21 2018 +0100

    SLING-8141 - ScriptCacheImpl throws IllegalStateException on deactivate
    
    * synced deactivate and configureCache, called from handleEvent so that
    if an event occurs at the same time as a deactivate the unregister method
    of the ResourceChangeListener service registration is not called twice for
    the same registration
    * optimised cache reconfiguration when an event occurs
---
 .../sling/scripting/core/impl/ScriptCacheImpl.java | 77 ++++++++++++----------
 1 file changed, 41 insertions(+), 36 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java b/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
index 61a028d..67f5882 100644
--- a/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
+++ b/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
@@ -233,37 +233,39 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
                 resolver.close();
             }
         }
-
-        configureCache();
         active = true;
+        configureCache();
     }
 
     private void configureCache() {
         writeLock.lock();
         try {
-            if (resourceChangeListener != null) {
-                resourceChangeListener.unregister();
-                resourceChangeListener = null;
-            }
-            internalMap.clear();
-            if (additionalExtensions != null) {
-                extensions.addAll(Arrays.asList(additionalExtensions));
-            }
-            if (!extensions.isEmpty()) {
-                Set<String> globPatterns = new HashSet<>(extensions.size());
-                for (String extension : extensions) {
-                    globPatterns.add("glob:**/*." + extension);
+            if (active) {
+                if (resourceChangeListener != null) {
+                    resourceChangeListener.unregister();
+                    resourceChangeListener = null;
+                }
+                internalMap.clear();
+                if (additionalExtensions != null) {
+                    extensions.addAll(Arrays.asList(additionalExtensions));
+                }
+                if (!extensions.isEmpty()) {
+                    Set<String> globPatterns = new HashSet<>(extensions.size());
+                    for (String extension : extensions) {
+                        globPatterns.add("glob:**/*." + extension);
+                    }
+                    Dictionary<String, Object> resourceChangeListenerProperties = new Hashtable<>();
+                    resourceChangeListenerProperties
+                            .put(ResourceChangeListener.PATHS, globPatterns.toArray(new String[globPatterns.size()]));
+                    resourceChangeListenerProperties.put(ResourceChangeListener.CHANGES,
+                            new String[]{ResourceChange.ChangeType.CHANGED.name(), ResourceChange.ChangeType.REMOVED.name()});
+                    resourceChangeListener =
+                            bundleContext.registerService(
+                                    ResourceChangeListener.class,
+                                    this,
+                                    resourceChangeListenerProperties
+                            );
                 }
-                Dictionary<String, Object> resourceChangeListenerProperties = new Hashtable<>();
-                resourceChangeListenerProperties.put(ResourceChangeListener.PATHS, globPatterns.toArray(new String[globPatterns.size()]));
-                resourceChangeListenerProperties.put(ResourceChangeListener.CHANGES,
-                        new String[]{ResourceChange.ChangeType.CHANGED.name(), ResourceChange.ChangeType.REMOVED.name()});
-                resourceChangeListener =
-                        bundleContext.registerService(
-                                ResourceChangeListener.class,
-                                this,
-                                resourceChangeListenerProperties
-                        );
             }
         } finally {
             writeLock.unlock();
@@ -272,16 +274,21 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
 
     @Deactivate
     protected void deactivate() {
-        internalMap.clear();
-        if (resourceChangeListener != null) {
-            resourceChangeListener.unregister();
-            resourceChangeListener = null;
-        }
-        if (threadPool != null) {
-            threadPoolManager.release(threadPool);
-            threadPool = null;
+        writeLock.lock();
+        try {
+            internalMap.clear();
+            if (resourceChangeListener != null) {
+                resourceChangeListener.unregister();
+                resourceChangeListener = null;
+            }
+            if (threadPool != null) {
+                threadPoolManager.release(threadPool);
+                threadPool = null;
+            }
+            active = false;
+        } finally {
+            writeLock.unlock();
         }
-        active = false;
     }
 
     @Override
@@ -291,10 +298,8 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
             ScriptEngine scriptEngine = factory.getScriptEngine();
             if (scriptEngine instanceof Compilable) {
                 extensions.addAll(factory.getExtensions());
-                if (active) {
-                    configureCache();
-                }
             }
         }
+        configureCache();
     }
 }