mirror of https://github.com/apache/activemq.git
added a helper method to make it easier to work with the admin view together with fixed some NPEs I was getting when redeploying ActiveMQ when using mvn jetty6:run
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@396892 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
73f0e97531
commit
8ad6fd36a1
|
@ -35,7 +35,6 @@ import org.apache.activemq.Service;
|
|||
import org.apache.activemq.advisory.AdvisoryBroker;
|
||||
import org.apache.activemq.broker.ft.MasterConnector;
|
||||
import org.apache.activemq.broker.jmx.BrokerView;
|
||||
import org.apache.activemq.broker.jmx.BrokerViewMBean;
|
||||
import org.apache.activemq.broker.jmx.ConnectorView;
|
||||
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
|
||||
import org.apache.activemq.broker.jmx.FTConnectorView;
|
||||
|
@ -96,6 +95,7 @@ public class BrokerService implements Service, Serializable {
|
|||
private String brokerName = "localhost";
|
||||
private File dataDirectory;
|
||||
private Broker broker;
|
||||
private BrokerView adminView;
|
||||
private ManagementContext managementContext;
|
||||
private ObjectName brokerObjectName;
|
||||
private TaskRunnerFactory taskRunnerFactory;
|
||||
|
@ -121,7 +121,6 @@ public class BrokerService implements Service, Serializable {
|
|||
private AtomicBoolean started = new AtomicBoolean(false);
|
||||
private BrokerPlugin[] plugins;
|
||||
private boolean keepDurableSubsActive=true;
|
||||
|
||||
private BrokerId brokerId;
|
||||
|
||||
/**
|
||||
|
@ -426,6 +425,7 @@ public class BrokerService implements Service, Serializable {
|
|||
|
||||
if (isUseJmx()) {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
for (Iterator iter = registeredMBeanNames.iterator(); iter.hasNext();) {
|
||||
ObjectName name = (ObjectName) iter.next();
|
||||
try {
|
||||
|
@ -435,6 +435,7 @@ public class BrokerService implements Service, Serializable {
|
|||
stopper.onException(mbeanServer, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
stopper.stop(getManagementContext());
|
||||
}
|
||||
|
||||
|
@ -445,6 +446,10 @@ public class BrokerService implements Service, Serializable {
|
|||
|
||||
// Properties
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the message broker
|
||||
*/
|
||||
public Broker getBroker() throws Exception {
|
||||
if (broker == null) {
|
||||
log.info("ActiveMQ " + ActiveMQConnectionMetaData.PROVIDER_VERSION + " JMS Message Broker ("
|
||||
|
@ -455,6 +460,24 @@ public class BrokerService implements Service, Serializable {
|
|||
return broker;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the administration view of the broker; used to create and destroy resources such as queues and topics.
|
||||
*
|
||||
* Note this method returns null if JMX is disabled.
|
||||
*/
|
||||
public BrokerView getAdminView() throws Exception {
|
||||
if (adminView == null) {
|
||||
// force lazy creation
|
||||
getBroker();
|
||||
}
|
||||
return adminView;
|
||||
}
|
||||
|
||||
public void setAdminView(BrokerView adminView) {
|
||||
this.adminView = adminView;
|
||||
}
|
||||
|
||||
public String getBrokerName() {
|
||||
return brokerName;
|
||||
}
|
||||
|
@ -774,6 +797,7 @@ public class BrokerService implements Service, Serializable {
|
|||
|
||||
protected void registerConnectorMBean(TransportConnector connector, ObjectName objectName) throws IOException, URISyntaxException {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
ConnectorViewMBean view = new ConnectorView(connector);
|
||||
try {
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
|
@ -783,17 +807,16 @@ public class BrokerService implements Service, Serializable {
|
|||
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
NetworkConnectorViewMBean view = new NetworkConnectorView(connector);
|
||||
try {
|
||||
ObjectName objectName = new ObjectName(
|
||||
managementContext.getJmxDomainName()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
|
||||
"Type=NetworkConnector,"+
|
||||
"NetworkConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
|
||||
);
|
||||
ObjectName objectName = new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=NetworkConnector," + "NetworkConnectorName="
|
||||
+ JMXSupport.encodeObjectNamePart(connector.getName()));
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
registeredMBeanNames.add(objectName);
|
||||
}
|
||||
|
@ -801,17 +824,16 @@ public class BrokerService implements Service, Serializable {
|
|||
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerProxyConnectorMBean(ProxyConnector connector) throws IOException {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
ProxyConnectorView view = new ProxyConnectorView(connector);
|
||||
try {
|
||||
ObjectName objectName = new ObjectName(
|
||||
managementContext.getJmxDomainName()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
|
||||
"Type=ProxyConnector,"+
|
||||
"ProxyConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
|
||||
);
|
||||
ObjectName objectName = new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=ProxyConnector," + "ProxyConnectorName="
|
||||
+ JMXSupport.encodeObjectNamePart(connector.getName()));
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
registeredMBeanNames.add(objectName);
|
||||
}
|
||||
|
@ -819,16 +841,15 @@ public class BrokerService implements Service, Serializable {
|
|||
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerFTConnectorMBean(MasterConnector connector) throws IOException {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
FTConnectorView view = new FTConnectorView(connector);
|
||||
try {
|
||||
ObjectName objectName = new ObjectName(
|
||||
managementContext.getJmxDomainName()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
|
||||
"Type=MasterConnector"
|
||||
);
|
||||
ObjectName objectName = new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=MasterConnector");
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
registeredMBeanNames.add(objectName);
|
||||
}
|
||||
|
@ -836,17 +857,16 @@ public class BrokerService implements Service, Serializable {
|
|||
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerJmsConnectorMBean(JmsConnector connector) throws IOException {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
JmsConnectorView view = new JmsConnectorView(connector);
|
||||
try {
|
||||
ObjectName objectName = new ObjectName(
|
||||
managementContext.getJmxDomainName()+":"+
|
||||
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
|
||||
"Type=JmsConnector,"+
|
||||
"JmsConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
|
||||
);
|
||||
ObjectName objectName = new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName="
|
||||
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=JmsConnector," + "JmsConnectorName="
|
||||
+ JMXSupport.encodeObjectNamePart(connector.getName()));
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
registeredMBeanNames.add(objectName);
|
||||
}
|
||||
|
@ -854,6 +874,7 @@ public class BrokerService implements Service, Serializable {
|
|||
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to create a new broker
|
||||
|
@ -882,12 +903,14 @@ public class BrokerService implements Service, Serializable {
|
|||
if (isUseJmx()) {
|
||||
ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
|
||||
managedBroker.setContextBroker(broker);
|
||||
BrokerViewMBean view = new BrokerView(this, managedBroker);
|
||||
adminView = new BrokerView(this, managedBroker);
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
if (mbeanServer != null) {
|
||||
ObjectName objectName = getBrokerObjectName();
|
||||
mbeanServer.registerMBean(view, objectName);
|
||||
mbeanServer.registerMBean(adminView, objectName);
|
||||
registeredMBeanNames.add(objectName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return broker;
|
||||
|
@ -908,8 +931,8 @@ public class BrokerService implements Service, Serializable {
|
|||
RegionBroker regionBroker = null;
|
||||
if (isUseJmx()) {
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
regionBroker = new ManagedRegionBroker(this,mbeanServer, getBrokerObjectName(),
|
||||
getTaskRunnerFactory(), getMemoryManager(), getPersistenceAdapter());
|
||||
regionBroker = new ManagedRegionBroker(this, mbeanServer, getBrokerObjectName(), getTaskRunnerFactory(), getMemoryManager(),
|
||||
getPersistenceAdapter());
|
||||
}
|
||||
else {
|
||||
regionBroker = new RegionBroker(this,getTaskRunnerFactory(), getMemoryManager(), getPersistenceAdapter());
|
||||
|
|
Loading…
Reference in New Issue