You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/01/20 21:29:02 UTC
[1/3] camel git commit: CAMEL-10732 Remove from all caches when
Groovy ...
Repository: camel
Updated Branches:
refs/heads/camel-2.17.x 4b1aafcc5 -> ff9ee2a55
refs/heads/camel-2.18.x 2dae076dd -> d7e84ed09
refs/heads/master cfde7ee3e -> f05f319a2
CAMEL-10732 Remove from all caches when Groovy ...
...script is removed from Camel script cache
This commit wraps the `Class<Script>` in a `org.apache.camel.Service`
before placing it in the cache so that on removal from the cache `stop`
method would be invoked in which Groovy's `InvokerHelper` is used to
cleanup three other caches that still hold references to the Script
Class in question.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f05f319a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f05f319a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f05f319a
Branch: refs/heads/master
Commit: f05f319a29c4d3f8077e13877bb9b542ddd99b20
Parents: cfde7ee
Author: Zoran Regvart <zo...@regvart.com>
Authored: Fri Jan 20 20:34:51 2017 +0100
Committer: Zoran Regvart <zo...@regvart.com>
Committed: Fri Jan 20 20:34:51 2017 +0100
----------------------------------------------------------------------
.../camel/language/groovy/GroovyLanguage.java | 33 ++++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f05f319a/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
----------------------------------------------------------------------
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 a82cd0f..d9a8226 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
@@ -17,8 +17,10 @@
package org.apache.camel.language.groovy;
import groovy.lang.Script;
+import org.apache.camel.Service;
import org.apache.camel.support.LanguageSupport;
import org.apache.camel.util.LRUSoftCache;
+import org.codehaus.groovy.runtime.InvokerHelper;
/**
* @version
@@ -26,7 +28,26 @@ import org.apache.camel.util.LRUSoftCache;
public class GroovyLanguage extends LanguageSupport {
// Cache used to stores the compiled scripts (aka their classes)
- private final LRUSoftCache<String, Class<Script>> scriptCache = new LRUSoftCache<String, Class<Script>>(1000);
+ private final LRUSoftCache<String, GroovyClassService> scriptCache = new LRUSoftCache<String, GroovyClassService>(16, 1000, true);
+
+ private static final class GroovyClassService implements Service {
+
+ private final Class<Script> script;
+
+ private GroovyClassService(Class<Script> script) {
+ this.script = script;
+ }
+
+ @Override
+ public void start() throws Exception {
+ }
+
+ @Override
+ public void stop() throws Exception {
+ InvokerHelper.removeClass(script);
+ }
+
+ }
public static GroovyExpression groovy(String expression) {
return new GroovyLanguage().createExpression(expression);
@@ -42,11 +63,17 @@ public class GroovyLanguage extends LanguageSupport {
}
Class<Script> getScriptFromCache(String script) {
- return scriptCache.get(script);
+ final GroovyClassService cached = scriptCache.get(script);
+
+ if (cached == null) {
+ return null;
+ }
+
+ return cached.script;
}
void addScriptToCache(String script, Class<Script> scriptClass) {
- scriptCache.put(script, scriptClass);
+ scriptCache.put(script, new GroovyClassService(scriptClass));
}
}
[2/3] camel git commit: CAMEL-10732 Remove from all caches when
Groovy ...
Posted by da...@apache.org.
CAMEL-10732 Remove from all caches when Groovy ...
...script is removed from Camel script cache
This commit wraps the `Class<Script>` in a `org.apache.camel.Service`
before placing it in the cache so that on removal from the cache `stop`
method would be invoked in which Groovy's `InvokerHelper` is used to
cleanup three other caches that still hold references to the Script
Class in question.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d7e84ed0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d7e84ed0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d7e84ed0
Branch: refs/heads/camel-2.18.x
Commit: d7e84ed092721fc425f008b1e917df5ad7cf51db
Parents: 2dae076
Author: Zoran Regvart <zo...@regvart.com>
Authored: Fri Jan 20 20:34:51 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 20 22:27:19 2017 +0100
----------------------------------------------------------------------
.../camel/language/groovy/GroovyLanguage.java | 33 ++++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d7e84ed0/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
----------------------------------------------------------------------
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 a82cd0f..d9a8226 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
@@ -17,8 +17,10 @@
package org.apache.camel.language.groovy;
import groovy.lang.Script;
+import org.apache.camel.Service;
import org.apache.camel.support.LanguageSupport;
import org.apache.camel.util.LRUSoftCache;
+import org.codehaus.groovy.runtime.InvokerHelper;
/**
* @version
@@ -26,7 +28,26 @@ import org.apache.camel.util.LRUSoftCache;
public class GroovyLanguage extends LanguageSupport {
// Cache used to stores the compiled scripts (aka their classes)
- private final LRUSoftCache<String, Class<Script>> scriptCache = new LRUSoftCache<String, Class<Script>>(1000);
+ private final LRUSoftCache<String, GroovyClassService> scriptCache = new LRUSoftCache<String, GroovyClassService>(16, 1000, true);
+
+ private static final class GroovyClassService implements Service {
+
+ private final Class<Script> script;
+
+ private GroovyClassService(Class<Script> script) {
+ this.script = script;
+ }
+
+ @Override
+ public void start() throws Exception {
+ }
+
+ @Override
+ public void stop() throws Exception {
+ InvokerHelper.removeClass(script);
+ }
+
+ }
public static GroovyExpression groovy(String expression) {
return new GroovyLanguage().createExpression(expression);
@@ -42,11 +63,17 @@ public class GroovyLanguage extends LanguageSupport {
}
Class<Script> getScriptFromCache(String script) {
- return scriptCache.get(script);
+ final GroovyClassService cached = scriptCache.get(script);
+
+ if (cached == null) {
+ return null;
+ }
+
+ return cached.script;
}
void addScriptToCache(String script, Class<Script> scriptClass) {
- scriptCache.put(script, scriptClass);
+ scriptCache.put(script, new GroovyClassService(scriptClass));
}
}
[3/3] camel git commit: CAMEL-10732 Remove from all caches when
Groovy ...
Posted by da...@apache.org.
CAMEL-10732 Remove from all caches when Groovy ...
...script is removed from Camel script cache
This commit wraps the `Class<Script>` in a `org.apache.camel.Service`
before placing it in the cache so that on removal from the cache `stop`
method would be invoked in which Groovy's `InvokerHelper` is used to
cleanup three other caches that still hold references to the Script
Class in question.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ff9ee2a5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ff9ee2a5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ff9ee2a5
Branch: refs/heads/camel-2.17.x
Commit: ff9ee2a55f613f0a43011175170fad065a7a9bf6
Parents: 4b1aafc
Author: Zoran Regvart <zo...@regvart.com>
Authored: Fri Jan 20 20:34:51 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 20 22:27:38 2017 +0100
----------------------------------------------------------------------
.../camel/language/groovy/GroovyLanguage.java | 33 ++++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ff9ee2a5/components/camel-groovy/src/main/java/org/apache/camel/language/groovy/GroovyLanguage.java
----------------------------------------------------------------------
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 a82cd0f..d9a8226 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
@@ -17,8 +17,10 @@
package org.apache.camel.language.groovy;
import groovy.lang.Script;
+import org.apache.camel.Service;
import org.apache.camel.support.LanguageSupport;
import org.apache.camel.util.LRUSoftCache;
+import org.codehaus.groovy.runtime.InvokerHelper;
/**
* @version
@@ -26,7 +28,26 @@ import org.apache.camel.util.LRUSoftCache;
public class GroovyLanguage extends LanguageSupport {
// Cache used to stores the compiled scripts (aka their classes)
- private final LRUSoftCache<String, Class<Script>> scriptCache = new LRUSoftCache<String, Class<Script>>(1000);
+ private final LRUSoftCache<String, GroovyClassService> scriptCache = new LRUSoftCache<String, GroovyClassService>(16, 1000, true);
+
+ private static final class GroovyClassService implements Service {
+
+ private final Class<Script> script;
+
+ private GroovyClassService(Class<Script> script) {
+ this.script = script;
+ }
+
+ @Override
+ public void start() throws Exception {
+ }
+
+ @Override
+ public void stop() throws Exception {
+ InvokerHelper.removeClass(script);
+ }
+
+ }
public static GroovyExpression groovy(String expression) {
return new GroovyLanguage().createExpression(expression);
@@ -42,11 +63,17 @@ public class GroovyLanguage extends LanguageSupport {
}
Class<Script> getScriptFromCache(String script) {
- return scriptCache.get(script);
+ final GroovyClassService cached = scriptCache.get(script);
+
+ if (cached == null) {
+ return null;
+ }
+
+ return cached.script;
}
void addScriptToCache(String script, Class<Script> scriptClass) {
- scriptCache.put(script, scriptClass);
+ scriptCache.put(script, new GroovyClassService(scriptClass));
}
}