added some helper methods to make it easier to access management information without having to use explicit JMX APIs

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@397198 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-04-26 13:54:11 +00:00
parent 4e65119cff
commit d680ba1291
13 changed files with 153 additions and 7 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.broker;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription;
@ -56,7 +57,10 @@ public class BrokerFilter implements Broker {
return next.getAdaptor(type);
}
public Map getDestinationMap() {
return next.getDestinationMap();
}
public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
next.acknowledge(context, ack);
}

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.broker;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription;
@ -56,6 +58,10 @@ public class EmptyBroker implements Broker{
return null;
}
public Map getDestinationMap() {
return Collections.EMPTY_MAP;
}
public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{
}

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.broker;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription;
@ -47,6 +49,10 @@ public class ErrorBroker implements Broker {
this.message=message;
}
public Map getDestinationMap() {
return Collections.EMPTY_MAP;
}
public Broker getAdaptor(Class type){
if (type.isInstance(this)){
return this;

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.broker;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription;
@ -68,7 +69,11 @@ public class MutableBrokerFilter implements Broker {
this.next=next;
}
}
public Map getDestinationMap() {
return getNext().getDestinationMap();
}
public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
getNext().acknowledge(context, ack);
}

View File

@ -38,6 +38,10 @@ public class BrokerView implements BrokerViewMBean {
this.broker = managedBroker;
}
public ManagedRegionBroker getBroker() {
return broker;
}
public String getBrokerId() {
return broker.getBrokerId().toString();
}

View File

@ -45,10 +45,15 @@ public class DestinationView {
this.destination=destination;
}
public void gc(){
destination.gc();
}
public String getName() {
return destination.getActiveMQDestination().getPhysicalName();
}
public void resetStatistics(){
destination.getDestinationStatistics().reset();
}

View File

@ -25,6 +25,11 @@ import javax.management.openmbean.TabularData;
public interface DestinationViewMBean {
/**
* Returns the name of this destination
*/
public String getName();
/**
* Resets the managment counters.
*/

View File

@ -14,6 +14,8 @@
package org.apache.activemq.broker.jmx;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.rmi.registry.LocateRegistry;
import java.util.List;
@ -27,6 +29,7 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.activemq.Service;
import org.apache.activemq.util.ClassLoading;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
@ -49,6 +52,7 @@ public class ManagementContext implements Service{
private boolean createMBeanServer=true;
private boolean locallyCreateMBeanServer=false;
private boolean createConnector=true;
private boolean findTigerMbeanServer=false;
private int connectorPort=1099;
private String connectorPath="/jmxrmi";
private AtomicBoolean started=new AtomicBoolean(false);
@ -186,6 +190,17 @@ public class ManagementContext implements Service{
this.createMBeanServer=enableJMX;
}
public boolean isFindTigerMbeanServer() {
return findTigerMbeanServer;
}
/**
* Enables/disables the searching for the Java 5 platform MBeanServer
*/
public void setFindTigerMbeanServer(boolean findTigerMbeanServer) {
this.findTigerMbeanServer = findTigerMbeanServer;
}
/**
* Formulate and return the MBean ObjectName of a custom control MBean
*
@ -261,11 +276,16 @@ public class ManagementContext implements Service{
// create the mbean server
try{
if(useMBeanServer){
// lets piggy back on another MBeanServer -
// we could be in an appserver!
List list=MBeanServerFactory.findMBeanServer(null);
if(list!=null&&list.size()>0){
result=(MBeanServer) list.get(0);
if (findTigerMbeanServer) {
result = findTigerMBeanServer();
}
if (result == null) {
// lets piggy back on another MBeanServer -
// we could be in an appserver!
List list=MBeanServerFactory.findMBeanServer(null);
if(list!=null&&list.size()>0){
result=(MBeanServer) list.get(0);
}
}
}
if(result==null&&createMBeanServer){
@ -280,6 +300,49 @@ public class ManagementContext implements Service{
return result;
}
public static MBeanServer findTigerMBeanServer() {
String name = "java.lang.management.ManagementFactory";
Class type = loadClass(name, ManagementContext.class.getClassLoader());
if (type != null) {
try {
Method method = type.getMethod("getPlatformMBeanServer", new Class[0]);
if (method != null) {
Object answer = method.invoke(null, new Object[0]);
if (answer instanceof MBeanServer) {
return (MBeanServer) answer;
}
else {
log.warn("Could not cast: " + answer + " into an MBeanServer. There must be some classloader strangeness in town");
}
}
else {
log.warn("Method getPlatformMBeanServer() does not appear visible on type: " + type.getName());
}
}
catch (Exception e) {
log.warn("Failed to call getPlatformMBeanServer() due to: " + e, e);
}
}
else {
log.trace("Class not found: " + name + " so probably running on Java 1.4");
}
return null;
}
private static Class loadClass(String name, ClassLoader loader) {
try {
return loader.loadClass(name);
}
catch (ClassNotFoundException e) {
try {
return Thread.currentThread().getContextClassLoader().loadClass(name);
}
catch (ClassNotFoundException e1) {
return null;
}
}
}
/**
* @return
* @throws NullPointerException

View File

@ -16,7 +16,9 @@
*/
package org.apache.activemq.broker.region;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.jms.JMSException;
@ -111,6 +113,12 @@ abstract public class AbstractRegion implements Region {
}
}
}
public Map getDestinationMap() {
synchronized(destinationsMutex){
return new HashMap(destinations);
}
}
public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {

View File

@ -349,6 +349,10 @@ public class Queue implements Destination {
return destination;
}
public String getDestination() {
return destination.getPhysicalName();
}
public UsageManager getUsageManager() {
return usageManager;
}

View File

@ -25,6 +25,8 @@ import org.apache.activemq.command.MessageAck;
import org.apache.activemq.command.MessageDispatchNotification;
import org.apache.activemq.command.RemoveSubscriptionInfo;
import java.util.Map;
/**
* A Region is used to implement the different QOS options available to
* a broker. A Broker is composed of multiple message processing Regions that
@ -57,6 +59,14 @@ public interface Region extends Service {
*/
public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception;
/**
* Returns a copy of the current destinations available in the region
*
* @return a copy of the regions currently active at the time of the call with the key the destination and the value the Destination.
*/
public Map getDestinationMap();
/**
* Adds a consumer.
* @param context the environment the operation is being executed under.

View File

@ -97,6 +97,12 @@ public class RegionBroker implements Broker {
tempTopicRegion = createTempTopicRegion(memoryManager, taskRunnerFactory);
}
public Map getDestinationMap() {
Map answer = getQueueRegion().getDestinationMap();
answer.putAll(getTopicRegion().getDestinationMap());
return answer;
}
public Broker getAdaptor(Class type){
if (type.isInstance(this)){
return this;
@ -104,6 +110,22 @@ public class RegionBroker implements Broker {
return null;
}
public Region getQueueRegion() {
return queueRegion;
}
public Region getTempQueueRegion() {
return tempQueueRegion;
}
public Region getTempTopicRegion() {
return tempTopicRegion;
}
public Region getTopicRegion() {
return topicRegion;
}
protected Region createTempTopicRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory) {
return new TempTopicRegion(this,destinationStatistics, memoryManager, taskRunnerFactory);
}

View File

@ -339,6 +339,10 @@ public class Topic implements Destination {
return destination;
}
public String getDestination() {
return destination.getPhysicalName();
}
public DispatchPolicy getDispatchPolicy() {
return dispatchPolicy;
}