git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1415159 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2012-11-29 13:28:37 +00:00
parent 3016b39249
commit ed96e2ec08
6 changed files with 163 additions and 0 deletions

View File

@ -2064,6 +2064,19 @@ public class BrokerService implements Service {
} }
broker = sb; 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()) { if (isAdvisorySupport()) {
broker = new AdvisoryBroker(broker); broker = new AdvisoryBroker(broker);
} }

View File

@ -809,4 +809,8 @@ public class ManagedRegionBroker extends RegionBroker {
} }
return sub; return sub;
} }
public Map<ObjectName, DestinationView> getQueueViews() {
return queues;
}
} }

View File

@ -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<String, Object> getFields(Object o) throws OpenDataException {
StatusEvent event = (StatusEvent) o;
Map<String, Object> rc = super.getFields(o);
rc.put("id", event.getId());
rc.put("resource", event.getResource());
return rc;
}
}
static { static {
OPEN_TYPE_FACTORIES.put(ActiveMQMessage.class, new MessageOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(ActiveMQMessage.class, new MessageOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(ActiveMQBytesMessage.class, new ByteMessageOpenTypeFactory()); 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(Job.class, new JobOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(SlowConsumerEntry.class, new SlowConsumerEntryOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(SlowConsumerEntry.class, new SlowConsumerEntryOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(ActiveMQBlobMessage.class, new ActiveMQBlobMessageOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(ActiveMQBlobMessage.class, new ActiveMQBlobMessageOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(StatusEvent.class, new StatusEventOpenTypeFactory());
} }
private OpenTypeSupport() { private OpenTypeSupport() {

View File

@ -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;
}
}

View File

@ -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<ObjectName, DestinationView> queueViews = broker.getQueueViews();
for (Map.Entry<ObjectName, DestinationView> 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;
}
}

View File

@ -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;
}