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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,8 @@
package org.apache.activemq.broker.jmx; package org.apache.activemq.broker.jmx;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.util.List; import java.util.List;
@ -27,6 +29,7 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import org.apache.activemq.Service; import org.apache.activemq.Service;
import org.apache.activemq.util.ClassLoading;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; 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 createMBeanServer=true;
private boolean locallyCreateMBeanServer=false; private boolean locallyCreateMBeanServer=false;
private boolean createConnector=true; private boolean createConnector=true;
private boolean findTigerMbeanServer=false;
private int connectorPort=1099; private int connectorPort=1099;
private String connectorPath="/jmxrmi"; private String connectorPath="/jmxrmi";
private AtomicBoolean started=new AtomicBoolean(false); private AtomicBoolean started=new AtomicBoolean(false);
@ -186,6 +190,17 @@ public class ManagementContext implements Service{
this.createMBeanServer=enableJMX; 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 * Formulate and return the MBean ObjectName of a custom control MBean
* *
@ -261,11 +276,16 @@ public class ManagementContext implements Service{
// create the mbean server // create the mbean server
try{ try{
if(useMBeanServer){ if(useMBeanServer){
// lets piggy back on another MBeanServer - if (findTigerMbeanServer) {
// we could be in an appserver! result = findTigerMBeanServer();
List list=MBeanServerFactory.findMBeanServer(null); }
if(list!=null&&list.size()>0){ if (result == null) {
result=(MBeanServer) list.get(0); // 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){ if(result==null&&createMBeanServer){
@ -280,6 +300,49 @@ public class ManagementContext implements Service{
return result; 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 * @return
* @throws NullPointerException * @throws NullPointerException

View File

@ -16,7 +16,9 @@
*/ */
package org.apache.activemq.broker.region; package org.apache.activemq.broker.region;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -112,6 +114,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 { public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
Subscription sub = createSubscription(context, info); Subscription sub = createSubscription(context, info);

View File

@ -349,6 +349,10 @@ public class Queue implements Destination {
return destination; return destination;
} }
public String getDestination() {
return destination.getPhysicalName();
}
public UsageManager getUsageManager() { public UsageManager getUsageManager() {
return usageManager; 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.MessageDispatchNotification;
import org.apache.activemq.command.RemoveSubscriptionInfo; import org.apache.activemq.command.RemoveSubscriptionInfo;
import java.util.Map;
/** /**
* A Region is used to implement the different QOS options available to * A Region is used to implement the different QOS options available to
* a broker. A Broker is composed of multiple message processing Regions that * 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; 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. * Adds a consumer.
* @param context the environment the operation is being executed under. * @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); tempTopicRegion = createTempTopicRegion(memoryManager, taskRunnerFactory);
} }
public Map getDestinationMap() {
Map answer = getQueueRegion().getDestinationMap();
answer.putAll(getTopicRegion().getDestinationMap());
return answer;
}
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type){
if (type.isInstance(this)){ if (type.isInstance(this)){
return this; return this;
@ -104,6 +110,22 @@ public class RegionBroker implements Broker {
return null; 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) { protected Region createTempTopicRegion(UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory) {
return new TempTopicRegion(this,destinationStatistics, memoryManager, taskRunnerFactory); return new TempTopicRegion(this,destinationStatistics, memoryManager, taskRunnerFactory);
} }

View File

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