From b3873fb3e45f1f74b77148bf64430ca0860a8266 Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Fri, 6 Nov 2009 13:56:28 +0000 Subject: [PATCH] https://issues.apache.org/activemq/browse/AMQ-2306 - jmx for slave brokers git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@833395 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/broker/BrokerService.java | 21 +++++++++++++++---- .../activemq/broker/jmx/BrokerView.java | 6 +++++- .../broker/jmx/ManagementContext.java | 6 +++++- 3 files changed, 27 insertions(+), 6 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 3bbc43649c..edfe74976d 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 @@ -440,6 +440,9 @@ public class BrokerService implements Service { }); } processHelperProperties(); + if (isUseJmx()) { + startManagementContext(); + } getPersistenceAdapter().setUsageManager(getProducerSystemUsage()); getPersistenceAdapter().setBrokerName(getBrokerName()); LOG.info("Using Persistence Adapter: " + getPersistenceAdapter()); @@ -451,12 +454,15 @@ public class BrokerService implements Service { addShutdownHook(); getBroker().start(); if (isUseJmx()) { - getManagementContext().start(); + if (!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 = new BrokerView(this, managedBroker); - ObjectName objectName = getBrokerObjectName(); - AnnotatedMBean.registerMBean(getManagementContext(), adminView, objectName); + adminView.setBroker(managedBroker); } BrokerRegistry.getInstance().bind(getBrokerName(), this); // see if there is a MasterBroker service and if so, configure @@ -1895,6 +1901,13 @@ public class BrokerService implements Service { protected void slaveConnectionEstablished() { slaveStartSignal.countDown(); } + + protected void startManagementContext() throws Exception { + getManagementContext().start(); + adminView = new BrokerView(this, null); + ObjectName objectName = getBrokerObjectName(); + AnnotatedMBean.registerMBean(getManagementContext(), adminView, objectName); + } /** * Start all transport and network connections, proxies and bridges diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index 9520ac60e3..1c655ee2be 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -43,7 +43,7 @@ import org.apache.activemq.network.NetworkConnector; */ public class BrokerView implements BrokerViewMBean { - final ManagedRegionBroker broker; + ManagedRegionBroker broker; private final BrokerService brokerService; private final AtomicInteger sessionIdCounter = new AtomicInteger(0); @@ -56,6 +56,10 @@ public class BrokerView implements BrokerViewMBean { return broker; } + public void setBroker(ManagedRegionBroker broker) { + this.broker = broker; + } + public String getBrokerId() { return broker.getBrokerId().toString(); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java index ca31868462..9a6827125f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java @@ -217,7 +217,11 @@ public class ManagementContext implements Service { return findTigerMbeanServer; } - /** + public boolean isConnectorStarted() { + return connectorServer.isActive(); + } + + /** * Enables/disables the searching for the Java 5 platform MBeanServer */ public void setFindTigerMbeanServer(boolean findTigerMbeanServer) {