Author: davsclaus
Date: Tue Sep 18 13:25:23 2012
New Revision: 1387142

URL: http://svn.apache.org/viewvc?rev=1387142&view=rev
Log:
Polished javadoc, and stop the producer template in main support if it was in 
use

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/main/MainSupport.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1387142&r1=1387141&r2=1387142&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Tue 
Sep 18 13:25:23 2012
@@ -687,6 +687,9 @@ public interface CamelContext extends Su
      * See this FAQ before use: <a 
href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html";>
      * Why does Camel use too many threads with ProducerTemplate?</a>
      * <p/>
+     * <b>Important:</b> Make sure to call {@link 
org.apache.camel.ProducerTemplate#stop()} when you are done using the template,
+     * to clean up any resources.
+     * <p/>
      * Will use cache size defined in Camel property with key {@link 
Exchange#MAXIMUM_CACHE_POOL_SIZE}.
      * If no key was defined then it will fallback to a default size of 1000.
      * You can also use the {@link 
org.apache.camel.ProducerTemplate#setMaximumCacheSize(int)} method to use a 
custom value
@@ -702,6 +705,9 @@ public interface CamelContext extends Su
      * <p/>
      * See this FAQ before use: <a 
href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html";>
      * Why does Camel use too many threads with ProducerTemplate?</a>
+     * <p/>
+     * <b>Important:</b> Make sure to call {@link ProducerTemplate#stop()} 
when you are done using the template,
+     * to clean up any resources.
      *
      * @param maximumCacheSize the maximum cache size
      * @return the template
@@ -715,6 +721,9 @@ public interface CamelContext extends Su
      * See this FAQ before use: <a 
href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html";>
      * Why does Camel use too many threads with ProducerTemplate?</a> as it 
also applies for ConsumerTemplate.
      * <p/>
+     * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} 
when you are done using the template,
+     * to clean up any resources.
+     * <p/>
      * Will use cache size defined in Camel property with key {@link 
Exchange#MAXIMUM_CACHE_POOL_SIZE}.
      * If no key was defined then it will fallback to a default size of 1000.
      * You can also use the {@link 
org.apache.camel.ConsumerTemplate#setMaximumCacheSize(int)} method to use a 
custom value
@@ -730,6 +739,9 @@ public interface CamelContext extends Su
      * <p/>
      * See this FAQ before use: <a 
href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html";>
      * Why does Camel use too many threads with ProducerTemplate?</a> as it 
also applies for ConsumerTemplate.
+     * <p/>
+     * <b>Important:</b> Make sure to call {@link ConsumerTemplate#stop()} 
when you are done using the template,
+     * to clean up any resources.
      *
      * @param maximumCacheSize the maximum cache size
      * @return the template

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/main/MainSupport.java?rev=1387142&r1=1387141&r2=1387142&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/main/MainSupport.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/main/MainSupport.java 
Tue Sep 18 13:25:23 2012
@@ -39,6 +39,7 @@ import org.apache.camel.model.ModelCamel
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
 import org.apache.camel.view.ModelFileGenerator;
 import org.apache.camel.view.RouteDotGenerator;
 import org.slf4j.Logger;
@@ -180,7 +181,14 @@ public abstract class MainSupport extend
      * Callback to run custom logic before CamelContext is being stopped
      */
     protected void beforeStop() {
-        // noop
+        if (camelTemplate != null) {
+            try {
+                ServiceHelper.stopService(camelTemplate);
+                camelTemplate = null;
+            } catch (Exception e) {
+                // ignore
+            }
+        }
     }
 
     /**
@@ -191,8 +199,6 @@ public abstract class MainSupport extend
         latch.countDown();
     }
 
-
-
     /**
      * Displays the command line options
      */


Reply via email to