This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch gstop in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0b58fa16826914c206fe9a0dcc2e7f12eeb7fbcf Author: Claus Ibsen <[email protected]> AuthorDate: Tue Aug 27 13:44:48 2024 +0200 CAMEL-21120: camel-groovy - Should clear cache when stopping to cleanup nicely. --- .../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; }
