camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1353248 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/test/java/org/apache/camel/builder/ components/camel-core-xml/src/main/java/org/apache/camel/core/xml/ components/camel-spring/src/test/java/org/a...
Date Sun, 24 Jun 2012 11:40:10 GMT
Author: davsclaus
Date: Sun Jun 24 11:40:09 2012
New Revision: 1353248

URL: http://svn.apache.org/viewvc?rev=1353248&view=rev
Log:
CAMEL-5386: ThreadPoolBuilder and <threadPool> can now create scheduled thread pools.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.java
      - copied, changed from r1353226, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThreadsThreadPoolFactoryBeanTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml
      - copied, changed from r1353226, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsThreadPoolFactoryBeanTest.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ThreadPoolBuilder.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ThreadPoolBuilderTest.java
    camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java

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=1353248&r1=1353247&r2=1353248&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
Jun 24 11:40:09 2012
@@ -17,6 +17,7 @@
 package org.apache.camel.builder;
 
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
@@ -103,4 +104,37 @@ public final class ThreadPoolBuilder {
         return context.getExecutorServiceManager().newThreadPool(source, name, profile);
     }
 
+    /**
+     * Builds the new scheduled thread pool
+     *
+     * @return the created scheduled thread pool
+     * @throws Exception is thrown if error building the scheduled thread pool
+     */
+    public ScheduledExecutorService buildScheduled() throws Exception {
+        return buildScheduled(null, null);
+    }
+
+    /**
+     * Builds the new scheduled thread pool
+     *
+     * @param name name which is appended to the thread name
+     * @return the created scheduled thread pool
+     * @throws Exception is thrown if error building the scheduled thread pool
+     */
+    public ScheduledExecutorService buildScheduled(String name) throws Exception {
+        return buildScheduled(null, name);
+    }
+
+    /**
+     * Builds the new scheduled thread pool
+     *
+     * @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 scheduled thread pool
+     * @throws Exception is thrown if error building the scheduled thread pool
+     */
+    public ScheduledExecutorService buildScheduled(Object source, String name) throws Exception
{
+        return context.getExecutorServiceManager().newScheduledThreadPool(source, name, profile);
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ThreadPoolBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ThreadPoolBuilderTest.java?rev=1353248&r1=1353247&r2=1353248&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ThreadPoolBuilderTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ThreadPoolBuilderTest.java
Sun Jun 24 11:40:09 2012
@@ -18,6 +18,7 @@ package org.apache.camel.builder;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
@@ -125,4 +126,39 @@ public class ThreadPoolBuilderTest exten
         assertEquals(true, executor2.isShutdown());
     }
 
+    public void testThreadPoolBuilderScheduled() throws Exception {
+        ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
+        ScheduledExecutorService executor = builder.poolSize(5).maxQueueSize(2000)
+                .buildScheduled();
+        assertNotNull(executor);
+
+        assertEquals(false, executor.isShutdown());
+        context.stop();
+        assertEquals(true, executor.isShutdown());
+    }
+
+    public void testThreadPoolBuilderScheduledName() throws Exception {
+        ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
+        ScheduledExecutorService executor = builder.poolSize(5).maxQueueSize(2000)
+                .buildScheduled("myScheduledPool");
+        assertNotNull(executor);
+
+        assertEquals(false, executor.isShutdown());
+        context.stop();
+        assertEquals(true, executor.isShutdown());
+    }
+
+
+    public void testThreadPoolBuilderScheduledSourceName() throws Exception {
+        ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
+        ScheduledExecutorService executor = builder.poolSize(5).maxQueueSize(2000)
+                .buildScheduled(this, "myScheduledPool");
+        assertNotNull(executor);
+
+        assertEquals(false, executor.isShutdown());
+        context.stop();
+        assertEquals(true, executor.isShutdown());
+    }
+
+
 }

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=1353248&r1=1353247&r2=1353248&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 Jun 24 11:40:09 2012
@@ -52,6 +52,8 @@ public abstract class AbstractCamelThrea
     private ThreadPoolRejectedPolicy rejectedPolicy = ThreadPoolRejectedPolicy.CallerRuns;
     @XmlAttribute(required = true)
     private String threadName;
+    @XmlAttribute
+    private Boolean scheduled;
 
     public ExecutorService getObject() throws Exception {
         int size = CamelContextHelper.parseInteger(getCamelContext(), poolSize);
@@ -81,7 +83,13 @@ public abstract class AbstractCamelThrea
                 .maxQueueSize(queueSize)
                 .rejectedPolicy(rejectedPolicy)
                 .build();
-        ExecutorService answer = getCamelContext().getExecutorServiceManager().newThreadPool(getId(),
getThreadName(), profile);
+
+        ExecutorService answer;
+        if (scheduled != null && scheduled) {
+            answer = getCamelContext().getExecutorServiceManager().newScheduledThreadPool(getId(),
getThreadName(), profile);
+        } else {
+            answer = getCamelContext().getExecutorServiceManager().newThreadPool(getId(),
getThreadName(), profile);
+        }
         return answer;
     }
 
@@ -145,4 +153,11 @@ public abstract class AbstractCamelThrea
         this.threadName = threadName;
     }
 
+    public Boolean getScheduled() {
+        return scheduled;
+    }
+
+    public void setScheduled(Boolean scheduled) {
+        this.scheduled = scheduled;
+    }
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.java
(from r1353226, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThreadsThreadPoolFactoryBeanTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThreadsThreadPoolFactoryBeanTest.java&r1=1353226&r2=1353248&rev=1353248&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringThreadsThreadPoolFactoryBeanTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.java
Sun Jun 24 11:40:09 2012
@@ -16,15 +16,24 @@
  */
 package org.apache.camel.spring.processor;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ThreadsDefaultTest;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.util.concurrent.SizedScheduledExecutorService;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+public class SpringScheduledThreadPoolTest extends SpringTestSupport {
 
-public class SpringThreadsThreadPoolFactoryBeanTest extends ThreadsDefaultTest {
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml");
+    }
+
+    public void testScheduledThreadPool() throws Exception {
+        SizedScheduledExecutorService pool = context.getRegistry().lookup("myPool", SizedScheduledExecutorService.class);
+        assertNotNull(pool);
 
-    protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/ThreadsThreadPoolFactoryBeanTest.xml");
+        assertFalse("Should be started", pool.isShutdown());
+        assertEquals(5, pool.getCorePoolSize());
     }
 
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml
(from r1353226, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsThreadPoolFactoryBeanTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsThreadPoolFactoryBeanTest.xml&r1=1353226&r2=1353248&rev=1353248&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ThreadsThreadPoolFactoryBeanTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringScheduledThreadPoolTest.xml
Sun Jun 24 11:40:09 2012
@@ -22,21 +22,11 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- START SNIPPET: e1 -->
     <camelContext xmlns="http://camel.apache.org/schema/spring">
 
-        <!-- define a custom thread pool -->
-        <threadPool id="myPool" poolSize="2" maxPoolSize="4" threadName="myPool"/>
+        <!-- define a custom scheduled thread pool -->
+        <threadPool id="myPool" poolSize="5" threadName="myPool" scheduled="true"/>
 
-        <route>
-            <from uri="direct:start"/>
-            <!-- use the custom thread pool in the camel route -->
-            <threads executorServiceRef="myPool">
-                <to uri="mock:result"/>
-            </threads>
-        </route>
-        
     </camelContext>
-    <!-- END SNIPPET: e1 -->
 
 </beans>



Mime
View raw message