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 2010/03/12 12:14:25 UTC

svn commit: r922217 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/dataset/ camel-core/src/main/java/org/apache/camel/component/timer/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-jms/src/main/java/org/apache...

Author: davsclaus
Date: Fri Mar 12 11:14:24 2010
New Revision: 922217

URL: http://svn.apache.org/viewvc?rev=922217&view=rev
Log:
CAMEL-1588: DefaultComponent and DefaultEndpoint should not offer thread pool by default. Removed @deprecated methods from DefaultComponent.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java Fri Mar 12 11:14:24 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.dataset;
 
+import java.util.concurrent.ExecutorService;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
@@ -29,6 +31,7 @@ import org.apache.camel.processor.Throug
 public class DataSetConsumer extends DefaultConsumer {
     private DataSetEndpoint endpoint;
     private Processor reporter;
+    private ExecutorService executorService;
 
     public DataSetConsumer(DataSetEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -47,7 +50,10 @@ public class DataSetConsumer extends Def
 
         sendMessages(0, preloadSize);
 
-        endpoint.getExecutorService().execute(new Runnable() {
+        executorService = endpoint.getCamelContext().getExecutorServiceStrategy()
+                .newSingleThreadExecutor(this, endpoint.getEndpointUri());
+
+        executorService.execute(new Runnable() {
             public void run() {
                 if (endpoint.getInitialDelay() > 0) {
                     try {
@@ -63,6 +69,16 @@ public class DataSetConsumer extends Def
         });
     }
 
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        if (executorService != null) {
+            executorService.shutdown();
+            executorService = null;
+        }
+    }
+
     protected void sendMessages(long startIndex, long endIndex) {
         try {
             for (long i = startIndex; i < endIndex; i++) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java Fri Mar 12 11:14:24 2010
@@ -23,7 +23,6 @@ import java.util.TimerTask;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.util.ExchangeHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Fri Mar 12 11:14:24 2010
@@ -20,8 +20,6 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ScheduledExecutorService;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
@@ -44,9 +42,7 @@ import org.apache.commons.logging.LogFac
 public abstract class DefaultComponent extends ServiceSupport implements Component {
     private static final transient Log LOG = LogFactory.getLog(DefaultComponent.class);
 
-    private static final int DEFAULT_THREADPOOL_SIZE = 10;
     private CamelContext camelContext;
-    private ExecutorService executorService;
 
     public DefaultComponent() {
     }
@@ -170,44 +166,12 @@ public abstract class DefaultComponent e
         this.camelContext = context;
     }
 
-    public synchronized ExecutorService getExecutorService() {
-        if (executorService == null) {
-            executorService = createScheduledExecutorService();
-        }
-        return executorService;
-    }
-
-    public synchronized void setExecutorService(ExecutorService executorService) {
-        this.executorService = executorService;
-    }
-
-    public synchronized ScheduledExecutorService getScheduledExecutorService() {
-        ExecutorService executor = getExecutorService();
-        if (executor instanceof ScheduledExecutorService) {
-            return (ScheduledExecutorService) executor;
-        } else {
-            return createScheduledExecutorService();
-        }
-    }
-
-    /**
-     * A factory method to create a default thread pool and executor
-     */
-    protected ScheduledExecutorService createScheduledExecutorService() {
-        String name = getClass().getSimpleName();
-        return getCamelContext().getExecutorServiceStrategy().newScheduledThreadPool(this, name, DEFAULT_THREADPOOL_SIZE);
-    }
-
     protected void doStart() throws Exception {
         ObjectHelper.notNull(getCamelContext(), "camelContext");
     }
 
     protected void doStop() throws Exception {
-        if (executorService != null) {
-            executorService.shutdown();
-            // must null it so we can restart
-            executorService = null;
-        }
+        // noop
     }
 
     /**
@@ -244,79 +208,6 @@ public abstract class DefaultComponent e
         return true;
     }
 
-
-    // Some helper methods
-    //-------------------------------------------------------------------------
-
-    /**
-     * Converts the given value to the requested type
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public <T> T convertTo(Class<T> type, Object value) {
-        return CamelContextHelper.convertTo(getCamelContext(), type, value);
-    }
-
-    /**
-     * Converts the given value to the specified type throwing an {@link IllegalArgumentException}
-     * if the value could not be converted to a non null value
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public  <T> T mandatoryConvertTo(Class<T> type, Object value) {
-        return CamelContextHelper.mandatoryConvertTo(getCamelContext(), type, value);
-    }
-
-    /**
-     * Creates a new instance of the given type using the {@link org.apache.camel.spi.Injector} on the given
-     * {@link CamelContext}
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public  <T> T newInstance(Class<T> beanType) {
-        return getCamelContext().getInjector().newInstance(beanType);
-    }
-
-    /**
-     * Look up the given named bean in the {@link org.apache.camel.spi.Registry} on the
-     * {@link CamelContext}
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public Object lookup(String name) {
-        return getCamelContext().getRegistry().lookup(name);
-    }
-
-    /**
-     * Look up the given named bean of the given type in the {@link org.apache.camel.spi.Registry} on the
-     * {@link CamelContext}
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public <T> T lookup(String name, Class<T> beanType) {
-        return getCamelContext().getRegistry().lookup(name, beanType);
-    }
-
-    /**
-     * Look up the given named bean in the {@link org.apache.camel.spi.Registry} on the
-     * {@link CamelContext} or throws exception if not found.
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public Object mandatoryLookup(String name) {
-        return CamelContextHelper.mandatoryLookup(getCamelContext(), name);
-    }
-
-    /**
-     * Look up the given named bean of the given type in the {@link org.apache.camel.spi.Registry} on the
-     * {@link CamelContext} or throws exception if not found.
-     * @deprecated will be removed in Camel 2.3
-     */
-    @Deprecated
-    public <T> T mandatoryLookup(String name, Class<T> beanType) {
-        return CamelContextHelper.mandatoryLookup(getCamelContext(), name, beanType);
-    }
-
     /**
      * Gets the parameter and remove it from the parameter map. This method doesn't resolve
      * reference parameters in the registry.

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java Fri Mar 12 11:14:24 2010
@@ -119,29 +119,21 @@ public abstract class DefaultEndpoint im
         this.camelContext = camelContext;
     }
 
+    /**
+     * @deprecated will be removed in Camel 2.4
+     */
+    @Deprecated
     public synchronized ExecutorService getExecutorService() {
         if (executorService == null) {
-            Component c = getComponent();
-            if (c instanceof DefaultComponent) {
-                DefaultComponent dc = (DefaultComponent) c;
-                executorService = dc.getExecutorService();
-            }
-            if (executorService == null) {
-                executorService = createScheduledExecutorService();
-            }
+            executorService = createScheduledExecutorService();
         }
         return executorService;
     }
-    
-    public synchronized ScheduledExecutorService getScheduledExecutorService() {
-        ExecutorService executor = getExecutorService();
-        if (executor instanceof ScheduledExecutorService) {
-            return (ScheduledExecutorService) executor;
-        } else {
-            return createScheduledExecutorService();
-        }
-    }
 
+    /**
+     * @deprecated will be removed in Camel 2.4
+     */
+    @Deprecated
     public synchronized void setExecutorService(ExecutorService executorService) {
         this.executorService = executorService;
     }
@@ -195,6 +187,10 @@ public abstract class DefaultEndpoint im
         this.exchangePattern = exchangePattern;
     }
 
+    /**
+     * @deprecated will be removed in Camel 2.4
+     */
+    @Deprecated
     protected ScheduledExecutorService createScheduledExecutorService() {
         return getCamelContext().getExecutorServiceStrategy().newScheduledThreadPool(this, getEndpointUri(), DEFAULT_THREADPOOL_SIZE);
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java Fri Mar 12 11:14:24 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.impl;
 
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -52,16 +51,9 @@ public abstract class ScheduledPollConsu
     public ScheduledPollConsumer(DefaultEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
 
-        ScheduledExecutorService scheduled;
-        ExecutorService service = endpoint.getExecutorService();
-        if (service instanceof ScheduledExecutorService) {
-            scheduled = (ScheduledExecutorService) service;
-        } else {
-            scheduled = endpoint.getCamelContext().getExecutorServiceStrategy()
+        // TODO: this executor should also be shutdown when CamelContext stops
+        this.executor = endpoint.getCamelContext().getExecutorServiceStrategy()
                             .newScheduledThreadPool(this, getEndpoint().getEndpointUri(), DEFAULT_THREADPOOL_SIZE);
-        }
-
-        this.executor = scheduled;
         ObjectHelper.notNull(executor, "executor");
     }
 

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Fri Mar 12 11:14:24 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.component.jms;
 
 import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
 import javax.jms.ConnectionFactory;
 import javax.jms.ExceptionListener;
 import javax.jms.Session;
@@ -53,8 +54,10 @@ import static org.apache.camel.util.Obje
 public class JmsComponent extends DefaultComponent implements ApplicationContextAware, HeaderFilterStrategyAware {
 
     private static final transient Log LOG = LogFactory.getLog(JmsComponent.class);
+    private static final int DEFAULT_THREADPOOL_SIZE = 100;
     private static final String DEFAULT_QUEUE_BROWSE_STRATEGY = "org.apache.camel.component.jms.DefaultQueueBrowseStrategy";
     private static final String KEY_FORMAT_STRATEGY_PARAM = "jmsKeyFormatStrategy";
+    private ScheduledExecutorService scheduledExecutorService;
     private JmsConfiguration configuration;
     private ApplicationContext applicationContext;
     private Requestor requestor;
@@ -350,6 +353,18 @@ public class JmsComponent extends Defaul
         this.requestor = requestor;
     }
 
+    public synchronized ScheduledExecutorService getScheduledExecutorService() {
+        if (scheduledExecutorService == null) {
+            scheduledExecutorService = getCamelContext().getExecutorServiceStrategy()
+                    .newScheduledThreadPool(this, "JmsComponent", DEFAULT_THREADPOOL_SIZE);
+        }
+        return scheduledExecutorService;
+    }
+
+    public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
+        this.scheduledExecutorService = scheduledExecutorService;
+    }
+
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
         this.applicationContext = applicationContext;
     }

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?rev=922217&r1=922216&r2=922217&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java Fri Mar 12 11:14:24 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.jms;
 
+import java.util.concurrent.ScheduledExecutorService;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.ExceptionListener;
@@ -53,6 +54,9 @@ import org.springframework.transaction.P
  */
 @ManagedResource(description = "Managed JMS Endpoint")
 public class JmsEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware, ManagementAware<JmsEndpoint>, MultipleConsumersSupport {
+    private static final int DEFAULT_THREADPOOL_SIZE = 100;
+
+    private ScheduledExecutorService scheduledExecutorService;
     private HeaderFilterStrategy headerFilterStrategy;
     private boolean pubSubDomain;
     private JmsBinding binding;
@@ -296,6 +300,18 @@ public class JmsEndpoint extends Default
         this.requestor = requestor;
     }
 
+    public synchronized ScheduledExecutorService getScheduledExecutorService() {
+        if (scheduledExecutorService == null) {
+            scheduledExecutorService = getCamelContext().getExecutorServiceStrategy()
+                    .newScheduledThreadPool(this, getEndpointUri(), DEFAULT_THREADPOOL_SIZE);
+        }
+        return scheduledExecutorService;
+    }
+
+    public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
+        this.scheduledExecutorService = scheduledExecutorService;
+    }
+
     public boolean isPubSubDomain() {
         return pubSubDomain;
     }