[jboss-cvs] JBossAS SVN: r77120 - in trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric: impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 15 18:10:16 EDT 2008


Author: pferraro
Date: 2008-08-15 18:10:16 -0400 (Fri, 15 Aug 2008)
New Revision: 77120

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/DeterministicLoadMetric.java
Removed:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java
Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SessionLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SingleLoadMetricSource.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
Log:
[JBAS-5664] Refactored LoadMetric.isDeterministic() flag into DeterministicLoadMetric.
Added LoadMetric.getBenchmark() used to normalize metrics.
Minor refactoring.

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -30,7 +30,7 @@
 {
    int getWeight();
    
-   boolean isTimeWindowRequired(); 
+   double getBenchmark();
    
-   double getMetric() throws Exception;
+   double getLoad() throws Exception;
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -23,16 +23,16 @@
 
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
 
-
-
 /**
+ * Abstract {@link LoadMetric} implementation with basic mutators/accessors.
+ * 
  * @author Paul Ferraro
- *
  */
 public abstract class AbstractLoadMetric implements LoadMetric
 {
    private volatile int weight = 0;
-
+   private volatile double benchmark = 1;
+   
    /**
     * @{inheritDoc}
     * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getWeight()
@@ -46,4 +46,18 @@
    {
       this.weight = weight;
    }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getBenchmark()
+    */
+   public double getBenchmark()
+   {
+      return this.benchmark;
+   }
+   
+   public void setBenchmark(double benchmark)
+   {
+      this.benchmark = benchmark;
+   }
 }
\ No newline at end of file

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -28,10 +28,10 @@
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource;
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
-
 /**
+ * Abstract {@link LoadMetricSource} that allows a {@link LoadMetric} to register with it.
+ * 
  * @author Paul Ferraro
- *
  */
 public abstract class AbstractLoadMetricSource implements LoadMetricSource
 {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ActiveSessionsLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,13 +21,16 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
+import java.util.List;
+
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
 /**
+ * {@link LoadMetric} implementation that returns the total number of active web sessions.
+ * 
  * @author Paul Ferraro
- *
  */
 public class ActiveSessionsLoadMetric extends AbstractLoadMetric
 {
@@ -44,28 +47,19 @@
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric() throws JMException
+   public double getLoad() throws JMException
    {
-      int active = 0;
+      int count = 0;
       
-      MBeanServer server = this.source.getServer();
+      List<Integer> results = this.source.getAttributes(ACTIVE_SESSIONS, Integer.class);
       
-      for (ObjectName name: this.source.getObjectNames())
+      for (Integer result: results)
       {
-         active += ((Integer) server.getAttribute(name, ACTIVE_SESSIONS)).intValue();
+         count += result.intValue();
       }
       
-      return active;
+      return count;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AverageSystemLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -24,10 +24,6 @@
 import java.lang.management.OperatingSystemMXBean;
 
 import javax.management.JMException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
 import org.jboss.logging.Logger;
 
@@ -53,55 +49,23 @@
    {
       this.source = source;
       
-      try
+      if (!this.source.exists(SYSTEM_LOAD_AVERAGE))
       {
-         MBeanInfo info = this.source.getServer().getMBeanInfo(source.getOperatingSystemObjectName());
-         
-         boolean exists = false;
-         
-         for (MBeanAttributeInfo attribute: info.getAttributes())
-         {
-            if (SYSTEM_LOAD_AVERAGE.equals(attribute.getName()))
-            {
-               exists = true;
-               break;
-            }
-         }
-         
-         if (exists)
-         {
-            this.source.add(this);
-         }
-         else
-         {
-            this.log.warn(OperatingSystemMXBean.class.getName() + "." + SYSTEM_LOAD_AVERAGE + " is only supported on Java 1.6 or later");
-         }
+         this.source.add(this);
       }
-      catch (JMException e)
+      else
       {
-         // This should not happen on a system mxbean
-         throw new RuntimeException(e);
+         this.log.warn(this.getClass().getName() + " discarded.  This metric requires the "
+               + SYSTEM_LOAD_AVERAGE + " OperatingSystemMXBean attribute found in Java 1.6 or later.");
       }
    }
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric() throws JMException
+   public double getLoad() throws JMException
    {
-      MBeanServer server = this.source.getServer();
-      ObjectName name = this.source.getOperatingSystemObjectName();
-      
-      return ((Double) server.getAttribute(name, SYSTEM_LOAD_AVERAGE)).doubleValue();
+      return this.source.getAttribute(SYSTEM_LOAD_AVERAGE, Double.class).doubleValue();
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/BusyConnectorsLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,16 +21,21 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
+import java.util.List;
+
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
 /**
+ * {@link LoadMetric} implementation that returns the total number of busy connector threads.
+ * 
  * @author Paul Ferraro
- *
  */
 public class BusyConnectorsLoadMetric extends AbstractLoadMetric
 {
+   private static final String CURRENT_THREADS_BUSY = "currentThreadsBusy";
+   
    private final ThreadPoolLoadMetricSource source;
    
    public BusyConnectorsLoadMetric(ThreadPoolLoadMetricSource source)
@@ -42,28 +47,19 @@
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric() throws JMException
+   public double getLoad() throws JMException
    {
       int busy = 0;
       
-      MBeanServer server = this.source.getServer();
+      List<Integer> results = this.source.getAttributes(CURRENT_THREADS_BUSY, Integer.class);
       
-      for (ObjectName threadPoolName: this.source.getObjectNames())
+      for (Integer result: results)
       {
-         busy += ((Integer) server.getAttribute(threadPoolName, "currentThreadsBusy")).intValue();
+         busy += result.intValue();
       }
       
       return busy;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/DeterministicLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/DeterministicLoadMetric.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/DeterministicLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
+/**
+ * Abstract {@link LoadMetric} implementation for deterministic metrics,
+ * i.e. metrics whose significance is relative to the previous value.
+ * 
+ * @author Paul Ferraro
+ */
+public abstract class DeterministicLoadMetric extends AbstractLoadMetric
+{
+   private AtomicReference<Double> currentMetric = new AtomicReference<Double>(new Double(0));
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
+    */
+   public final double getLoad() throws Exception
+   {
+      double currentMetric = this.getDeterministicMetric();
+      double previousMetric = this.currentMetric.getAndSet(new Double(currentMetric)).doubleValue();
+      
+      return currentMetric - previousMetric;
+   }
+
+   protected abstract double getDeterministicMetric() throws Exception;
+}
\ No newline at end of file

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/HeapMemoryUsageLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -29,8 +29,9 @@
 
 
 /**
+ * {@link LoadMetric} implementation that returns the heap memory usage ratio.
+ * 
  * @author Paul Ferraro
- *
  */
 public class HeapMemoryUsageLoadMetric extends SingleLoadMetricSource
 {
@@ -48,21 +49,12 @@
 
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric()
+   public double getLoad()
    {
       MemoryUsage usage = this.bean.getHeapMemoryUsage();
 
       return ((double) usage.getUsed()) / usage.getMax();
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -22,8 +22,11 @@
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
 import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
+import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -31,8 +34,9 @@
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
 /**
+ * Abstract {@link LoadMetricSource} that queries the mbean server for beans to be made available to its registered {@link LoadMetric}s.
+ * 
  * @author Paul Ferraro
- *
  */
 public abstract class ObjectNamePatternLoadMetricSource extends AbstractLoadMetricSource
 {
@@ -88,13 +92,15 @@
       this.objectNames = this.server.queryNames(this.objectNamePattern, null);
    }
    
-   public MBeanServer getServer()
+   public <T> List<T> getAttributes(String attribute, Class<T> targetClass) throws JMException
    {
-      return this.server;
+      List<T> list = new ArrayList<T>(this.objectNames.size());
+      
+      for (ObjectName name: this.objectNames)
+      {
+         list.add(targetClass.cast(this.server.getAttribute(name, attribute)));
+      }
+      
+      return list;
    }
-   
-   public Set<ObjectName> getObjectNames()
-   {
-      return this.objectNames;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/OperatingSystemLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -22,17 +22,23 @@
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
 import java.lang.management.ManagementFactory;
+import java.util.Set;
+import java.util.TreeSet;
 
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource;
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
-
 /**
+ * Abstract {@link LoadMetricSource} implementation that simplifies generic access to the {@link java.lang.management.OperatingSystemMXBean}.
+ * 
  * @author Paul Ferraro
- *
  */
 public class OperatingSystemLoadMetricSource extends AbstractLoadMetricSource
 {
@@ -54,18 +60,40 @@
       }
       catch (MalformedObjectNameException e)
       {
-         // Should never happen given this is a platform mxbean
+         // Should never happen for a platform mxbean
          throw new RuntimeException(e);
       }
    }
 
-   public ObjectName getOperatingSystemObjectName()
+   public boolean exists(String... attributes)
    {
-      return this.name;
+      Set<String> missingAttributes = new TreeSet<String>();
+      
+      for (String attribute: attributes)
+      {
+         missingAttributes.add(attribute);
+      }
+      
+      try
+      {
+         MBeanInfo info = this.server.getMBeanInfo(this.name);
+         
+         for (MBeanAttributeInfo attribute: info.getAttributes())
+         {
+            missingAttributes.remove(attribute.getName());
+         }
+         
+         return missingAttributes.isEmpty();
+      }
+      catch (JMException e)
+      {
+         // Should never happen for a platform mxbean
+         throw new RuntimeException(e);
+      }
    }
    
-   public MBeanServer getServer()
+   public <T> T getAttribute(String attribute, Class<T> targetClass) throws JMException
    {
-      return this.server;
+      return targetClass.cast(this.server.getAttribute(this.name, attribute));
    }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ReceiveTrafficLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,15 +21,17 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
+import java.util.List;
+
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
 /**
+ * {@link LoadMetric} implementation that returns the incoming bandwidth in KB.
  * @author Paul Ferraro
- *
  */
-public class ReceiveTrafficLoadMetric extends AbstractLoadMetric
+public class ReceiveTrafficLoadMetric extends DeterministicLoadMetric
 {
    private static final String RECEIVE_COUNT = "bytesReceived";
    
@@ -42,28 +44,19 @@
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.DeterministicLoadMetric#getDeterministicMetric()
     */
-   public double getMetric() throws JMException
+   protected double getDeterministicMetric() throws JMException
    {
-      MBeanServer server = this.source.getServer();
-      
       long bytes = 0;
+
+      List<Long> results = this.source.getAttributes(RECEIVE_COUNT, Long.class);
       
-      for (ObjectName name: this.source.getObjectNames())
+      for (Long result: results)
       {
-         bytes += ((Long) server.getAttribute(name, RECEIVE_COUNT)).longValue();
+         bytes += result.longValue();
       }
       
-      return bytes;
+      return bytes * 1000;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return true;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestCountLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,15 +21,18 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
+import java.util.List;
+
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
 /**
+ * {@link LoadMetric} implementation that returns the number of web requests.
+ * 
  * @author Paul Ferraro
- *
  */
-public class RequestCountLoadMetric extends AbstractLoadMetric
+public class RequestCountLoadMetric extends DeterministicLoadMetric
 {
    private static final String REQUEST_COUNT = "requestCount";
    
@@ -42,28 +45,19 @@
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.DeterministicLoadMetric#getDeterministicMetric()
     */
-   public double getMetric() throws JMException
+   protected double getDeterministicMetric() throws JMException
    {
-      MBeanServer server = this.source.getServer();
-      
       int count = 0;
+
+      List<Integer> results = this.source.getAttributes(REQUEST_COUNT, Integer.class);
       
-      for (ObjectName name: this.source.getObjectNames())
+      for (Integer result: results)
       {
-         count += ((Integer) server.getAttribute(name, REQUEST_COUNT)).intValue();
+         count += result.intValue();
       }
       
       return count;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return true;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -24,8 +24,10 @@
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
 /**
+ * {@link LoadMetricSource} implementation that simplifies generic mbean access to 
+ * the JBossWeb request processors.
+ * 
  * @author Paul Ferraro
- *
  */
 public class RequestProcessorLoadMetricSource extends ObjectNamePatternLoadMetricSource
 {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SendTrafficLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,15 +21,18 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
+import java.util.List;
+
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+
 /**
+ * {@link LoadMetric} implementation that returns the outgoing bandwidth in KB.
+ * 
  * @author Paul Ferraro
- *
  */
-public class SendTrafficLoadMetric extends AbstractLoadMetric
+public class SendTrafficLoadMetric extends DeterministicLoadMetric
 {
    private static final String SEND_COUNT = "bytesSent";
    
@@ -42,28 +45,19 @@
    
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.DeterministicLoadMetric#getDeterministicMetric()
     */
-   public double getMetric() throws JMException
+   protected double getDeterministicMetric() throws JMException
    {
-      MBeanServer server = this.source.getServer();
-      
       long bytes = 0;
+
+      List<Long> results = this.source.getAttributes(SEND_COUNT, Long.class);
       
-      for (ObjectName name: this.source.getObjectNames())
+      for (Long result: results)
       {
-         bytes += ((Long) server.getAttribute(name, SEND_COUNT)).longValue();
+         bytes += result.longValue();
       }
       
       return bytes;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return true;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SessionLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SessionLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SessionLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -24,8 +24,10 @@
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
 /**
+ * {@link LoadMetricSource} implementation that simplifies generic mbean access to 
+ * all JBossWeb session managers.
+ * 
  * @author Paul Ferraro
- *
  */
 public class SessionLoadMetricSource extends ObjectNamePatternLoadMetricSource
 {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SingleLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SingleLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SingleLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -30,8 +30,9 @@
 
 
 /**
+ * Abstract {@link LoadMetricSource} + {@link LoadMetric} implementation that returns a single metric.
+ * 
  * @author Paul Ferraro
- *
  */
 public abstract class SingleLoadMetricSource extends AbstractLoadMetric implements LoadMetricSource
 {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SystemMemoryUsageLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -21,20 +21,17 @@
  */
 package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
 
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.Arrays;
 
 import javax.management.JMException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
 import org.jboss.logging.Logger;
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
 
 
 /**
- * Uses {@link com.sun.management.OperatingSystemMXBean} to determine system memory usage.
+ * {@link LoadMetric} implementation that uses {@link com.sun.management.OperatingSystemMXBean}
+ * to determine system memory usage.
  * 
  * @author Paul Ferraro
  */
@@ -55,57 +52,27 @@
    {
       this.source = source;
       
-      try
+      if (this.source.exists(FREE_MEMORY, TOTAL_MEMORY))
       {
-         MBeanInfo info = this.source.getServer().getMBeanInfo(source.getOperatingSystemObjectName());
-         
-         Set<String> missingAttributes = new TreeSet<String>();
-         
-         missingAttributes.add(FREE_MEMORY);
-         missingAttributes.add(TOTAL_MEMORY);
-         
-         for (MBeanAttributeInfo attribute: info.getAttributes())
-         {
-            missingAttributes.remove(attribute.getName());
-         }
-         
-         if (missingAttributes.isEmpty())
-         {
-            this.source.add(this);
-         }
-         else
-         {
-            this.log.warn(this.source.getOperatingSystemObjectName() + " is missing the following attributes required by this metric: " + missingAttributes);
-         }
+         this.source.add(this);
       }
-      catch (JMException e)
+      else
       {
-         // This should not happen on a system mxbean
-         throw new RuntimeException(e);
+         this.log.warn(this.getClass().getName() + " discarded."
+               + "This metric requires the following OperatingSystemMXBean attributes: "
+               + Arrays.asList(FREE_MEMORY, TOTAL_MEMORY));
       }
    }
 
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric() throws JMException
+   public double getLoad() throws JMException
    {
-      MBeanServer server = this.source.getServer();
-      ObjectName name = this.source.getOperatingSystemObjectName();
+      long free = this.source.getAttribute(FREE_MEMORY, Long.class).longValue();
+      long total = this.source.getAttribute(TOTAL_MEMORY, Long.class).longValue();
       
-      long free = ((Long) server.getAttribute(name, FREE_MEMORY)).longValue();
-      long total = ((Long) server.getAttribute(name, FREE_MEMORY)).longValue();
-      
       return ((double) free) / total;
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadCountLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -46,19 +46,10 @@
 
    /**
     * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getLoad()
     */
-   public double getMetric()
+   public double getLoad()
    {
       return this.bean.getThreadCount();
    }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
 }

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -23,8 +23,10 @@
 
 import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
 
-
 /**
+ * {@link LoadMetricSource} implementation that simplifies generic mbean access to 
+ * all JBossWeb connector thread pools.
+ * 
  * @author Paul Ferraro
  */
 public class ThreadPoolLoadMetricSource extends ObjectNamePatternLoadMetricSource

Deleted: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java	2008-08-15 16:34:32 UTC (rev 77119)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/UptimeLoadMetric.java	2008-08-15 22:10:16 UTC (rev 77120)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
-
-import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
-
-
-/**
- * @author Paul Ferraro
- *
- */
-public class UptimeLoadMetric extends SingleLoadMetricSource
-{
-   private RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
-   
-   /**
-    * Create a new RuntimeMetric.
-    * 
-    * @param registration
-    */
-   public UptimeLoadMetric(LoadMetricSourceRegistration registration)
-   {
-      super(registration);
-   }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#getMetric()
-    */
-   public double getMetric()
-   {
-      return this.runtimeBean.getUptime();
-   }
-
-   /**
-    * @{inheritDoc}
-    * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric#isTimeWindowRequired()
-    */
-   public boolean isTimeWindowRequired()
-   {
-      return false;
-   }
-}




More information about the jboss-cvs-commits mailing list