You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ul...@apache.org on 2009/03/06 16:00:08 UTC

svn commit: r750932 - in /servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix: Main.java jbi/container/SpringJBIContainer.java jbi/nmr/flow/jca/JCAFlow.java

Author: ulhasbhole
Date: Fri Mar  6 15:00:07 2009
New Revision: 750932

URL: http://svn.apache.org/viewvc?rev=750932&view=rev
Log:
[SM-1821] ESB hangs on exit when destroyApplicationContextOnShutdown is set to true and the broker's persistent storage fails.

Modified:
    servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java
    servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java
    servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java

Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java?rev=750932&r1=750931&r2=750932&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java Fri Mar  6 15:00:07 2009
@@ -82,13 +82,7 @@
             //this is for classworlds 1.1 launcher which use System.exit() 
             //explicitly after lauch Main. To avoid System.exit() being invoked
             //during servicemix runing, we need keep ServiceMix main thread alive.
-            while (true) {
-                try {
-                    Thread.sleep(60000);
-                } catch (InterruptedException e) {
-                    //
-                }
-            }
+            container.block();
         } catch (Exception e) {
             System.out.println("Caught: " + e);
             e.printStackTrace();

Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java?rev=750932&r1=750931&r2=750932&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringJBIContainer.java Fri Mar  6 15:00:07 2009
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.Semaphore;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.Component;
@@ -59,6 +60,7 @@
     private String[] deployArchives;
     private DeploySupport[] deployments;
     private Runnable onShutDown;
+    private Semaphore block = new Semaphore(0);
     private Map components;
     private Map endpoints;
 
@@ -301,6 +303,7 @@
 
     public void destroy() throws Exception {
         super.shutDown();
+        block.release();
     }
 
     public void shutDown() throws JBIException {
@@ -313,6 +316,10 @@
         }
     }
 
+    public void block() throws InterruptedException {
+        block.acquire();
+    }
+
     /**
      * Set a {@link Runnable} which can handle the shutdown of the container
      * 

Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java?rev=750932&r1=750931&r2=750932&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java Fri Mar  6 15:00:07 2009
@@ -20,8 +20,12 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.Timer;
+import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jbi.JBIException;
@@ -88,6 +92,7 @@
 import org.jencks.SingletonEndpointFactory;
 import org.jencks.factory.ConnectionManagerFactoryBean;
 
+
 /**
  * Use for message routing among a network of containers. All
  * routing/registration happens automatically.
@@ -682,10 +687,22 @@
             ra.endpointActivation(endpointFactory, spec);
         }
 
-        public void stop() {
-            ra.endpointDeactivation(endpointFactory, spec);
-            ra.stop();
-            executor.shutdown();
+        public void stop() throws Exception {
+            
+            // In some cases these calls on the resource adapter can be blocked, causing
+            // servicemix to hang on shutdown.
+            FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
+                    public Void call() {
+                        ra.endpointDeactivation(endpointFactory, spec);
+                        ra.stop();
+                        executor.shutdown();
+                        return null;
+                    }
+                }
+            );
+            
+            Executors.newFixedThreadPool(1).execute(task);
+            task.get(500, TimeUnit.MILLISECONDS);
         }
     }