activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r609016 - /activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
Date Fri, 04 Jan 2008 21:38:44 GMT
Author: chirino
Date: Fri Jan  4 13:38:44 2008
New Revision: 609016

URL: http://svn.apache.org/viewvc?rev=609016&view=rev
Log:
Fix for http://issues.apache.org/activemq/browse/AMQ-1519
Start up the embeded broker in an async thread so that it does not block the AppServer startup
if a slave broker is started.

Modified:
    activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java

Modified: activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java?rev=609016&r1=609015&r2=609016&view=diff
==============================================================================
--- activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
(original)
+++ activemq/trunk/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
Fri Jan  4 13:38:44 2008
@@ -63,6 +63,7 @@
     private String brokerXmlConfig;
     private BrokerService broker;
     private ActiveMQConnectionFactory connectionFactory;
+    private Thread brokerStartThread;
 
     /**
      * 
@@ -77,12 +78,28 @@
     public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException
{
         this.bootstrapContext = bootstrapContext;
         if (brokerXmlConfig != null && brokerXmlConfig.trim().length() > 0) {
+            brokerStartThread = new Thread("Starting ActiveMQ Broker") {
+                public void run () {
+                    try {
+                        synchronized( ActiveMQResourceAdapter.this ) {
+                            broker = BrokerFactory.createBroker(new URI(brokerXmlConfig));
+                        }
+                        broker.start();
+                    } catch (Throwable e) {
+                        LOG.warn("Could not start up embeded ActiveMQ Broker '"+brokerXmlConfig+"':
"+e.getMessage());
+                        LOG.debug("Reason for: "+e.getMessage(), e);
+                    }
+                }
+            };
+            brokerStartThread.setDaemon(true);
+            brokerStartThread.start();
+            
+            // Wait up to 5 seconds for the broker to start up in the async thread.. otherwise
keep going without it..
             try {
-                broker = BrokerFactory.createBroker(new URI(brokerXmlConfig));
-                broker.start();
-            } catch (Throwable e) {
-                throw new ResourceAdapterInternalException("Failed to startup an embedded
broker: " + brokerXmlConfig + ", due to: " + e, e);
-            }
+                brokerStartThread.join(1000*5);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            }                
         }
     }
 
@@ -176,10 +193,17 @@
             ActiveMQEndpointActivationKey key = endpointWorkers.keySet().iterator().next();
             endpointDeactivation(key.getMessageEndpointFactory(), key.getActivationSpec());
         }
-        if (broker != null) {
-            ServiceSupport.dispose(broker);
-            broker = null;
+        
+        synchronized( this ) {
+            if (broker != null) {
+                if( brokerStartThread.isAlive() ) {
+                    brokerStartThread.interrupt();
+                }
+                ServiceSupport.dispose(broker);
+                broker = null;
+            }
         }
+        
         this.bootstrapContext = null;
     }
 



Mime
View raw message