geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r945663 - in /geronimo/server/branches/2.2/plugins/activemq: activemq-broker/src/main/plan/plan.xml geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java
Date Tue, 18 May 2010 14:10:39 GMT
Author: kevan
Date: Tue May 18 14:10:39 2010
New Revision: 945663

URL: http://svn.apache.org/viewvc?rev=945663&view=rev
Log:
GERONIMO-5312 support asyncStartup of the ActiveMQ BrokerService. Use of asyncStartup (and
master-slave configuration) requires coordination with any client jms resources. mdb or outbound
connectors will need to use a failover or discovery protocol to insure they can connect to
an active broker (which may not be a broker running in the local process

Modified:
    geronimo/server/branches/2.2/plugins/activemq/activemq-broker/src/main/plan/plan.xml
    geronimo/server/branches/2.2/plugins/activemq/geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java

Modified: geronimo/server/branches/2.2/plugins/activemq/activemq-broker/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/activemq-broker/src/main/plan/plan.xml?rev=945663&r1=945662&r2=945663&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/activemq-broker/src/main/plan/plan.xml (original)
+++ geronimo/server/branches/2.2/plugins/activemq/activemq-broker/src/main/plan/plan.xml Tue
May 18 14:10:39 2010
@@ -28,6 +28,7 @@
         <attribute name="amqDataDir">data/default</attribute>
         <attribute name="amqConfigFile">conf/activemq.xml</attribute>
         <attribute name="useShutdownHook">false</attribute>
+        <attribute name="asyncStartup">false</attribute>
         <!--reference name="dataSource">
             <name>NoTxDatasource</name>
         </reference-->

Modified: geronimo/server/branches/2.2/plugins/activemq/geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/activemq/geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java?rev=945663&r1=945662&r2=945663&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/activemq/geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java
(original)
+++ geronimo/server/branches/2.2/plugins/activemq/geronimo-activemq/src/main/java/org/apache/geronimo/activemq/BrokerServiceGBeanImpl.java
Tue May 18 14:10:39 2010
@@ -19,6 +19,7 @@ package org.apache.geronimo.activemq;
 
 import java.io.File;
 import java.net.URI;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jms.JMSException;
 
@@ -52,21 +53,25 @@ public class BrokerServiceGBeanImpl impl
 
     private final String objectName;
     private final BrokerService brokerService;
-//    private ResourceSource<ResourceException> dataSource;
+    private final boolean asyncStartup;
+    private final AtomicBoolean active = new AtomicBoolean(false);
+    private Thread asyncStartThread;
     private JMSManager manager;
 
     public BrokerServiceGBeanImpl(@ParamAttribute (name="brokerName") String brokerName,
                                   @ParamAttribute (name="amqBaseDir") URI amqBaseDir, 
                                   @ParamAttribute (name="amqDataDir") String amqDataDir,

                                   @ParamAttribute (name="amqConfigFile") String amqConfigFile,

-                                  @ParamAttribute (name="useShutdownHook") boolean useShutdownHook,

-                                  @ParamReference (name="ServerInfo") ServerInfo serverInfo,

+                                  @ParamAttribute (name="useShutdownHook") boolean useShutdownHook,
+                                  @ParamAttribute (name="asyncStartup") boolean asyncStartup,
+                                  @ParamReference (name="ServerInfo") ServerInfo serverInfo,
                                   @ParamReference (name="MBeanServerReference") MBeanServerReference
mbeanServerReference,
                                   @ParamSpecial (type= SpecialAttributeType.objectName) String
objectName,
                                   @ParamSpecial (type=SpecialAttributeType.classLoader) ClassLoader
classLoader) 
         throws Exception {
         
         this.objectName = objectName;
+        this.asyncStartup = asyncStartup;
         URI baseDir = serverInfo.resolveServer(amqBaseDir);
         URI dataDir = baseDir.resolve(amqDataDir);
         URI amqConfigUri = baseDir.resolve(amqConfigFile);
@@ -96,12 +101,6 @@ public class BrokerServiceGBeanImpl impl
 
             // Do not allow the broker to use a shutdown hook, the kernel will stop it
             brokerService.setUseShutdownHook(useShutdownHook);
-
-            // Setup the persistence adapter to use the right datasource and directory
-//            DefaultPersistenceAdapterFactory persistenceFactory = (DefaultPersistenceAdapterFactory)
brokerService.getPersistenceFactory();
-//            persistenceFactory.setDataDirectoryFile(serverInfo.resolveServer(dataDirectory));
-//            persistenceFactory.setDataSource((DataSource) dataSource.getResource());  
         
-            brokerService.start();
         }
         finally {
             Thread.currentThread().setContextClassLoader(old);
@@ -117,35 +116,59 @@ public class BrokerServiceGBeanImpl impl
     }
 
     public synchronized void doStart() throws Exception {
-      
+        if (!asyncStartup) {
+            brokerService.start();
+        } else {
+            active.set(true);
+            asyncStartThread = new Thread(new Runnable() {
+                public void run() {
+                    asyncStart();
+                }
+            }, "AsyncStartThread-" + getBrokerName());
+            asyncStartThread.start();
+        }
     }
 
     public synchronized void doStop() throws Exception {
+        if (asyncStartup) {
+            active.set(false);
+        }
         brokerService.stop();
         brokerService.waitUntilStopped();
     }
 
     public synchronized void doFail() {
+        if (asyncStartup) {
+            active.set(false);
+        }        
+        try {
+            brokerService.stop();
+            brokerService.waitUntilStopped();
+        } catch (JMSException ignored) {
+            // just a lame exception ActiveMQ likes to throw on shutdown
+            if (!(ignored.getCause() instanceof TransportDisposedIOException)) {
+                log.warn("Caught while closing due to failure: " + ignored, ignored);
+            }
+        } catch (Exception e) {
+            log.warn("Caught while closing due to failure: " + e, e);
+        }
+    }
+
+    private void asyncStart() {
+        while (active.get()) {
             try {
-                brokerService.stop();
+                brokerService.start();
+                log.info("brokerService started");
                 brokerService.waitUntilStopped();
-            } catch (JMSException ignored) {
-                // just a lame exception ActiveMQ likes to throw on shutdown
-                if (!(ignored.getCause() instanceof TransportDisposedIOException)) {
-                    log.warn("Caught while closing due to failure: " + ignored, ignored);
+                if (active.get()) {
+                    log.warn("brokerService stopped");
                 }
             } catch (Exception e) {
-                log.warn("Caught while closing due to failure: " + e, e);
+                log.warn("brokerService start failed: " + e, e);
             }
         }
 
-//    public ResourceSource<ResourceException> getDataSource() {
-//        return dataSource;
-//    }
-//
-//    public void setDataSource(ResourceSource<ResourceException> dataSource) {
-//        this.dataSource = dataSource;
-//    }
+    }
 
     /**
      * Gets the unique name of this object.  The object name must comply with the ObjectName
specification



Mime
View raw message