camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1075001 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/component/properties/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/test/java/org/apache/camel/compon...
Date Sun, 27 Feb 2011 07:58:43 GMT
Author: davsclaus
Date: Sun Feb 27 07:58:42 2011
New Revision: 1075001

URL: http://svn.apache.org/viewvc?rev=1075001&view=rev
Log:
CAMEL-3722: ThreadPoolProfile and ThreadPool now accepts String types making them easy to
use with property placeholders.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java
  (contents, props changed)
      - copied, changed from r1074810, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml
      - copied, changed from r1074810, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/pool.properties
      - copied, changed from r1074810, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/route.properties
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadPoolProfileDefinition.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
    camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
    camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsExternalThreadPoolFactoryBeanTest.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java Sun
Feb 27 07:58:42 2011
@@ -17,11 +17,13 @@
 package org.apache.camel.builder;
 
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ThreadPoolRejectedPolicy;
 import org.apache.camel.model.ThreadPoolProfileDefinition;
+import org.apache.camel.util.CamelContextHelper;
 
 /**
  * A builder to create thread pools.
@@ -74,8 +76,9 @@ public final class ThreadPoolBuilder {
      *
      * @param name name which is appended to the thread name
      * @return the created thread pool
+     * @throws Exception is thrown if error building the thread pool
      */
