Author: davsclaus
Date: Sat Dec 18 10:48:04 2010
New Revision: 1050612

URL: http://svn.apache.org/viewvc?rev=1050612&view=rev
Log:
CAMEL-3437: Improved naming for common thread pools used internally in Camel 
such as for producer template, error handlers, graceful shutdown etc.

Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java?rev=1050612&r1=1050611&r2=1050612&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
 Sat Dec 18 10:48:04 2010
@@ -361,7 +361,7 @@ public class DefaultExecutorServiceStrat
         // add to internal list of thread pools
         executorServices.add(executorService);
 
-        String id = null;
+        String id;
         String sourceId = null;
         String routeId = null;
 
@@ -372,8 +372,17 @@ public class DefaultExecutorServiceStrat
             sourceId = ((OptionalIdentifiedDefinition) source).getShortName();
         } else if (source instanceof String) {
             id = (String) source;
+        } else if (source != null) {
+            // fallback and use the simple class name with hashcode for the id 
so its unique for this given source
+            id = source.getClass().getSimpleName() + "(" + 
ObjectHelper.getIdentityHashCode(source) + ")";
+        } else {
+            // no source, so fallback and use the simple class name from 
thread pool and its hashcode identity so its unique
+            id = executorService.getClass().getSimpleName() + "(" + 
ObjectHelper.getIdentityHashCode(executorService) + ")";
         }
 
+        // id is mandatory
+        ObjectHelper.notEmpty(id, "id for thread pool " + executorService);
+
         // extract route id if possible
         if (source instanceof ProcessorDefinition) {
             RouteDefinition route = 
ProcessorDefinitionHelper.getRoute((ProcessorDefinition) source);

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java?rev=1050612&r1=1050611&r2=1050612&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
 Sat Dec 18 10:48:04 2010
@@ -254,19 +254,9 @@ public class DefaultManagementNamingStra
         buffer.append(domainName).append(":");
         buffer.append(KEY_CONTEXT + 
"=").append(getContextId(context)).append(",");
         buffer.append(KEY_TYPE + "=" + TYPE_THREAD_POOL + ",");
-        buffer.append(KEY_NAME + "=");
-        if (id == null) {
-            // if no id then use class name as id
-            buffer.append(threadPool.getClass().getSimpleName());
-        } else {
-            buffer.append(id);
-        }
-        if (id == null && sourceId == null) {
-            // if we don't really know the id or source id then use instance 
hashcode so the name is unique
-            // for this particular thread pool
-            
buffer.append("(").append(ObjectHelper.getIdentityHashCode(threadPool)).append(")");
-        } else if (sourceId != null) {
-            // provide source if we know it, this helps end user to know where 
the pool is used
+        buffer.append(KEY_NAME + "=").append(id);
+        if (sourceId != null) {
+            // provide source id if we know it, this helps end user to know 
where the pool is used
             buffer.append("(").append(sourceId).append(")");
         }
         return createObjectName(buffer);


Reply via email to