Author: davsclaus
Date: Tue Mar 16 14:36:53 2010
New Revision: 923762

URL: http://svn.apache.org/viewvc?rev=923762&view=rev
Log:
CAMEL-1588: Configuring a custom default thread pool profile in Spring XML now 
possible.

Added:
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.java
      - copied, changed from r923718, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.java
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml
      - copied, changed from r923718, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.xml
Modified:
    
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsCoreAndMaxPoolKeepAliveTimeTest.xml

Modified: 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=923762&r1=923761&r2=923762&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
 Tue Mar 16 14:36:53 2010
@@ -55,6 +55,7 @@ import org.apache.camel.model.ProcessorD
 import org.apache.camel.model.RouteBuilderDefinition;
 import org.apache.camel.model.RouteContainer;
 import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ThreadPoolProfileDefinition;
 import org.apache.camel.model.ToDefinition;
 import org.apache.camel.model.TransactedDefinition;
 import org.apache.camel.model.config.PropertiesDefinition;
@@ -141,6 +142,8 @@ public class CamelContextFactoryBean ext
     private List beans;    
     @XmlElement(name = "routeBuilder", required = false)
     private List<RouteBuilderDefinition> builderRefs = new 
ArrayList<RouteBuilderDefinition>();
+    @XmlElement(name = "threadPoolProfile", required = false)
+    private List<ThreadPoolProfileDefinition> threadPoolProfiles;
     @XmlElement(name = "threadPool", required = false)
     private List<CamelThreadPoolFactoryBean> threadPools;
     @XmlElement(name = "endpoint", required = false)
@@ -318,23 +321,7 @@ public class CamelContextFactoryBean ext
         }
 
         // set the default thread pool profile if defined