-    public ExecutorService build(String name) {
+    public ExecutorService build(String name) throws Exception {
         return build(null, name);
     }
 
@@ -85,13 +88,18 @@ public final class ThreadPoolBuilder {
      * @param source the source object, usually it should be <tt>this</tt> passed
in as parameter
      * @param name   name which is appended to the thread name
      * @return the created thread pool
+     * @throws Exception is thrown if error building the thread pool
      */
-    public ExecutorService build(Object source, String name) {
-        ExecutorService answer = camelContext.getExecutorServiceStrategy().newThreadPool(source,
name,
-                threadPoolDefinition.getPoolSize(), threadPoolDefinition.getMaxPoolSize(),
-                threadPoolDefinition.getKeepAliveTime(), threadPoolDefinition.getTimeUnit(),
-                threadPoolDefinition.getMaxQueueSize(), threadPoolDefinition.getRejectedExecutionHandler(),
false);
+    public ExecutorService build(Object source, String name) throws Exception {
+        int size = CamelContextHelper.parseInteger(camelContext, threadPoolDefinition.getPoolSize());
+        int max = CamelContextHelper.parseInteger(camelContext, threadPoolDefinition.getMaxPoolSize());
+        long keepAlive = CamelContextHelper.parseLong(camelContext, threadPoolDefinition.getKeepAliveTime());
+        int queueSize = CamelContextHelper.parseInteger(camelContext, threadPoolDefinition.getMaxQueueSize());
+        TimeUnit unit = threadPoolDefinition.getTimeUnit();
+        RejectedExecutionHandler handler = threadPoolDefinition.getRejectedExecutionHandler();
 
+        ExecutorService answer = camelContext.getExecutorServiceStrategy().newThreadPool(source,
name,
+                size, max, keepAlive, unit, queueSize, handler, true);
         return answer;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
Sun Feb 27 07:58:42 2011
@@ -45,7 +45,7 @@ public class DefaultPropertiesParser imp
             // check the replaced with the visited to avoid circular reference
             for (String replace : replaced) {
                 if (visited.contains(replace)) {
-                    throw new IllegalArgumentException("Circular reference detected with
key [" + replace + "] in uri " + text);
+                    throw new IllegalArgumentException("Circular reference detected with
key [" + replace + "] from text: " + text);
                 }
             }
             // okay all okay so add the replaced as visited
@@ -78,13 +78,13 @@ public class DefaultPropertiesParser imp
                 pivot = idx + prefixToken.length();
                 int endIdx = uri.indexOf(suffixToken, pivot);
                 if (endIdx < 0) {
-                    throw new IllegalArgumentException("Expecting " + suffixToken + " but
found end of string for uri: " + uri);
+                    throw new IllegalArgumentException("Expecting " + suffixToken + " but
found end of string from text: " + uri);
                 }
                 String key = uri.substring(pivot, endIdx);
 
                 String part = createPlaceholderPart(key, properties, replaced);
                 if (part == null) {
-                    throw new IllegalArgumentException("Property with key [" + key + "] not
found in properties for uri: " + uri);
+                    throw new IllegalArgumentException("Property with key [" + key + "] not
found in properties from text: " + uri);
                 }
                 sb.append(part);
                 pivot = endIdx + suffixToken.length();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadPoolProfileDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadPoolProfileDefinition.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadPoolProfileDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThreadPoolProfileDefinition.java
Sun Feb 27 07:58:42 2011
@@ -24,9 +24,13 @@ import javax.xml.bind.annotation.XmlAttr
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ThreadPoolRejectedPolicy;
 import org.apache.camel.builder.xml.TimeUnitAdapter;
+import org.apache.camel.impl.ThreadPoolProfileSupport;
 import org.apache.camel.spi.ThreadPoolProfile;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Represents an XML &lt;threadPoolProfile/&gt; element
@@ -35,19 +39,19 @@ import org.apache.camel.spi.ThreadPoolPr
  */
 @XmlRootElement(name = "threadPoolProfile")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class ThreadPoolProfileDefinition extends OptionalIdentifiedDefinition implements
ThreadPoolProfile {
+public class ThreadPoolProfileDefinition extends OptionalIdentifiedDefinition {
     @XmlAttribute
     private Boolean defaultProfile;
     @XmlAttribute
-    private Integer poolSize;
+    private String poolSize;
     @XmlAttribute
-    private Integer maxPoolSize;
+    private String maxPoolSize;
     @XmlAttribute
-    private Long keepAliveTime;
+    private String keepAliveTime;
     @XmlJavaTypeAdapter(TimeUnitAdapter.class)
     private TimeUnit timeUnit;
     @XmlAttribute
-    private Integer maxQueueSize;
+    private String maxQueueSize;
     @XmlAttribute
     private ThreadPoolRejectedPolicy rejectedPolicy;
 
@@ -56,26 +60,38 @@ public class ThreadPoolProfileDefinition
 
     public ThreadPoolProfileDefinition(ThreadPoolProfile threadPoolProfile) {
         setDefaultProfile(threadPoolProfile.isDefaultProfile());
-        setPoolSize(threadPoolProfile.getPoolSize());
-        setMaxPoolSize(threadPoolProfile.getMaxPoolSize());
-        setKeepAliveTime(threadPoolProfile.getKeepAliveTime());
+        setPoolSize("" + threadPoolProfile.getPoolSize());
+        setMaxPoolSize("" + threadPoolProfile.getMaxPoolSize());
+        setKeepAliveTime("" + threadPoolProfile.getKeepAliveTime());
         setTimeUnit(threadPoolProfile.getTimeUnit());
-        setMaxQueueSize(threadPoolProfile.getMaxQueueSize());
+        setMaxQueueSize("" + threadPoolProfile.getMaxQueueSize());
         setRejectedPolicy(threadPoolProfile.getRejectedPolicy());
     }
 
     public ThreadPoolProfileDefinition poolSize(int poolSize) {
+        return poolSize("" + poolSize);
+    }
+
+    public ThreadPoolProfileDefinition poolSize(String poolSize) {
         setPoolSize(poolSize);
         return this;
     }
 
     public ThreadPoolProfileDefinition maxPoolSize(int maxPoolSize) {
-        setMaxPoolSize(maxPoolSize);
+        return maxPoolSize("" + maxQueueSize);
+    }
+
+    public ThreadPoolProfileDefinition maxPoolSize(String maxPoolSize) {
+        setMaxPoolSize("" + maxPoolSize);
         return this;
     }
 
     public ThreadPoolProfileDefinition keepAliveTime(long keepAliveTime) {
-        setKeepAliveTime(keepAliveTime);
+        return keepAliveTime("" + keepAliveTime);
+    }
+
+    public ThreadPoolProfileDefinition keepAliveTime(String keepAliveTime) {
+        setKeepAliveTime("" + keepAliveTime);
         return this;
     }
 
@@ -85,7 +101,11 @@ public class ThreadPoolProfileDefinition
     }
 
     public ThreadPoolProfileDefinition maxQueueSize(int maxQueueSize) {
-        setMaxQueueSize(maxQueueSize);
+        return maxQueueSize("" + maxQueueSize);
+    }
+
+    public ThreadPoolProfileDefinition maxQueueSize(String maxQueueSize) {
+        setMaxQueueSize("" + maxQueueSize);
         return this;
     }
 
@@ -106,44 +126,44 @@ public class ThreadPoolProfileDefinition
         return defaultProfile != null && defaultProfile;
     }
 
-    public Integer getPoolSize() {
+    public String getPoolSize() {
         return poolSize;
     }
 
-    public void setPoolSize(Integer poolSize) {
+    public void setPoolSize(String poolSize) {
         this.poolSize = poolSize;
     }
 
-    public Integer getMaxPoolSize() {
+    public String getMaxPoolSize() {
         return maxPoolSize;
     }
 
-    public void setMaxPoolSize(Integer maxPoolSize) {
+    public void setMaxPoolSize(String maxPoolSize) {
         this.maxPoolSize = maxPoolSize;
     }
 
-    public Long getKeepAliveTime() {
+    public String getKeepAliveTime() {
         return keepAliveTime;
     }
 
-    public void setKeepAliveTime(Long keepAliveTime) {
+    public void setKeepAliveTime(String keepAliveTime) {
         this.keepAliveTime = keepAliveTime;
     }
 
-    public TimeUnit getTimeUnit() {
-        return timeUnit;
+    public String getMaxQueueSize() {
+        return maxQueueSize;
     }
 
-    public void setTimeUnit(TimeUnit timeUnit) {
-        this.timeUnit = timeUnit;
+    public void setMaxQueueSize(String maxQueueSize) {
+        this.maxQueueSize = maxQueueSize;
     }
 
-    public Integer getMaxQueueSize() {
-        return maxQueueSize;
+    public TimeUnit getTimeUnit() {
+        return timeUnit;
     }
 
-    public void setMaxQueueSize(Integer maxQueueSize) {
-        this.maxQueueSize = maxQueueSize;
+    public void setTimeUnit(TimeUnit timeUnit) {
+        this.timeUnit = timeUnit;
     }
 
     public ThreadPoolRejectedPolicy getRejectedPolicy() {
@@ -160,4 +180,25 @@ public class ThreadPoolProfileDefinition
     public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
         this.rejectedPolicy = rejectedPolicy;
     }
+
+    /**
+     * Creates a {@link ThreadPoolProfile} instance based on this definition.
+     *
+     * @param context    the camel context
+     * @return           the profile
+     * @throws Exception is thrown if error creating the profile
+     */
+    public ThreadPoolProfile asThreadPoolProfile(CamelContext context) throws Exception {
+        ObjectHelper.notNull(context, "CamelContext", this);
+
+        ThreadPoolProfileSupport answer = new ThreadPoolProfileSupport(getId());
+        answer.setDefaultProfile(getDefaultProfile());
+        answer.setPoolSize(CamelContextHelper.parseInteger(context, getPoolSize()));
+        answer.setMaxPoolSize(CamelContextHelper.parseInteger(context, getMaxPoolSize()));
+        answer.setKeepAliveTime(CamelContextHelper.parseLong(context, getKeepAliveTime()));
+        answer.setMaxQueueSize(CamelContextHelper.parseInteger(context, getMaxQueueSize()));
+        answer.setRejectedPolicy(getRejectedPolicy());
+        answer.setTimeUnit(getTimeUnit());
+        return answer;
+    }
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/OptionalPropertiesDslInvalidSyntaxTest.java
Sun Feb 27 07:58:42 2011
@@ -40,7 +40,7 @@ public class OptionalPropertiesDslInvali
             fail("Should have thrown exception");
         } catch (FailedToCreateRouteException e) {
             IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class,
e.getCause());
-            assertEquals("Property with key [xxx] not found in properties for uri: {{xxx}}",
cause.getMessage());
+            assertEquals("Property with key [xxx] not found in properties from text: {{xxx}}",
cause.getMessage());
         }
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRegistryTest.java
Sun Feb 27 07:58:42 2011
@@ -78,7 +78,7 @@ public class PropertiesComponentRegistry
             fail("Should have thrown exception");
         } catch (RuntimeCamelException e) {
             IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class,
e.getCause());
-            assertEquals("Property with key [bean.unknown] not found in properties for uri:
{{bean.unknown}}", cause.getMessage());
+            assertEquals("Property with key [bean.unknown] not found in properties from text:
{{bean.unknown}}", cause.getMessage());
         }
     }
 
@@ -93,7 +93,7 @@ public class PropertiesComponentRegistry
             fail("Should have thrown exception");
         } catch (RuntimeCamelException e) {
             IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class,
e.getCause());
-            assertEquals("Property with key [bean.unknown] not found in properties for uri:
{{bean.unknown}}", cause.getMessage());
+            assertEquals("Property with key [bean.unknown] not found in properties from text:
{{bean.unknown}}", cause.getMessage());
         }
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
Sun Feb 27 07:58:42 2011
@@ -145,7 +145,7 @@ public class PropertiesComponentTest ext
         } catch (FailedToCreateRouteException e) {
             ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class,
e.getCause());
             IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class,
cause.getCause());
-            assertEquals("Property with key [foo.unknown] not found in properties for uri:
{{foo.unknown}}", iae.getMessage());
+            assertEquals("Property with key [foo.unknown] not found in properties from text:
{{foo.unknown}}", iae.getMessage());
         }
     }
 
@@ -162,7 +162,7 @@ public class PropertiesComponentTest ext
         } catch (FailedToCreateRouteException e) {
             ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class,
e.getCause());
             IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class,
cause.getCause());
-            assertEquals("Circular reference detected with key [cool.a] in uri {{cool.a}}",
iae.getMessage());
+            assertEquals("Circular reference detected with key [cool.a] from text: {{cool.a}}",
iae.getMessage());
         }
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/URISupportTest.java Sun Feb
27 07:58:42 2011
@@ -136,8 +136,6 @@ public class URISupportTest extends Cont
         map.put("bar", "123,456");
         map.put("name", "S\u00F8ren"); // danish letter
 
-        System.out.println(map.get("name"));
-
         // create new uri with the parameters
         URI out = URISupport.createRemainingURI(new URI(uri), map);
         assertNotNull(out);

Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
Sun Feb 27 07:58:42 2011
@@ -519,7 +519,7 @@ public abstract class AbstractCamelConte
         }
     }
 
-    protected void initThreadPoolProfiles(T context) {
+    protected void initThreadPoolProfiles(T context) throws Exception {
         Set<String> defaultIds = new HashSet<String>();
 
         // lookup and use custom profiles from the registry
@@ -543,10 +543,10 @@ public abstract class AbstractCamelConte
             for (ThreadPoolProfileDefinition profile : getThreadPoolProfiles()) {
                 if (profile.isDefaultProfile()) {
                     LOG.info("Using custom default ThreadPoolProfile with id: " + profile.getId()
+ " and implementation: " + profile);
-                    context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(profile);
+                    context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(profile.asThreadPoolProfile(context));
                     defaultIds.add(profile.getId());
                 } else {
-                    context.getExecutorServiceStrategy().registerThreadPoolProfile(profile);
+                    context.getExecutorServiceStrategy().registerThreadPoolProfile(profile.asThreadPoolProfile(context));
                 }
             }
         }

Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java
(original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java
Sun Feb 27 07:58:42 2011
@@ -27,6 +27,7 @@ import javax.xml.bind.annotation.adapter
 import org.apache.camel.CamelContext;
 import org.apache.camel.ThreadPoolRejectedPolicy;
 import org.apache.camel.builder.xml.TimeUnitAdapter;
+import org.apache.camel.util.CamelContextHelper;
 
 /**
  * A factory which instantiates {@link java.util.concurrent.ExecutorService} objects
@@ -37,36 +38,49 @@ import org.apache.camel.builder.xml.Time
 public abstract class AbstractCamelThreadPoolFactoryBean extends AbstractCamelFactoryBean<ExecutorService>
{
 
     @XmlAttribute(required = true)
-    private Integer poolSize;
+    private String poolSize;
     @XmlAttribute
-    private Integer maxPoolSize;
+    private String maxPoolSize;
     @XmlAttribute
-    private Long keepAliveTime = 60L;
+    private String keepAliveTime;
     @XmlAttribute
     @XmlJavaTypeAdapter(TimeUnitAdapter.class)
     private TimeUnit timeUnit = TimeUnit.SECONDS;
     @XmlAttribute
-    private Integer maxQueueSize = -1;
+    private String maxQueueSize;
     @XmlAttribute
     private ThreadPoolRejectedPolicy rejectedPolicy = ThreadPoolRejectedPolicy.CallerRuns;
     @XmlAttribute(required = true)
     private String threadName;
-    @XmlAttribute
-    private Boolean daemon = Boolean.TRUE;
 
     public ExecutorService getObject() throws Exception {
-        if (poolSize == null || poolSize <= 0) {
+        int size = CamelContextHelper.parseInteger(getCamelContext(), poolSize);
+        if (size <= 0) {
             throw new IllegalArgumentException("PoolSize must be a positive number");
         }
 
-        int max = getMaxPoolSize() != null ? getMaxPoolSize() : getPoolSize();
+        int max = size;
+        if (maxPoolSize != null) {
+            max = CamelContextHelper.parseInteger(getCamelContext(), maxPoolSize);
+        }
+
         RejectedExecutionHandler rejected = null;
         if (rejectedPolicy != null) {
             rejected = rejectedPolicy.asRejectedExecutionHandler();
         }
 
-        ExecutorService answer = getCamelContext().getExecutorServiceStrategy().newThreadPool(getId(),
getThreadName(), getPoolSize(), max,
-                    getKeepAliveTime(), getTimeUnit(), getMaxQueueSize(), rejected, isDaemon());
+        long keepAlive = 60;
+        if (keepAliveTime != null) {
+            keepAlive = CamelContextHelper.parseLong(getCamelContext(), keepAliveTime);
+        }
+
+        int queueSize = -1;
+        if (maxQueueSize != null) {
+            queueSize = CamelContextHelper.parseInteger(getCamelContext(), keepAliveTime);
+        }
+
+        ExecutorService answer = getCamelContext().getExecutorServiceStrategy().newThreadPool(getId(),
getThreadName(),
+                size, max, keepAlive, getTimeUnit(), queueSize, rejected, true);
         return answer;
     }
 
@@ -76,27 +90,27 @@ public abstract class AbstractCamelThrea
         return ExecutorService.class;
     }
 
-    public Integer getPoolSize() {
+    public String getPoolSize() {
         return poolSize;
     }
 
-    public void setPoolSize(Integer poolSize) {
+    public void setPoolSize(String poolSize) {
         this.poolSize = poolSize;
     }
 
-    public Integer getMaxPoolSize() {
+    public String getMaxPoolSize() {
         return maxPoolSize;
     }
 
-    public void setMaxPoolSize(Integer maxPoolSize) {
+    public void setMaxPoolSize(String maxPoolSize) {
         this.maxPoolSize = maxPoolSize;
     }
 
-    public Long getKeepAliveTime() {
+    public String getKeepAliveTime() {
         return keepAliveTime;
     }
 
-    public void setKeepAliveTime(Long keepAliveTime) {
+    public void setKeepAliveTime(String keepAliveTime) {
         this.keepAliveTime = keepAliveTime;
     }
 
@@ -108,11 +122,11 @@ public abstract class AbstractCamelThrea
         this.timeUnit = timeUnit;
     }
 
-    public Integer getMaxQueueSize() {
+    public String getMaxQueueSize() {
         return maxQueueSize;
     }
 
-    public void setMaxQueueSize(Integer maxQueueSize) {
+    public void setMaxQueueSize(String maxQueueSize) {
         this.maxQueueSize = maxQueueSize;
     }
 
@@ -132,12 +146,5 @@ public abstract class AbstractCamelThrea
         this.threadName = threadName;
     }
 
-    public Boolean isDaemon() {
-        return daemon;
-    }
-
-    public void setDaemon(Boolean daemon) {
-        this.daemon = daemon;
-    }
 
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java
(from r1074810, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.java&r1=1074810&r2=1075001&rev=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java
Sun Feb 27 07:58:42 2011
@@ -16,61 +16,13 @@
  */
 package org.apache.camel.spring.config;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ThreadPoolRejectedPolicy;
-import org.apache.camel.spi.ThreadPoolProfile;
-import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class SpringCamelContextThreadPoolProfilesTest extends SpringTestSupport {
+public class SpringCamelContextThreadPoolProfilesWithPlaceholderTest extends SpringCamelContextThreadPoolProfilesTest
{
 
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.xml");
-    }
-
-    public void testLowProfile() throws Exception {
-        CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
-
-        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getThreadPoolProfile("low");
-        assertEquals(1, profile.getPoolSize().intValue());
-        assertEquals(5, profile.getMaxPoolSize().intValue());
-        assertEquals(null, profile.getKeepAliveTime());
-        assertEquals(null, profile.getMaxQueueSize());
-        assertEquals(null, profile.getRejectedPolicy());
-
-        // create a thread pool from low
-        ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this,
"MyLow", "low");
-        ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
-        assertEquals(1, tp.getCorePoolSize());
-        assertEquals(5, tp.getMaximumPoolSize());
-        // should inherit default options
-        assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
-        assertIsInstanceOf(ThreadPoolExecutor.CallerRunsPolicy.class, tp.getRejectedExecutionHandler());
-    }
-
-    public void testBigProfile() throws Exception {
-        CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");
-
-        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getThreadPoolProfile("big");
-        assertEquals(50, profile.getPoolSize().intValue());
-        assertEquals(100, profile.getMaxPoolSize().intValue());
-        assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
-        assertEquals(null, profile.getKeepAliveTime());
-        assertEquals(null, profile.getMaxQueueSize());
-
-        // create a thread pool from big
-        ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this,
"MyBig", "big");
-        ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
-        assertEquals(50, tp.getCorePoolSize());
-        assertEquals(100, tp.getMaximumPoolSize());
-        // should inherit default options
-        assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
-        assertIsInstanceOf(ThreadPoolExecutor.DiscardOldestPolicy.class, tp.getRejectedExecutionHandler());
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml");
     }
 
 }
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml
(from r1074810, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.xml&r1=1074810&r2=1075001&rev=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/SpringCamelContextThreadPoolProfilesWithPlaceholderTest.xml
Sun Feb 27 07:58:42 2011
@@ -24,15 +24,17 @@
 
     <camelContext id="camel-C" xmlns="http://camel.apache.org/schema/spring">
 
+        <propertyPlaceholder id="properties" location="org/apache/camel/spring/config/pool.properties"/>
+
         <!-- define a low profile -->
         <threadPoolProfile id="low"
-                           poolSize="1"
-                           maxPoolSize="5"/>
+                           poolSize="{{low.min}}"
+                           maxPoolSize="{{low.max}}"/>
 
         <!-- define a big profile with many threads -->
         <threadPoolProfile id="big"
-                           poolSize="50"
-                           maxPoolSize="100" rejectedPolicy="DiscardOldest"/>
+                           poolSize="{{big.min}}"
+                           maxPoolSize="{{big.max}}" rejectedPolicy="DiscardOldest"/>
 
         <route>
             <from uri="direct:start"/>

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/pool.properties
(from r1074810, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/route.properties)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/pool.properties?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/pool.properties&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/route.properties&r1=1074810&r2=1075001&rev=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/route.properties
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/pool.properties
Sun Feb 27 07:58:42 2011
@@ -15,5 +15,8 @@
 ## limitations under the License.
 ## ------------------------------------------------------------------------
 
-cool.foo.startup=false
-cool.bar.startup=true
+low.min=1
+low.max=5
+
+big.min=50
+big.max=100
\ No newline at end of file

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsExternalThreadPoolFactoryBeanTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsExternalThreadPoolFactoryBeanTest.xml?rev=1075001&r1=1075000&r2=1075001&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsExternalThreadPoolFactoryBeanTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsExternalThreadPoolFactoryBeanTest.xml
Sun Feb 27 07:58:42 2011
@@ -32,7 +32,6 @@
                 keepAliveTime="30"
                 rejectedPolicy="DiscardOldest"
                 timeUnit="SECONDS"
-                daemon="true"
                 xmlns="http://camel.apache.org/schema/spring"/>
 
     <camelContext xmlns="http://camel.apache.org/schema/spring">



Mime
View raw message