You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by de...@apache.org on 2012/07/18 17:25:25 UTC

svn commit: r1362979 - in /activemq/trunk: activemq-console/src/main/java/org/apache/activemq/console/command/ activemq-core/src/main/java/org/apache/activemq/broker/ activemq-core/src/main/java/org/apache/activemq/xbean/

Author: dejanb
Date: Wed Jul 18 15:25:25 2012
New Revision: 1362979

URL: http://svn.apache.org/viewvc?rev=1362979&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3696 - make start() sync because of the tests and embedded brokers and introduce startAsync() to be used by XBean

Modified:
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java?rev=1362979&r1=1362978&r2=1362979&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java (original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/StartCommand.java Wed Jul 18 15:25:25 2012
@@ -116,7 +116,7 @@ public class StartCommand extends Abstra
         brokers.add(broker);
         broker.start();
         if (!broker.waitUntilStarted()) {
-            throw broker.getStartException();
+            throw new Exception(broker.getStartException());
         }
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1362979&r1=1362978&r2=1362979&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java Wed Jul 18 15:25:25 2012
@@ -223,7 +223,7 @@ public class BrokerService implements Se
 
     private final Object persistenceAdapterLock = new Object();
     private boolean persistenceAdapterStarted = false;
-    private Exception startException = null;
+    private Throwable startException = null;
 
     static {
         String localHostName = "localhost";
@@ -496,11 +496,19 @@ public class BrokerService implements Se
     @PostConstruct
     public void autoStart() throws Exception {
         if(shouldAutostart()) {
-            start();
+            startAsync();
         }
     }
 
     public void start() throws Exception {
+        doStart(false);
+    }
+
+    public void startAsync() throws Exception {
+        doStart(true);
+    }
+
+    public void doStart(boolean async) throws Exception {
         if (stopped.get() || !started.compareAndSet(false, true)) {
             // lets just ignore redundant start() calls
             // as its way too easy to not be completely sure if start() has been
@@ -521,8 +529,8 @@ public class BrokerService implements Se
                 startManagementContext();
             }
 
-            startPersistenceAdapter();
-            startBroker();
+            startPersistenceAdapter(async);
+            startBroker(async);
             startedLatch.countDown();
         } catch (Exception e) {
             LOG.error("Failed to start ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + "). Reason: " + e, e);
@@ -539,86 +547,103 @@ public class BrokerService implements Se
         }
     }
 
-    private void startPersistenceAdapter() throws Exception {
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    getPersistenceAdapter().setUsageManager(getProducerSystemUsage());
-                    getPersistenceAdapter().setBrokerName(getBrokerName());
-                    LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
-                    if (deleteAllMessagesOnStartup) {
-                        deleteAllMessages();
-                    }
-                    getPersistenceAdapter().start();
-                } catch (Exception e) {
-                    startException = e;
-                } finally {
-                    synchronized (persistenceAdapterLock) {
-                        persistenceAdapterLock.notifyAll();
+    private void startPersistenceAdapter(boolean async) throws Exception {
+        if (async) {
+            new Thread("Persistence Adapter Starting Thread") {
+                @Override
+                public void run() {
+                    try {
+                        doStartPersistenceAdapter();
+                    } catch (Throwable e) {
+                        startException = e;
+                    } finally {
+                        synchronized (persistenceAdapterLock) {
+                            persistenceAdapterLock.notifyAll();
+                        }
                     }
                 }
-            }
-        }.start();
+            }.start();
+        } else {
+            doStartPersistenceAdapter();
+        }
     }
 
-    private void startBroker() throws Exception {
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    synchronized (persistenceAdapterLock) {
-                        persistenceAdapterLock.wait();
-                    }
-                    if (startException != null) {
-                        return;
-                    }
-                    slave = false;
-                    startDestinations();
-                    addShutdownHook();
-                    getBroker().start();
-                    if (isUseJmx()) {
-                        if (getManagementContext().isCreateConnector() && !getManagementContext().isConnectorStarted()) {
-                            // try to restart management context
-                            // typical for slaves that use the same ports as master
-                            managementContext.stop();
-                            startManagementContext();
-                        }
-                        ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
-                        managedBroker.setContextBroker(broker);
-                        adminView.setBroker(managedBroker);
-                    }
-                    BrokerRegistry.getInstance().bind(getBrokerName(), BrokerService.this);
-                    // see if there is a MasterBroker service and if so, configure
-                    // it and start it.
-                    for (Service service : services) {
-                        if (service instanceof MasterConnector) {
-                            configureService(service);
-                            service.start();
-                        }
-                    }
-                    if (!isSlave() && (masterConnector == null || isShutdownOnMasterFailure() == false)) {
-                        startAllConnectors();
-                    }
-                    if (!stopped.get()) {
-                        if (isUseJmx() && masterConnector != null) {
-                            registerFTConnectorMBean(masterConnector);
+    private void doStartPersistenceAdapter() throws Exception {
+        getPersistenceAdapter().setUsageManager(getProducerSystemUsage());
+        getPersistenceAdapter().setBrokerName(getBrokerName());
+        LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
+        if (deleteAllMessagesOnStartup) {
+            deleteAllMessages();
+        }
+        getPersistenceAdapter().start();
+    }
+
+    private void startBroker(boolean async) throws Exception {
+        if (async) {
+            new Thread("Broker Starting Thread") {
+                @Override
+                public void run() {
+                    try {
+                        synchronized (persistenceAdapterLock) {
+                            persistenceAdapterLock.wait();
                         }
+                        doStartBroker();
+                    } catch (Throwable t) {
+                        startException = t;
                     }
-                    if (brokerId == null) {
-                        brokerId = broker.getBrokerId();
-                    }
-                    if (ioExceptionHandler == null) {
-                        setIoExceptionHandler(new DefaultIOExceptionHandler());
-                    }
-                    LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + ") started");
-                    getBroker().brokerServiceStarted();
-                    checkSystemUsageLimits();
-                } catch (Exception e) {
-                    startException = e;
                 }
+            }.start();
+        } else {
+            doStartBroker();
+        }
+    }
+
+    private void doStartBroker() throws Exception {
+
+        if (startException != null) {
+            return;
+        }
+        slave = false;
+        startDestinations();
+        addShutdownHook();
+        getBroker().start();
+        if (isUseJmx()) {
+            if (getManagementContext().isCreateConnector() && !getManagementContext().isConnectorStarted()) {
+                // try to restart management context
+                // typical for slaves that use the same ports as master
+                managementContext.stop();
+                startManagementContext();
+            }
+            ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
+            managedBroker.setContextBroker(broker);
+            adminView.setBroker(managedBroker);
+        }
+        BrokerRegistry.getInstance().bind(getBrokerName(), BrokerService.this);
+        // see if there is a MasterBroker service and if so, configure
+        // it and start it.
+        for (Service service : services) {
+            if (service instanceof MasterConnector) {
+                configureService(service);
+                service.start();
             }
-        }.start();
+        }
+        if (!isSlave() && (masterConnector == null || isShutdownOnMasterFailure() == false)) {
+            startAllConnectors();
+        }
+        if (!stopped.get()) {
+            if (isUseJmx() && masterConnector != null) {
+                registerFTConnectorMBean(masterConnector);
+            }
+        }
+        if (brokerId == null) {
+            brokerId = broker.getBrokerId();
+        }
+        if (ioExceptionHandler == null) {
+            setIoExceptionHandler(new DefaultIOExceptionHandler());
+        }
+        LOG.info("ActiveMQ JMS Message Broker (" + getBrokerName() + ", " + brokerId + ") started");
+        getBroker().brokerServiceStarted();
+        checkSystemUsageLimits();
     }
 
     /**
@@ -2762,7 +2787,7 @@ public class BrokerService implements Se
                 getVirtualTopicConsumerDestinationFilter().matches(destination);
     }
 
-    public Exception getStartException() {
+    public Throwable getStartException() {
         return startException;
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java?rev=1362979&r1=1362978&r2=1362979&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java Wed Jul 18 15:25:25 2012
@@ -57,7 +57,7 @@ public class XBeanBrokerService extends 
     public void afterPropertiesSet() throws Exception {
         ensureSystemUsageHasStore();
         if (shouldAutostart()) {
-            start();
+            startAsync();
         }
     }