From f1b6362dedeb6f55ae344478d1666598a8b1bfee Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Wed, 9 Apr 2008 09:45:22 +0000 Subject: [PATCH] Applied patch for https://issues.apache.org/activemq/browse/AMQ-1511 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@646245 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/broker/BrokerService.java | 36 +++++++++++++------ .../activemq/broker/ft/MasterConnector.java | 26 ++++++-------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java index 3ab8516ace..a174f3fc7a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -439,12 +439,17 @@ public class BrokerService implements Service { getBroker().start(); - /* - * if(isUseJmx()){ // yes - this is order dependent! // register all - * destination in persistence store including inactive destinations - * as mbeans this.startDestinationsInPersistenceStore(broker); } - */ - startAllConnectors(); + // 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()) { + startAllConnectors(); + } if (isUseJmx() && masterConnector != null) { registerFTConnectorMBean(masterConnector); @@ -1301,6 +1306,7 @@ public class BrokerService implements Service { * @throws Exception */ protected void processHelperProperties() throws Exception { + boolean masterServiceExists = false; if (transportConnectorURIs != null) { for (int i = 0; i < transportConnectorURIs.length; i++) { String uri = transportConnectorURIs[i]; @@ -1319,8 +1325,14 @@ public class BrokerService implements Service { addJmsConnector(jmsBridgeConnectors[i]); } } + for (Service service : services) { + if (service instanceof MasterConnector) { + masterServiceExists = true; + break; + } + } if (masterConnectorURI != null) { - if (masterConnector != null) { + if (masterServiceExists) { throw new IllegalStateException("Cannot specify masterConnectorURI when a masterConnector is already registered via the services property"); } else { addService(new MasterConnector(masterConnectorURI)); @@ -1843,12 +1855,14 @@ public class BrokerService implements Service { */ protected void configureService(Object service) { if (service instanceof BrokerServiceAware) { - BrokerServiceAware serviceAware = (BrokerServiceAware)service; + BrokerServiceAware serviceAware = (BrokerServiceAware) service; serviceAware.setBrokerService(this); } - if (service instanceof MasterConnector) { - masterConnector = (MasterConnector)service; - supportFailOver = true; + if (masterConnector == null) { + if (service instanceof MasterConnector) { + masterConnector = (MasterConnector) service; + supportFailOver = true; + } } } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java b/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java index edeb6ec5f5..265abe8ee4 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/ft/MasterConnector.java @@ -104,7 +104,7 @@ public class MasterConnector implements Service, BrokerServiceAware { } localBroker = TransportFactory.connect(localURI); remoteBroker = TransportFactory.connect(remoteURI); - LOG.info("Starting a network connection between " + localBroker + " and " + remoteBroker + " has been established."); + LOG.info("Starting a slave connection between " + localBroker + " and " + remoteBroker + " has been established."); localBroker.setTransportListener(new DefaultTransportListener() { public void onCommand(Object command) { @@ -131,21 +131,15 @@ public class MasterConnector implements Service, BrokerServiceAware { } } }); - masterActive.set(true); - Thread thead = new Thread() { - - public void run() { - try { - localBroker.start(); - remoteBroker.start(); - startBridge(); - } catch (Exception e) { - masterActive.set(false); - LOG.error("Failed to start network bridge: " + e, e); - } - } - }; - thead.start(); + try { + localBroker.start(); + remoteBroker.start(); + startBridge(); + masterActive.set(true); + } catch (Exception e) { + masterActive.set(false); + LOG.error("Failed to start network bridge: " + e, e); + } } protected void startBridge() throws Exception {