git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1425871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2012-12-26 10:53:41 +00:00
parent 1f8306b861
commit c37859a80a
7 changed files with 106 additions and 117 deletions

View File

@ -1178,7 +1178,7 @@ public class BrokerService implements Service {
this.useJmx = useJmx;
}
public ObjectName getBrokerObjectName() throws IOException {
public ObjectName getBrokerObjectName() throws MalformedObjectNameException {
if (brokerObjectName == null) {
brokerObjectName = createBrokerObjectName();
}
@ -1998,9 +1998,9 @@ public class BrokerService implements Service {
}
private ObjectName createConnectorObjectName(TransportConnector connector) throws MalformedObjectNameException {
return new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=Connector," + "ConnectorName="
+ JMXSupport.encodeObjectNamePart(connector.getName()));
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",connector=clientConnectors,connectorName="+ JMXSupport.encodeObjectNamePart(connector.getName());
return new ObjectName(objectNameStr);
}
protected void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException {
@ -2016,17 +2016,17 @@ public class BrokerService implements Service {
protected ObjectName createNetworkConnectorObjectName(NetworkConnector connector)
throws MalformedObjectNameException {
return new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=NetworkConnector,"
+ "NetworkConnectorName=" + JMXSupport.encodeObjectNamePart(connector.getName()));
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",connector=networkConnectors,networkConnectorName="+ JMXSupport.encodeObjectNamePart(connector.getName());
return new ObjectName(objectNameStr);
}
public ObjectName createDuplexNetworkConnectorObjectName(String transport)
throws MalformedObjectNameException {
return new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=NetworkConnector,"
+ "NetworkConnectorName=duplex" + JMXSupport.encodeObjectNamePart(transport));
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",connector=duplexNetworkConnectors,networkConnectorName="+ JMXSupport.encodeObjectNamePart(transport);
return new ObjectName(objectNameStr);
}
protected void unregisterNetworkConnectorMBean(NetworkConnector connector) {
@ -2043,9 +2043,9 @@ public class BrokerService implements Service {
protected void registerProxyConnectorMBean(ProxyConnector connector) throws IOException {
ProxyConnectorView view = new ProxyConnectorView(connector);
try {
ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=ProxyConnector,"
+ "ProxyConnectorName=" + JMXSupport.encodeObjectNamePart(connector.getName()));
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",connector=proxyConnectors,proxyConnectorName="+ JMXSupport.encodeObjectNamePart(connector.getName());
ObjectName objectName = new ObjectName(objectNameStr);
AnnotatedMBean.registerMBean(getManagementContext(), view, objectName);
} catch (Throwable e) {
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
@ -2057,9 +2057,9 @@ public class BrokerService implements Service {
protected void registerJmsConnectorMBean(JmsConnector connector) throws IOException {
JmsConnectorView view = new JmsConnectorView(connector);
try {
ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=JmsConnector,"
+ "JmsConnectorName=" + JMXSupport.encodeObjectNamePart(connector.getName()));
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",connector=jmsConnectors,JmsConnectors="+ JMXSupport.encodeObjectNamePart(connector.getName());
ObjectName objectName = new ObjectName(objectNameStr);
AnnotatedMBean.registerMBean(getManagementContext(), view, objectName);
} catch (Throwable e) {
throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(), e);
@ -2123,8 +2123,13 @@ public class BrokerService implements Service {
protected Broker createRegionBroker(DestinationInterceptor destinationInterceptor) throws IOException {
RegionBroker regionBroker;
if (isUseJmx()) {
try {
regionBroker = new ManagedRegionBroker(this, getManagementContext(), getBrokerObjectName(),
getTaskRunnerFactory(), getConsumerSystemUsage(), destinationFactory, destinationInterceptor,getScheduler(),getExecutor());
}catch(MalformedObjectNameException me){
LOG.error("Couldn't create ManagedRegionBroker",me);
throw new IOException(me);
}
} else {
regionBroker = new RegionBroker(this, getTaskRunnerFactory(), getConsumerSystemUsage(), destinationFactory,
destinationInterceptor,getScheduler(),getExecutor());
@ -2173,10 +2178,10 @@ public class BrokerService implements Service {
if (isUseJmx()) {
JobSchedulerViewMBean view = new JobSchedulerView(sb.getJobScheduler());
try {
ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":"
+ "BrokerName=" + JMXSupport.encodeObjectNamePart(getBrokerName()) + ","
+ "Type=jobScheduler," + "jobSchedulerName=JMS");
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",service=JobScheduler,name=JMS";
ObjectName objectName = new ObjectName(objectNameStr);
AnnotatedMBean.registerMBean(getManagementContext(), view, objectName);
this.adminView.setJMSJobScheduler(objectName);
} catch (Throwable e) {
@ -2190,10 +2195,9 @@ public class BrokerService implements Service {
if (isUseJmx()) {
HealthViewMBean statusView = new HealthView((ManagedRegionBroker)getRegionBroker());
try {
ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":"
+ "BrokerName=" + JMXSupport.encodeObjectNamePart(getBrokerName()) + ","
+ "Type=Health");
String objectNameStr = getBrokerObjectName().toString();
objectNameStr += ",service=Health";
ObjectName objectName = new ObjectName(objectNameStr);
AnnotatedMBean.registerMBean(getManagementContext(), statusView, objectName);
} catch (Throwable e) {
throw IOExceptionSupport.create("Status MBean could not be registered in JMX: "
@ -2243,13 +2247,10 @@ public class BrokerService implements Service {
}
}
protected ObjectName createBrokerObjectName() throws IOException {
try {
return new ObjectName(getManagementContext().getJmxDomainName() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=Broker");
} catch (Throwable e) {
throw IOExceptionSupport.create("Invalid JMX broker name: " + brokerName, e);
}
protected ObjectName createBrokerObjectName() throws MalformedObjectNameException {
String objectNameStr = getManagementContext().getJmxDomainName() + ":type=Broker,brokerName=";
objectNameStr += JMXSupport.encodeObjectNamePart(getBrokerName());
return new ObjectName(objectNameStr);
}
protected TransportConnector createTransportConnector(URI brokerURI) throws Exception {

View File

@ -149,9 +149,9 @@ public class ConnectionView implements ConnectionViewMBean {
private ObjectName createConsumerQueury(String clientId) throws IOException {
try {
return new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName=*,"
+ "Type=Subscription,persistentMode=*,"
return new ObjectName(managementContext.getJmxDomainName() + ":type=Broker,brokerName=*,"
+ "destinationType=*,destinationName=*,"
+ "endpoint=Consumer,"
+ "clientId=" + JMXSupport.encodeObjectNamePart(clientId) + ","
+ "consumerId=*");
} catch (Throwable e) {
@ -161,11 +161,11 @@ public class ConnectionView implements ConnectionViewMBean {
private ObjectName createProducerQueury(String clientId) throws IOException {
try {
return new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName=*,"
+ "Type=Producer,"
+ "destinationType=*,destinationName=*,"
+ "clientId=" + JMXSupport.encodeObjectNamePart(clientId) + ","
+ "producerId=*");
return new ObjectName(managementContext.getJmxDomainName() + ":type=Broker,brokerName=*,"
+ "destinationType=*,destinationName=*,"
+ "endpoint=Producer,"
+ "clientId=" + JMXSupport.encodeObjectNamePart(clientId) + ","
+ "producerId=*");
} catch (Throwable e) {
throw IOExceptionSupport.create(e);
}

View File

@ -35,6 +35,7 @@ import org.apache.activemq.usage.SystemUsage;
public class HealthView implements HealthViewMBean {
ManagedRegionBroker broker;
String currentState = "Good";
public HealthView(ManagedRegionBroker broker) {
this.broker = broker;
@ -172,7 +173,24 @@ public class HealthView implements HealthViewMBean {
}
}
if (answer != null && !answer.isEmpty()){
this.currentState = "Feeling Ill {";
for (HealthStatus hs: answer){
currentState += hs + " , ";
}
currentState += " }";
} else{
this.currentState="Good";
}
return answer;
}
/**
* @return String representation of the current Broker state
*/
@Override
public String getCurrentStatus() {
return this.currentState;
}
}

View File

@ -33,5 +33,12 @@ public interface HealthViewMBean {
*
* If in doubt, please use the {@link #status()} method instead!
*/
@MBeanInfo("List of warnings and errors about the current health of the Broker - empty list is Good!")
List<HealthStatus> healthList() throws Exception;
/**
* @return String representation of the current Broker state
*/
@MBeanInfo("String representation of current Broker state")
String getCurrentStatus();
}

View File

@ -40,23 +40,12 @@ import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.broker.jmx.OpenTypeSupport.OpenTypeFactory;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.DestinationFactory;
import org.apache.activemq.broker.region.DestinationFactoryImpl;
import org.apache.activemq.broker.region.DestinationInterceptor;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.broker.region.Region;
import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.broker.region.Topic;
import org.apache.activemq.broker.region.TopicRegion;
import org.apache.activemq.broker.region.TopicSubscription;
import org.apache.activemq.broker.region.*;
import org.apache.activemq.broker.region.policy.AbortSlowConsumerStrategy;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
@ -228,27 +217,15 @@ public class ManagedRegionBroker extends RegionBroker {
}
public static String getSubscriptionObjectName(ConsumerInfo info, String connectionClientId, ObjectName brokerJmxObjectName) {
Hashtable<String, String> map = brokerJmxObjectName.getKeyPropertyList();
String brokerDomain = brokerJmxObjectName.getDomain();
String objectNameStr = brokerDomain + ":" + "BrokerName=" + map.get("BrokerName") + ",Type=Subscription,";
String destinationType = "destinationType=" + info.getDestination().getDestinationTypeAsString();
String destinationName = "destinationName=" + JMXSupport.encodeObjectNamePart(info.getDestination().getPhysicalName());
String clientId = "clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId);
String persistentMode = "persistentMode=";
String consumerId = "";
if (info.isDurable()) {
persistentMode += "Durable,subscriptionID=" + JMXSupport.encodeObjectNamePart(info.getSubscriptionName());
String objectNameStr = brokerJmxObjectName.toString();
objectNameStr += getDestinationType(info.getDestination()) + ",endpoint=Consumer";
objectNameStr += ",clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId);
objectNameStr += ",consumerId=";
if (info.isDurable()){
objectNameStr += "Durable(" + JMXSupport.encodeObjectNamePart(connectionClientId + ":" + info.getSubscriptionName()) +")";
} else {
persistentMode += "Non-Durable";
if (info.getConsumerId() != null) {
consumerId = ",consumerId=" + JMXSupport.encodeObjectNamePart(info.getConsumerId().toString());
}
objectNameStr += JMXSupport.encodeObjectNamePart(info.getConsumerId().toString());
}
objectNameStr += persistentMode + ",";
objectNameStr += destinationType + ",";
objectNameStr += destinationName + ",";
objectNameStr += clientId;
objectNameStr += consumerId;
return objectNameStr;
}
@ -698,39 +675,33 @@ public class ManagedRegionBroker extends RegionBroker {
this.contextBroker = contextBroker;
}
protected ObjectName createObjectName(ActiveMQDestination destName) throws MalformedObjectNameException {
protected ObjectName createObjectName(ActiveMQDestination destination) throws MalformedObjectNameException {
// Build the object name for the destination
Hashtable<String, String> map = brokerObjectName.getKeyPropertyList();
ObjectName objectName = new ObjectName(brokerObjectName.getDomain() + ":" + "BrokerName=" + map.get("BrokerName") + "," + "Type="
+ JMXSupport.encodeObjectNamePart(destName.getDestinationTypeAsString()) + "," + "Destination="
+ JMXSupport.encodeObjectNamePart(destName.getPhysicalName()));
return objectName;
String objectNameStr = brokerObjectName.toString();
objectNameStr += getDestinationType(destination);
return new ObjectName(objectNameStr);
}
protected static String getDestinationType(ActiveMQDestination destination){
String result = "";
if (destination != null){
result = ",destinationType="+ JMXSupport.encodeObjectNamePart(destination.getDestinationTypeAsString()) + ",destinationName=" + JMXSupport.encodeObjectNamePart(destination.getPhysicalName());
}
return result;
}
protected ObjectName createObjectName(ProducerInfo producerInfo, String connectionClientId) throws MalformedObjectNameException {
// Build the object name for the producer info
Hashtable<String, String> map = brokerObjectName.getKeyPropertyList();
String destinationType = "destinationType=";
String destinationName = "destinationName=";
String objectNameStr = brokerObjectName.toString();
if (producerInfo.getDestination() == null) {
destinationType += "Dynamic";
destinationName = null;
objectNameStr += ",endpoint=dynamicProducer";
} else {
destinationType += producerInfo.getDestination().getDestinationTypeAsString();
destinationName += JMXSupport.encodeObjectNamePart(producerInfo.getDestination().getPhysicalName());
objectNameStr += getDestinationType(producerInfo.getDestination()) + ",endpoint=Producer";
}
String clientId = "clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId);
String producerId = "producerId=" + JMXSupport.encodeObjectNamePart(producerInfo.getProducerId().toString());
ObjectName objectName = new ObjectName(brokerObjectName.getDomain() + ":" + "BrokerName=" + map.get("BrokerName") + ","
+ "Type=Producer" + ","
+ destinationType + ","
+ (destinationName != null ? destinationName + "," : "")
+ clientId + "," + producerId);
return objectName;
objectNameStr += ",clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId);
objectNameStr += ",producerId=" + JMXSupport.encodeObjectNamePart(producerInfo.getProducerId().toString());
return new ObjectName(objectNameStr);
}
public ObjectName registerSlowConsumerStrategy(AbortSlowConsumerStrategy strategy) throws MalformedObjectNameException {
@ -750,9 +721,8 @@ public class ManagedRegionBroker extends RegionBroker {
}
protected ObjectName createObjectName(XATransaction transaction) throws MalformedObjectNameException {
Hashtable<String, String> map = brokerObjectName.getKeyPropertyList();
ObjectName objectName = new ObjectName(brokerObjectName.getDomain() + ":" + "BrokerName=" + map.get("BrokerName")
+ "," + "Type=RecoveredXaTransaction"
ObjectName objectName = new ObjectName(brokerObjectName.toString()
+ "," + "transactionType=RecoveredXaTransaction"
+ "," + "Xid="
+ JMXSupport.encodeObjectNamePart(transaction.getTransactionId().toString()));
return objectName;
@ -789,9 +759,10 @@ public class ManagedRegionBroker extends RegionBroker {
}
private ObjectName createObjectName(AbortSlowConsumerStrategy strategy) throws MalformedObjectNameException{
String objectNameStr = this.brokerObjectName.toString();
objectNameStr += "Service=SlowConsumerStrategy,InstanceName="+ JMXSupport.encodeObjectNamePart(strategy.getName());
Hashtable<String, String> map = brokerObjectName.getKeyPropertyList();
ObjectName objectName = new ObjectName(brokerObjectName.getDomain() + ":" + "BrokerName=" + map.get("BrokerName") + ","
+ "Type=SlowConsumerStrategy," + "InstanceName=" + JMXSupport.encodeObjectNamePart(strategy.getName()));
ObjectName objectName = new ObjectName(objectNameStr);
return objectName;
}

View File

@ -17,10 +17,8 @@
package org.apache.activemq.broker.jmx;
import java.io.IOException;
import java.util.Hashtable;
import javax.management.ObjectName;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.TransportConnector;
@ -116,27 +114,21 @@ public class ManagedTransportConnection extends TransportConnection {
}
protected ObjectName createByAddressObjectName(String type, String value) throws IOException {
Hashtable<String, String> map = connectorName.getKeyPropertyList();
try {
return new ObjectName(connectorName.getDomain() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart((String)map.get("BrokerName")) + ","
+ "Type=Connection," + "ConnectorName="
+ JMXSupport.encodeObjectNamePart((String)map.get("ConnectorName")) + ","
+ "ViewType=" + JMXSupport.encodeObjectNamePart(type) + "," + "Name="
+ JMXSupport.encodeObjectNamePart(value));
String objectNameStr = connectorName.toString();
objectNameStr += ",connectionViewType=" + JMXSupport.encodeObjectNamePart(type);
objectNameStr += ",connectionName="+JMXSupport.encodeObjectNamePart(value);
return new ObjectName(objectNameStr);
} catch (Throwable e) {
throw IOExceptionSupport.create(e);
}
}
protected ObjectName createByClientIdObjectName(String value) throws IOException {
Hashtable<String, String> map = connectorName.getKeyPropertyList();
try {
return new ObjectName(connectorName.getDomain() + ":" + "BrokerName="
+ JMXSupport.encodeObjectNamePart((String)map.get("BrokerName")) + ","
+ "Type=Connection," + "ConnectorName="
+ JMXSupport.encodeObjectNamePart((String)map.get("ConnectorName")) + ","
+ "Connection=" + JMXSupport.encodeObjectNamePart(value));
String objectNameStr = connectorName.toString();
objectNameStr += ",connectionName="+JMXSupport.encodeObjectNamePart(value);
return new ObjectName(objectNameStr);
} catch (Throwable e) {
throw IOExceptionSupport.create(e);
}

View File

@ -74,7 +74,7 @@ public class SubscriptionView implements SubscriptionViewMBean {
if (managementCtx != null) {
try {
ObjectName query = createConnectionQueury(managementCtx, service.getBrokerName());
ObjectName query = createConnectionQuery(managementCtx, service.getBrokerName());
Set<ObjectName> names = managementCtx.queryNames(query, null);
if (names.size() == 1) {
result = names.iterator().next();
@ -87,12 +87,12 @@ public class SubscriptionView implements SubscriptionViewMBean {
return result;
}
private ObjectName createConnectionQueury(ManagementContext ctx, String brokerName) throws IOException {
private ObjectName createConnectionQuery(ManagementContext ctx, String brokerName) throws IOException {
try {
return new ObjectName(ctx.getJmxDomainName() + ":" + "BrokerName="
return new ObjectName(ctx.getJmxDomainName() + ":type=Broker,brokerName="
+ JMXSupport.encodeObjectNamePart(brokerName) + ","
+ "Type=Connection," + "ConnectorName=*,"
+ "Connection=" + JMXSupport.encodeObjectNamePart(clientId));
+ "connector=*," + "connectorName=*,"
+ "connectionName=" + JMXSupport.encodeObjectNamePart(clientId));
} catch (Throwable e) {
throw IOExceptionSupport.create(e);
}