[jboss-cvs] JBossAS SVN: r77460 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 25 19:02:52 EDT 2008


Author: pferraro
Date: 2008-08-25 19:02:52 -0400 (Mon, 25 Aug 2008)
New Revision: 77460

Added:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java
Log:
Renamed ObjectNamePatternLoadMetricSource -> MBeanQueryLoadMetricSource

Copied: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java (from rev 77364, 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/MBeanQueryLoadMetricSource.java	                        (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java	2008-08-25 23:02:52 UTC (rev 77460)
@@ -0,0 +1,104 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetric;
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource;
+import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
+
+/**
+ * Abstract {@link LoadMetricSource} that queries the mbean server for the set of beans to be made available to its registered {@link LoadMetric}s.
+ * 
+ * @author Paul Ferraro
+ */
+public abstract class MBeanQueryLoadMetricSource extends AbstractLoadMetricSource
+{
+   private final MBeanServer server;
+   private final ObjectName pattern;
+   
+   private transient Set<ObjectName> objectNames;
+   
+   protected MBeanQueryLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+   {
+      this(registration, pattern, ManagementFactory.getPlatformMBeanServer());
+   }
+   
+   protected MBeanQueryLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
+   {
+      super(registration);
+      
+      this.pattern = ObjectName.getInstance(pattern);      
+      this.server = server;
+   }
+
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.AbstractLoadMetricSource#prepare()
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   public void prepare()
+   {
+      this.objectNames = this.pattern.isPattern() ? this.server.queryNames(this.pattern, null) : Collections.singleton(this.pattern);
+   }
+   
+   /**
+    * @{inheritDoc}
+    * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.AbstractLoadMetricSource#cleanup()
+    */
+   @Override
+   public void cleanup()
+   {
+      this.objectNames = null;
+   }
+
+   /**
+    * Collects the attribute values for each mbean matching the object name pattern
+    * @param <T> the type of the attribute
+    * @param attribute the mbean attribute name
+    * @param targetClass the type of the attribute
+    * @return a list of attribute values for each mbean
+    * @throws JMException
+    */
+   public <T> List<T> getAttributes(String attribute, Class<T> targetClass) throws JMException
+   {
+      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;
+   }
+}


Property changes on: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/MBeanQueryLoadMetricSource.java
___________________________________________________________________
Name: svn:mergeinfo
   + 




More information about the jboss-cvs-commits mailing list