Author: ningjiang
Date: Tue Jan 13 18:55:09 2009
New Revision: 734311

URL: http://svn.apache.org/viewvc?rev=734311&view=rev
Log:
Merged revisions 734309 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r734309 | ningjiang | 2009-01-14 10:44:56 +0800 (Wed, 14 Jan 2009) | 1 line
  
  CAMEL-1244 applied patch with thanks to Hari
........

Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    
activemq/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 13 18:55:09 2009
@@ -1 +1 @@
-/activemq/camel/trunk:732943,733749,734053,734057-734058,734064,734130
+/activemq/camel/trunk:732943,733749,734053,734057-734058,734064,734130,734309

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
activemq/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java?rev=734311&r1=734310&r2=734311&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
 Tue Jan 13 18:55:09 2009
@@ -28,6 +28,8 @@
 import org.apache.camel.spring.handler.CamelNamespaceHandler;
 import org.apache.camel.util.MainSupport;
 import org.apache.camel.view.ModelFileGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -65,10 +67,35 @@
         });
 
     }
+    
+    /**
+     * A class for intercepting the hang up signal and do a graceful shutdown 
of
+     * the Camel.
+     */
+    private class HangupInterceptor extends Thread {
+        Log log = LogFactory.getLog(this.getClass());
+        Main mainInstance;
+
+        public HangupInterceptor(Main main) {
+            mainInstance = main;
+        }
+
+        @Override
+        public void run() {
+            log.info("Recieved hang up - stopping the main instance.");
+            try {
+                mainInstance.stop();
+            } catch (Exception ex) {
+                log.warn(ex);
+            }
+        }
+    }
+
 
     public static void main(String... args) {
         Main main = new Main();
         instance = main;
+        main.enableHangupSupport();
         main.run(args);
     }
 
@@ -80,6 +107,15 @@
     public static Main getInstance() {
         return instance;
     }
+    
+    /**
+     * Enables the hangup support. Gracefully stops by calling stop() on a
+     * Hangup signal.
+     */
+    public void enableHangupSupport() {
+        HangupInterceptor interceptor = new HangupInterceptor(this);
+        Runtime.getRuntime().addShutdownHook(interceptor);
+    }
 
     @Override
     public void enableDebug() {


Reply via email to