Author: davsclaus
Date: Mon Jan 16 14:56:28 2012
New Revision: 1232013
URL: http://svn.apache.org/viewvc?rev=1232013&view=rev
Log:
CAMEL-4093: Changed thread name pattern tokens to not clash with property
placeholder tokens.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ThreadHelper.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelAggregateThreadPoolIssueTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
Mon Jan 16 14:56:28 2012
@@ -123,7 +123,7 @@ public class DefaultExecutorServiceManag
@Override
public void setThreadNamePattern(String threadNamePattern) {
// must set camel id here in the pattern and let the other
placeholders be resolved on demand
- String name = threadNamePattern.replaceFirst("\\$\\{camelId\\}",
this.camelContext.getName());
+ String name = threadNamePattern.replaceFirst("#camelId#",
this.camelContext.getName());
this.threadNamePattern = name;
}
@@ -282,7 +282,7 @@ public class DefaultExecutorServiceManag
protected void doStart() throws Exception {
if (threadNamePattern == null) {
// set default name pattern which includes the camel context name
- threadNamePattern = "Camel (" + camelContext.getName() + ") thread
#${counter} - ${name}";
+ threadNamePattern = "Camel (" + camelContext.getName() + ") thread
##counter# - #name#";
}
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java
Mon Jan 16 14:56:28 2012
@@ -101,12 +101,12 @@ public interface ExecutorServiceManager
/**
* Sets the thread name pattern used for creating the full thread name.
* <p/>
- * The default pattern is: <tt>Camel (${camelId}) thread #${counter} -
${name}</tt>
+ * The default pattern is: <tt>Camel (#camelId#) thread ##counter# -
#name#</tt>
* <p/>
- * Where <tt>${camelId}</tt> is the name of the {@link
org.apache.camel.CamelContext}
- * <br/>and <tt>${counter}</tt> is a unique incrementing counter.
- * <br/>and <tt>${name}</tt> is the regular thread name.
- * <br/>You can also use <tt>${longName}</tt> is the long thread name
which can includes endpoint parameters etc.
+ * Where <tt>#camelId#</tt> is the name of the {@link
org.apache.camel.CamelContext}
+ * <br/>and <tt>#counter#</tt> is a unique incrementing counter.
+ * <br/>and <tt>#name#</tt> is the regular thread name.
+ * <br/>You can also use <tt>#longName#</tt> is the long thread name which
can includes endpoint parameters etc.
*
* @param pattern the pattern
* @throws IllegalArgumentException if the pattern is invalid.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java
Mon Jan 16 14:56:28 2012
@@ -90,12 +90,12 @@ public interface ExecutorServiceStrategy
/**
* Sets the thread name pattern used for creating the full thread name.
* <p/>
- * The default pattern is: <tt>Camel (${camelId}) thread #${counter} -
${name}</tt>
+ * The default pattern is: <tt>Camel (#camelId#) thread #counter# -
#name#</tt>
* <p/>
- * Where <tt>${camelId}</tt> is the name of the {@link
org.apache.camel.CamelContext}
- * <br/>and <tt>${counter}</tt> is a unique incrementing counter.
- * <br/>and <tt>${name}</tt> is the regular thread name.
- * <br/>You can also use <tt>${longName}</tt> is the long thread name
which can includes endpoint parameters etc.
+ * Where <tt>#camelId#</tt> is the name of the {@link
org.apache.camel.CamelContext}
+ * <br/>and <tt>#counter#</tt> is a unique incrementing counter.
+ * <br/>and <tt>#name#</tt> is the regular thread name.
+ * <br/>You can also use <tt>#longName#</tt> is the long thread name which
can includes endpoint parameters etc.
*
* @param pattern the pattern
* @throws IllegalArgumentException if the pattern is invalid.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ThreadHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ThreadHelper.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ThreadHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ThreadHelper.java
Mon Jan 16 14:56:28 2012
@@ -17,6 +17,8 @@
package org.apache.camel.util.concurrent;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.camel.util.ObjectHelper;
@@ -24,8 +26,9 @@ import org.apache.camel.util.ObjectHelpe
* Various helper method for thread naming.
*/
public final class ThreadHelper {
- public static final String DEFAULT_PATTERN = "Camel Thread ${counter} -
${name}";
-
+ public static final String DEFAULT_PATTERN = "Camel Thread ##counter# -
#name#";
+ private static final Pattern INVALID_PATTERN =
Pattern.compile(".*#\\w+#.*");
+
private static AtomicLong threadCounter = new AtomicLong();
private ThreadHelper() {
@@ -37,6 +40,8 @@ public final class ThreadHelper {
/**
* Creates a new thread name with the given pattern
+ * <p/>
+ * See {@link
org.apache.camel.spi.ExecutorServiceManager#setThreadNamePattern(String)} for
supported patterns.
*
* @param pattern the pattern
* @param name the name
@@ -47,26 +52,23 @@ public final class ThreadHelper {
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
+ // 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);
+
+ // replace tokens
+ String answer = pattern.replaceFirst("#counter#", "" +
nextThreadCounter());
+ answer = answer.replaceFirst("#longName#", longName);
+ answer = answer.replaceFirst("#name#", shortName);
- 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) {
+ // 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);
}
- if (answer.indexOf("CAMEL_REPLACE_ME") > -1) {
- answer = answer.replaceAll("CAMEL_REPLACE_ME", "\\$");
- }
-
return answer;
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.java
Mon Jan 16 14:56:28 2012
@@ -42,8 +42,8 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPattern() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("#${counter}
- ${name}");
- assertEquals("#${counter} - ${name}",
context.getExecutorServiceManager().getThreadNamePattern());
+ context.getExecutorServiceManager().setThreadNamePattern("##counter# -
#name#");
+ assertEquals("##counter# - #name#",
context.getExecutorServiceManager().getThreadNamePattern());
String foo =
context.getExecutorServiceManager().resolveThreadName("foo");
String bar =
context.getExecutorServiceManager().resolveThreadName("bar");
@@ -55,7 +55,7 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPatternCamelId() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("#${camelId}
- #${counter} - ${name}");
+ context.getExecutorServiceManager().setThreadNamePattern("##camelId# -
##counter# - #name#");
String foo =
context.getExecutorServiceManager().resolveThreadName("foo");
String bar =
context.getExecutorServiceManager().resolveThreadName("bar");
@@ -67,14 +67,14 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPatternWithDollar() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("Hello -
${name}");
+ context.getExecutorServiceManager().setThreadNamePattern("Hello -
#name#");
String foo =
context.getExecutorServiceManager().resolveThreadName("foo$bar");
assertEquals("Hello - foo$bar", foo);
}
public void testGetThreadNameCustomPatternLongName() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("#${counter}
- ${longName}");
+ context.getExecutorServiceManager().setThreadNamePattern("##counter# -
#longName#");
String foo =
context.getExecutorServiceManager().resolveThreadName("foo?beer=Carlsberg");
String bar =
context.getExecutorServiceManager().resolveThreadName("bar");
@@ -86,7 +86,7 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPatternWithParameters() throws
Exception {
- context.getExecutorServiceManager().setThreadNamePattern("#${counter}
- ${name}");
+ context.getExecutorServiceManager().setThreadNamePattern("##counter# -
#name#");
String foo =
context.getExecutorServiceManager().resolveThreadName("foo?beer=Carlsberg");
String bar =
context.getExecutorServiceManager().resolveThreadName("bar");
@@ -98,7 +98,7 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPatternNoCounter() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("Cool
${name}");
+ context.getExecutorServiceManager().setThreadNamePattern("Cool
#name#");
String foo =
context.getExecutorServiceManager().resolveThreadName("foo");
String bar =
context.getExecutorServiceManager().resolveThreadName("bar");
@@ -108,16 +108,16 @@ public class DefaultExecutorServiceManag
}
public void testGetThreadNameCustomPatternInvalid() throws Exception {
- context.getExecutorServiceManager().setThreadNamePattern("Cool
${xxx}");
+ context.getExecutorServiceManager().setThreadNamePattern("Cool #xxx#");
try {
context.getExecutorServiceManager().resolveThreadName("foo");
fail("Should thrown an exception");
} catch (IllegalArgumentException e) {
- assertEquals("Pattern is invalid: Cool ${xxx}", e.getMessage());
+ assertEquals("Pattern is invalid: Cool #xxx#", e.getMessage());
}
// reset it so we can shutdown properly
- context.getExecutorServiceManager().setThreadNamePattern("Camel Thread
${counter} - ${name}");
+ context.getExecutorServiceManager().setThreadNamePattern("Camel Thread
#counter# - #name#");
}
public void testDefaultThreadPool() throws Exception {
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java
Mon Jan 16 14:56:28 2012
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ThreadPoolRejectedPolicy;
+import org.apache.camel.util.concurrent.ThreadHelper;
/**
* Unit test to ensure the {@link
org.apache.camel.spi.ExecutorServiceStrategy} still
@@ -44,7 +45,7 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPattern() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("#${counter}
- ${name}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("##counter#
- #name#");
String foo = context.getExecutorServiceStrategy().getThreadName("foo");
String bar = context.getExecutorServiceStrategy().getThreadName("bar");
@@ -56,7 +57,7 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPatternCamelId() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("#${camelId}
- #${counter} - ${name}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("##camelId#
- ##counter# - #name#");
String foo = context.getExecutorServiceStrategy().getThreadName("foo");
String bar = context.getExecutorServiceStrategy().getThreadName("bar");
@@ -68,14 +69,14 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPatternWithDollar() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("Hello -
${name}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("Hello -
#name#");
String foo =
context.getExecutorServiceStrategy().getThreadName("foo$bar");
assertEquals("Hello - foo$bar", foo);
}
public void testGetThreadNameCustomPatternLongName() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("#${counter}
- ${longName}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("##counter#
- #longName#");
String foo =
context.getExecutorServiceStrategy().getThreadName("foo?beer=Carlsberg");
String bar = context.getExecutorServiceStrategy().getThreadName("bar");
@@ -87,7 +88,7 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPatternWithParameters() throws
Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("#${counter}
- ${name}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("##counter#
- #name#");
String foo =
context.getExecutorServiceStrategy().getThreadName("foo?beer=Carlsberg");
String bar = context.getExecutorServiceStrategy().getThreadName("bar");
@@ -99,7 +100,7 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPatternNoCounter() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("Cool
${name}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("Cool
#name#");
String foo = context.getExecutorServiceStrategy().getThreadName("foo");
String bar = context.getExecutorServiceStrategy().getThreadName("bar");
@@ -109,16 +110,16 @@ public class DefaultExecutorServiceStrat
}
public void testGetThreadNameCustomPatternInvalid() throws Exception {
- context.getExecutorServiceStrategy().setThreadNamePattern("Cool
${xxx}");
+ context.getExecutorServiceStrategy().setThreadNamePattern("Cool
#xxx#");
try {
context.getExecutorServiceStrategy().getThreadName("foo");
fail("Should thrown an exception");
} catch (IllegalArgumentException e) {
- assertEquals("Pattern is invalid: Cool ${xxx}", e.getMessage());
+ assertEquals("Pattern is invalid: Cool #xxx#", e.getMessage());
}
// reset it so we can shutdown properly
- context.getExecutorServiceStrategy().setThreadNamePattern("Camel
Thread ${counter} - ${name}");
+
context.getExecutorServiceStrategy().setThreadNamePattern(ThreadHelper.DEFAULT_PATTERN);
}
public void testDefaultThreadPool() throws Exception {
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelAggregateThreadPoolIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelAggregateThreadPoolIssueTest.java?rev=1232013&r1=1232012&r2=1232013&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelAggregateThreadPoolIssueTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelAggregateThreadPoolIssueTest.java
Mon Jan 16 14:56:28 2012
@@ -52,7 +52,7 @@ public class RecipientListParallelAggreg
return new RouteBuilder() {
@Override
public void configure() throws Exception {
-
context.getExecutorServiceManager().setThreadNamePattern("${counter}");
+
context.getExecutorServiceManager().setThreadNamePattern("#counter#");
from("direct:start")
.recipientList(header("foo")).parallelProcessing();