activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r397198 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker: ./ jmx/ region/
Date Wed, 26 Apr 2006 13:54:13 GMT
Author: jstrachan
Date: Wed Apr 26 06:54:11 2006
New Revision: 397198

URL: http://svn.apache.org/viewcvs?rev=397198&view=rev
Log:
added some helper methods to make it easier to access management information without having
to use explicit JMX APIs

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Region.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Topic.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java
Wed Apr 26 06:54:11 2006
@@ -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 @@
         return next.getAdaptor(type);
     }
 
-    
+    public Map getDestinationMap() {
+        return next.getDestinationMap();
+    }
+
     public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
         next.acknowledge(context, ack);
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java
Wed Apr 26 06:54:11 2006
@@ -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;
@@ -54,6 +56,10 @@
             return this;
         }
         return null;
+    }
+
+    public Map getDestinationMap() {
+        return Collections.EMPTY_MAP;
     }
 
     public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java
Wed Apr 26 06:54:11 2006
@@ -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 @@
         this.message=message;
     }
     
+    public Map getDestinationMap() {
+        return Collections.EMPTY_MAP;
+    }
+
     public Broker getAdaptor(Class type){
         if (type.isInstance(this)){
             return this;

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java
Wed Apr 26 06:54:11 2006
@@ -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 @@
             this.next=next;
         }
     }
-    
+        
+    public Map getDestinationMap() {
+        return getNext().getDestinationMap();
+    }
+
     public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
         getNext().acknowledge(context, ack);
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
Wed Apr 26 06:54:11 2006
@@ -38,6 +38,10 @@
 		this.broker = managedBroker;
     }
     
+    public ManagedRegionBroker getBroker() {
+        return broker;
+    }
+
     public String getBrokerId() {
         return broker.getBrokerId().toString();
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
Wed Apr 26 06:54:11 2006
@@ -45,8 +45,13 @@
         this.destination=destination;
     }
 
+    
     public void gc(){
         destination.gc();
+    }
+
+    public String getName() {
+        return destination.getActiveMQDestination().getPhysicalName();
     }
 
     public void resetStatistics(){

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
Wed Apr 26 06:54:11 2006
@@ -25,6 +25,11 @@
 
 public interface DestinationViewMBean {
     
+    /**
+     * Returns the name of this destination
+     */
+    public String getName();
+    
 	/**
 	 * Resets the managment counters.
 	 */

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
Wed Apr 26 06:54:11 2006
@@ -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.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 @@
     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 @@
         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 @@
         // 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){
@@ -278,6 +298,49 @@
             log.error("Failed to initialize MBeanServer",e);
         }
         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;
+            }
+        }
     }
 
     /**

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
Wed Apr 26 06:54:11 2006
@@ -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;
@@ -109,6 +111,12 @@
             }else{
                 log.debug("Destination doesn't exist: " + dest);
             }
+        }
+    }
+    
+    public Map getDestinationMap() {
+        synchronized(destinationsMutex){
+            return new HashMap(destinations);
         }
     }
 

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
Wed Apr 26 06:54:11 2006
@@ -349,6 +349,10 @@
         return destination;
     }
 
+    public String getDestination() {
+        return destination.getPhysicalName();
+    }
+    
     public UsageManager getUsageManager() {
         return usageManager;
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Region.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Region.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Region.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Region.java
Wed Apr 26 06:54:11 2006
@@ -25,6 +25,8 @@
 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
@@ -56,6 +58,14 @@
      * @throws Exception TODO
      */
     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.

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
Wed Apr 26 06:54:11 2006
@@ -97,11 +97,33 @@
         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;
         }
         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) {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Topic.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Topic.java?rev=397198&r1=397197&r2=397198&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Topic.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Topic.java
Wed Apr 26 06:54:11 2006
@@ -339,6 +339,10 @@
         return destination;
     }
 
+    public String getDestination() {
+        return destination.getPhysicalName();
+    }
+    
     public DispatchPolicy getDispatchPolicy() {
         return dispatchPolicy;
     }



Mime
View raw message