-        Map<String, ThreadPoolProfile> threadPoolProfiles = 
getContext().getRegistry().lookupByType(ThreadPoolProfile.class);
-        if (threadPoolProfiles != null && !threadPoolProfiles.isEmpty()) {
-            Set<String> ids = new HashSet<String>();
-            for (String id : threadPoolProfiles.keySet()) {
-                ThreadPoolProfile profile = threadPoolProfiles.get(id);
-                // do not add if already added, for instance a tracer that is 
also an InterceptStrategy class
-                if (profile.isDefaultProfile()) {
-                    LOG.info("Using custom default ThreadPoolProfile with id: 
" + id + " and implementation: " + profile);
-                    
getContext().getExecutorServiceStrategy().setDefaultThreadPoolProfile(profile);
-                    ids.add(id);
-                }
-            }
-            // validate at most one is defined
-            if (ids.size() > 1) {
-                throw new IllegalArgumentException("Only exactly one default 
ThreadPoolProfile is allowed, was " + ids.size() + " ids: " + ids);
-            }
-        }
+        initDefaultThreadPoolProfile(getContext());
 
         // Set the application context and camelContext for the 
beanPostProcessor
         if (beanPostProcessor != null) {
@@ -949,6 +936,14 @@ public class CamelContextFactoryBean ext
         this.shutdownRunningTask = shutdownRunningTask;
     }
 
+    public List<ThreadPoolProfileDefinition> getThreadPoolProfiles() {
+        return threadPoolProfiles;
+    }
+
+    public void setThreadPoolProfiles(List<ThreadPoolProfileDefinition> 
threadPoolProfiles) {
+        this.threadPoolProfiles = threadPoolProfiles;
+    }
+
     // Implementation methods
     // 
-------------------------------------------------------------------------
 
@@ -964,7 +959,7 @@ public class CamelContextFactoryBean ext
     /**
      * Initializes the context
      * 
-     * @param ctx the contxt
+     * @param ctx the context
      * @throws Exception is thrown if error occurred
      */
     protected void initSpringCamelContext(SpringCamelContext ctx) throws 
Exception {
@@ -998,6 +993,40 @@ public class CamelContextFactoryBean ext
         return new SpringCamelContext(getApplicationContext());
     }
 
+    private void initDefaultThreadPoolProfile(CamelContext context) {
+        Set<String> ids = new HashSet<String>();
+
+        // lookup and use custom profiles from the registry
+        Map<String, ThreadPoolProfile> profiles = 
context.getRegistry().lookupByType(ThreadPoolProfile.class);
+        if (profiles != null && !profiles.isEmpty()) {
+            for (String id : profiles.keySet()) {
+                ThreadPoolProfile profile = profiles.get(id);
+                // do not add if already added, for instance a tracer that is 
also an InterceptStrategy class
+                if (profile.isDefaultProfile()) {
+                    LOG.info("Using custom default ThreadPoolProfile with id: 
" + id + " and implementation: " + profile);
+                    
context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(profile);
+                    ids.add(id);
+                }
+            }
+        }
+
+        // use custom profiles defined in the CamelContext
+        if (threadPoolProfiles != null && !threadPoolProfiles.isEmpty()) {
+            for (ThreadPoolProfileDefinition profile : threadPoolProfiles) {
+                if (profile.isDefaultProfile()) {
+                    LOG.info("Using custom default ThreadPoolProfile with id: 
" + profile.getId() + " and implementation: " + profile);
+                    
context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(profile);
+                    ids.add(profile.getId());
+                }
+            }
+        }
+
+        // validate at most one is defined
+        if (ids.size() > 1) {
+            throw new IllegalArgumentException("Only exactly one default 
ThreadPoolProfile is allowed, was " + ids.size() + " ids: " + ids);
+        }
+    }
+
     /**
      * Strategy to install all available routes into the context
      */

Modified: 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=923762&r1=923761&r2=923762&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
 Tue Mar 16 14:36:53 2010
@@ -231,6 +231,7 @@ public class CamelNamespaceHandler exten
                 }
                 builder.addPropertyValue("camelPropertyPlaceholder", 
factoryBean.getCamelPropertyPlaceholder());
                 builder.addPropertyValue("camelJMXAgent", 
factoryBean.getCamelJMXAgent());
+                builder.addPropertyValue("threadPoolProfiles", 
factoryBean.getThreadPoolProfiles());
             }
 
             boolean createdBeanPostProcessor = false;

Copied: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.java
 (from r923718, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.java&r1=923718&r2=923762&rev=923762&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.java
 Tue Mar 16 14:36:53 2010
@@ -23,10 +23,10 @@ import org.apache.camel.spring.SpringTes
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class SpringCamelContextCustomDefaultThreadPoolProfileTest extends 
SpringTestSupport {
+public class SpringCamelContextCustomThreadPoolProfileTest extends 
SpringTestSupport {
 
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.xml");
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml");
     }
 
     public void testDefaultThreadPoolProfile() throws Exception {

Copied: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml
 (from r923718, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.xml&r1=923718&r2=923762&rev=923762&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomDefaultThreadPoolProfileTest.xml
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextCustomThreadPoolProfileTest.xml
 Tue Mar 16 14:36:53 2010
@@ -22,22 +22,19 @@
        http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- define the default thread profile settings -->
-    <bean id="myDefaultThreadPoolProfile" 
class="org.apache.camel.impl.ThreadPoolProfileSupport">
-        <property name="defaultProfile" value="true"/>
-        <property name="poolSize" value="5"/>
-        <property name="maxPoolSize" value="15"/>
-        <property name="keepAliveTime" value="25"/>
-        <property name="maxQueueSize" value="250"/>
-        <property name="rejectedPolicy" value="Abort"/>
-    </bean>
-
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
+
+        <!-- define the default thread pool profile to be used in Camel -->
+        <threadPoolProfile id="myDefaultProfile"
+                           defaultProfile="true"
+                           poolSize="5" keepAliveTime="25" maxPoolSize="15" 
maxQueueSize="250" rejectedPolicy="Abort"/>
+
         <route>
             <from uri="direct:start"/>
             <threads/>
             <to uri="mock:result"/>
         </route>
+
     </camelContext>
 
 </beans>

Modified: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsCoreAndMaxPoolKeepAliveTimeTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsCoreAndMaxPoolKeepAliveTimeTest.xml?rev=923762&r1=923761&r2=923762&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsCoreAndMaxPoolKeepAliveTimeTest.xml
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsCoreAndMaxPoolKeepAliveTimeTest.xml
 Tue Mar 16 14:36:53 2010
@@ -25,7 +25,7 @@
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
         <route>
             <from uri="direct:start"/>
-            <threads poolSize="5" maxPoolSize="10" keepAliveTime="10" 
units="SECONDS">
+            <threads poolSize="5" maxPoolSize="10" keepAliveTime="10" 
timeUnit="SECONDS">
                 <to uri="mock:result"/>
             </threads>
         </route>


Reply via email to