You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/12/16 14:06:05 UTC

svn commit: r1215114 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/spi/ test/java/org/apache/camel/impl/

Author: davsclaus
Date: Fri Dec 16 13:06:05 2011
New Revision: 1215114

URL: http://svn.apache.org/viewvc?rev=1215114&view=rev
Log:
Added missing newScheduledThreadPool using profile id

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceManager.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceManager.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceManagerTest.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=1215114&r1=1215113&r2=1215114&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 Fri Dec 16 13:06:05 2011
@@ -220,7 +220,17 @@ public class DefaultExecutorServiceManag
             LOG.debug("Created new ScheduledThreadPool for source: {} with name: {}. -> {}", new Object[]{source, sanitizedName, answer});
         }
         return answer;
+    }
 
+    @Override
+    public ScheduledExecutorService newScheduledThreadPool(Object source, String name, String profileId) {
+        ThreadPoolProfile profile = getThreadPoolProfile(profileId);
+        if (profile != null) {
+            return newScheduledThreadPool(source, name, profile);
+        } else {
+            // no profile with that id
+            return null;
+        }
     }
 
     @Override

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java?rev=1215114&r1=1215113&r2=1215114&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultThreadPoolFactory.java Fri Dec 16 13:06:05 2011
@@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -91,7 +92,20 @@ public class DefaultThreadPoolFactory im
     
     @Override
     public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
-        return Executors.newScheduledThreadPool(profile.getPoolSize(), threadFactory);
+        ScheduledThreadPoolExecutor answer = new ScheduledThreadPoolExecutor(profile.getPoolSize(), threadFactory);
+
+        // need to use setters to set the other values as we cannot use a constructor
+        // keep alive and maximum pool size have no effects on a scheduled thread pool as its
+        // a fixed size pool with an unbounded queue (see class javadoc)
+        // TODO: when JDK7 we should setRemoveOnCancelPolicy(true)
+
+        RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler();
+        if (rejectedExecutionHandler == null) {
+            rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
+        }
+        answer.setRejectedExecutionHandler(rejectedExecutionHandler);
+
+        return answer;
     }
 
 }

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=1215114&r1=1215113&r2=1215114&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 Fri Dec 16 13:06:05 2011
@@ -141,8 +141,8 @@ public interface ExecutorServiceManager 
     /**
      * Creates a new thread pool using the given profile
      *
-     * @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
+     * @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
      * @param profile the profile with the thread pool settings to use
      * @return the created thread pool
      */
@@ -151,8 +151,8 @@ public interface ExecutorServiceManager 
     /**
      * Creates a new thread pool using using the given profile id
      *
-     * @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
+     * @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
      * @param profileId the id of the profile with the thread pool settings to use
      * @return the created thread pool, or <tt>null</tt> if the thread pool profile could not be found
      */
@@ -223,15 +223,25 @@ public interface ExecutorServiceManager 
     
     /**
      * Creates a new scheduled thread pool using a profile
-     * 
-     * @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
-     * @param profile
+     *
+     * @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
+     * @param profile     the profile with the thread pool settings to use
      * @return created thread pool
      */
     ScheduledExecutorService newScheduledThreadPool(Object source, String name, ThreadPoolProfile profile);
 
     /**
+     * Creates a new scheduled thread pool using a profile id
+     *
+     * @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
+     * @param profileId   the id of the profile with the thread pool settings to use
+     * @return created thread pool
+     */
+    ScheduledExecutorService newScheduledThreadPool(Object source, String name, String profileId);
+
+    /**
      * Shutdown the given executor service.
      *
      * @param executorService the executor service to shutdown

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=1215114&r1=1215113&r2=1215114&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 Fri Dec 16 13:06:05 2011
@@ -430,4 +430,30 @@ public class DefaultExecutorServiceManag
         assertTrue(tp.isShutdown());
     }
 
+    public void testNewScheduledThreadPoolProfileById() throws Exception {
+        assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
+
+        ThreadPoolProfile foo = new ThreadPoolProfile("foo");
+        foo.setKeepAliveTime(20L);
+        foo.setMaxPoolSize(40);
+        foo.setPoolSize(5);
+        foo.setMaxQueueSize(2000);
+
+        context.getExecutorServiceManager().registerThreadPoolProfile(foo);
+
+        ExecutorService pool = context.getExecutorServiceManager().newScheduledThreadPool(this, "Cool", "foo");
+        assertNotNull(pool);
+
+        ScheduledThreadPoolExecutor tp = assertIsInstanceOf(ScheduledThreadPoolExecutor.class, pool);
+        // a scheduled dont use keep alive
+        assertEquals(0, tp.getKeepAliveTime(TimeUnit.SECONDS));
+        assertEquals(Integer.MAX_VALUE, tp.getMaximumPoolSize());
+        assertEquals(5, tp.getCorePoolSize());
+        assertFalse(tp.isShutdown());
+
+        context.stop();
+
+        assertTrue(tp.isShutdown());
+    }
+
 }