diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java index f737dba1e4..344e897f57 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -2064,6 +2064,19 @@ public class BrokerService implements Service { } broker = sb; } + if (isUseJmx()) { + StatusViewMBean statusView = new StatusView((ManagedRegionBroker)getRegionBroker()); + try { + ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":" + + "BrokerName=" + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + + "Type=Status"); + + AnnotatedMBean.registerMBean(getManagementContext(), statusView, objectName); + } catch (Throwable e) { + throw IOExceptionSupport.create("Status MBean could not be registered in JMX: " + + e.getMessage(), e); + } + } if (isAdvisorySupport()) { broker = new AdvisoryBroker(broker); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java index 3830c03a16..3d88eeb870 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagedRegionBroker.java @@ -809,4 +809,8 @@ public class ManagedRegionBroker extends RegionBroker { } return sub; } + + public Map getQueueViews() { + return queues; + } } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java index d18c627a2d..dc5dc0d50c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java @@ -478,6 +478,29 @@ public final class OpenTypeSupport { } } + static class StatusEventOpenTypeFactory extends AbstractOpenTypeFactory { + @Override + protected String getTypeName() { + return StatusEvent.class.getName(); + } + + @Override + protected void init() throws OpenDataException { + super.init(); + addItem("id", "event id", SimpleType.STRING); + addItem("resource", "event resource", SimpleType.STRING); + } + + @Override + public Map getFields(Object o) throws OpenDataException { + StatusEvent event = (StatusEvent) o; + Map rc = super.getFields(o); + rc.put("id", event.getId()); + rc.put("resource", event.getResource()); + return rc; + } + } + static { OPEN_TYPE_FACTORIES.put(ActiveMQMessage.class, new MessageOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(ActiveMQBytesMessage.class, new ByteMessageOpenTypeFactory()); @@ -488,6 +511,7 @@ public final class OpenTypeSupport { OPEN_TYPE_FACTORIES.put(Job.class, new JobOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(SlowConsumerEntry.class, new SlowConsumerEntryOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(ActiveMQBlobMessage.class, new ActiveMQBlobMessageOpenTypeFactory()); + OPEN_TYPE_FACTORIES.put(StatusEvent.class, new StatusEventOpenTypeFactory()); } private OpenTypeSupport() { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusEvent.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusEvent.java new file mode 100644 index 0000000000..b0fbd4bee5 --- /dev/null +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusEvent.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.broker.jmx; + +import java.io.Serializable; + +public class StatusEvent implements Serializable { + + protected String id; + protected String resource; + + public StatusEvent(String id, String resource) { + this.id = id; + this.resource = resource; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Object getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } +} diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusView.java new file mode 100644 index 0000000000..9da0ee6281 --- /dev/null +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusView.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.broker.jmx; + +import javax.management.ObjectName; +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.TabularData; +import javax.management.openmbean.TabularDataSupport; +import javax.management.openmbean.TabularType; +import java.util.Map; + +public class StatusView implements StatusViewMBean { + + ManagedRegionBroker broker; + + public StatusView(ManagedRegionBroker broker) { + this.broker = broker; + } + + @Override + public TabularData status() throws Exception { + OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(StatusEvent.class); + CompositeType ct = factory.getCompositeType(); + TabularType tt = new TabularType("Status", "Status", ct, new String[]{"id", "resource"}); + TabularDataSupport rc = new TabularDataSupport(tt); + + Map queueViews = broker.getQueueViews(); + for (Map.Entry entry : queueViews.entrySet()) { + DestinationView queue = entry.getValue(); + if (queue.getConsumerCount() == 0 && queue.getProducerCount() > 0) { + rc.put(new CompositeDataSupport(ct, factory.getFields(new StatusEvent("AMQ-NoConsumer", entry.getKey().toString())))); + } + } + return rc; + } + +} diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusViewMBean.java new file mode 100644 index 0000000000..189cb3beae --- /dev/null +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/StatusViewMBean.java @@ -0,0 +1,24 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.broker.jmx; + +import javax.management.openmbean.TabularData; + +public interface StatusViewMBean { + + public TabularData status() throws Exception; +}