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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 35905050a8d CAMEL-21120: camel-groovy - Should clear cache when 
stopping to cleanup nicely. (#15337)
35905050a8d is described below

commit 35905050a8d21e678498191de1b276d3e0dc14d0
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Aug 27 18:42:38 2024 +0200

    CAMEL-21120: camel-groovy - Should clear cache when stopping to cleanup 
nicely. (#15337)
---
 .../apache/camel/language/groovy/GroovyLanguage.java    | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
 
b/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
index 77bf2ca8d42..da3014c585c 100644
--- 
a/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
+++ 
b/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
@@ -29,16 +29,18 @@ import org.apache.camel.spi.annotations.Language;
 import org.apache.camel.support.LRUCacheFactory;
 import org.apache.camel.support.ObjectHelper;
 import org.apache.camel.support.TypedLanguageSupport;
+import org.apache.camel.support.service.ServiceHelper;
 import org.codehaus.groovy.runtime.InvokerHelper;
 
 @Language("groovy")
-public class GroovyLanguage extends TypedLanguageSupport implements 
ScriptingLanguage {
+public class GroovyLanguage extends TypedLanguageSupport implements 
ScriptingLanguage, Service {
 
     /**
      * In case the expression is referring to an external resource, it 
indicates whether it is still needed to load the
      * resource.
      */
     private final boolean loadExternalResource;
+
     /**
      * Cache used to stores the compiled scripts (aka their classes)
      */
@@ -53,6 +55,17 @@ public class GroovyLanguage extends TypedLanguageSupport 
implements ScriptingLan
         this(LRUCacheFactory.newLRUSoftCache(16, 1000, true), true);
     }
 
+    @Override
+    public void start() {
+        // noop
+    }
+
+    @Override
+    public void stop() {
+        ServiceHelper.stopService(scriptCache.values());
+        scriptCache.clear();
+    }
+
     private static final class GroovyClassService implements Service {
 
         private final Class<Script> script;
@@ -111,11 +124,9 @@ public class GroovyLanguage extends TypedLanguageSupport 
implements ScriptingLan
 
     Class<Script> getScriptFromCache(String script) {
         final GroovyClassService cached = scriptCache.get(script);
-
         if (cached == null) {
             return null;
         }
-
         return cached.script;
     }
 

Reply via email to