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 2012/01/19 06:46:04 UTC
svn commit: r1233187 - in /camel/branches/camel-2.8.x/camel-core/src:
main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java
test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java
Author: davsclaus
Date: Thu Jan 19 05:46:03 2012
New Revision: 1233187
URL: http://svn.apache.org/viewvc?rev=1233187&view=rev
Log:
CAMEL-4904: Fixed get thread name to support names with $ signs and other chars.
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java?rev=1233187&r1=1233186&r2=1233187&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java Thu Jan 19 05:46:03 2012
@@ -29,6 +29,8 @@ import java.util.concurrent.ThreadFactor
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.camel.model.ExecutorServiceAwareDefinition;
import org.apache.camel.spi.ExecutorServiceStrategy;
@@ -52,6 +54,7 @@ import org.slf4j.LoggerFactory;
public final class ExecutorServiceHelper {
public static final String DEFAULT_PATTERN = "Camel Thread ${counter} - ${name}";
+ private static final Pattern INVALID_PATTERN = Pattern.compile(".*\\$\\{\\w+\\}.*");
private static final Logger LOG = LoggerFactory.getLogger(ExecutorServiceHelper.class);
private static AtomicLong threadCounter = new AtomicLong();
@@ -74,24 +77,21 @@ public final class ExecutorServiceHelper
pattern = DEFAULT_PATTERN;
}
- // the name could potential have a $ sign we want to keep
- if (name.indexOf("$") > -1) {
- name = name.replaceAll("\\$", "CAMEL_REPLACE_ME");
- }
-
// we support ${longName} and ${name} as name placeholders
String longName = name;
String shortName = name.contains("?") ? ObjectHelper.before(name, "?") : name;
+ // must quote the names to have it work as literal replacement
+ shortName = Matcher.quoteReplacement(shortName);
+ longName = Matcher.quoteReplacement(longName);
+
String answer = pattern.replaceFirst("\\$\\{counter\\}", "" + nextThreadCounter());
answer = answer.replaceFirst("\\$\\{longName\\}", longName);
answer = answer.replaceFirst("\\$\\{name\\}", shortName);
- if (answer.indexOf("$") > -1 || answer.indexOf("${") > -1 || answer.indexOf("}") > -1) {
- throw new IllegalArgumentException("Pattern is invalid: " + pattern);
- }
- if (answer.indexOf("CAMEL_REPLACE_ME") > -1) {
- answer = answer.replaceAll("CAMEL_REPLACE_ME", "\\$");
+ // are there any ${word} combos left, if so they should be considered invalid tokens
+ if (INVALID_PATTERN.matcher(answer).matches()) {
+ throw new IllegalArgumentException("Pattern is invalid: " + pattern);
}
return answer;
Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java?rev=1233187&r1=1233186&r2=1233187&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/concurrent/ExecutorServiceHelperTest.java Thu Jan 19 05:46:03 2012
@@ -34,6 +34,13 @@ public class ExecutorServiceHelperTest e
assertTrue(name.endsWith("foo"));
}
+ public void testGetThreadNameWithDollar() {
+ String name = ExecutorServiceHelper.getThreadName("Camel Thread ${counter} - ${name}", "foo$bar");
+
+ assertTrue(name.startsWith("Camel Thread"));
+ assertTrue(name.endsWith("foo$bar"));
+ }
+
public void testNewScheduledThreadPool() {
ScheduledExecutorService pool = ExecutorServiceHelper.newScheduledThreadPool(1, "MyPool ${name}", "foo", true);
assertNotNull(pool);