[jboss-cvs] JBossAS SVN: r77364 - in trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load: metric and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 22 12:43:19 EDT 2008
Author: pferraro
Date: 2008-08-22 12:43:18 -0400 (Fri, 22 Aug 2008)
New Revision: 77364
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
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/LoadMetricSource.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/ObjectNamePatternLoadMetricSource.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/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/ThreadPoolLoadMetricSource.java
Log:
Refactor open(), close() -> prepare(), cleanup().
Replace ObjectNamePatternLoadMetricSource domain, propertyPattern properties with constructor injection of object name pattern.
Javadoc the important stuff.
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-08-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -82,7 +82,7 @@
if (!metricList.isEmpty())
{
- source.open();
+ source.prepare();
try
{
@@ -106,7 +106,7 @@
}
finally
{
- source.close();
+ source.cleanup();
}
}
}
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetric.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -21,16 +21,30 @@
*/
package org.jboss.web.tomcat.service.modcluster.load.metric;
-
/**
+ * Represents a specific load metric.
* @author Paul Ferraro
- *
*/
public interface LoadMetric
{
+ /**
+ * Returns the "weight" of this metric, i.e. significance of this load metric compared to the other metrics.
+ * @return the weight of the metric
+ */
int getWeight();
+ /**
+ * Returns the load capacity of this metric.
+ * Used to normalize the value returned by {@link #getLoad()} expressed as a percentage of the capacity, such that:
+ * 0 <= ({@link #getLoad()} / {@link #getCapacity()}) < 1
+ * @return the estimated capacity of this metric.
+ */
double getCapacity();
+ /**
+ * Returns the current load. This value only has meaning when expressed as a ratio of the capacity.
+ * @return the current load.
+ * @throws Exception if there was an error fetching this metric.
+ */
double getLoad() throws Exception;
}
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetricSource.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetricSource.java 2008-08-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/LoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -24,14 +24,24 @@
import java.util.Collection;
/**
+ * A source for obtaining load metrics.
* @author Paul Ferraro
- *
*/
public interface LoadMetricSource
{
+ /**
+ * Returns the collection of metrics registered with this source.
+ * @return the metrics from this source
+ */
Collection<LoadMetric> getMetrics();
- void open();
+ /**
+ * Prepare any resource required to collect load metrics
+ */
+ void prepare();
- void close();
+ /**
+ * Cleanup any resources used to collect load metrics
+ */
+ void cleanup();
}
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/AbstractLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -58,9 +58,9 @@
/**
* @{inheritDoc}
- * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#open()
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#prepare()
*/
- public void open()
+ public void prepare()
{
// Nothing to open
}
@@ -69,7 +69,7 @@
* @{inheritDoc}
* @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#cleanup()
*/
- public void close()
+ public void cleanup()
{
// Nothing to close
}
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ObjectNamePatternLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -44,77 +44,44 @@
public abstract class ObjectNamePatternLoadMetricSource extends AbstractLoadMetricSource
{
private final MBeanServer server;
+ private final ObjectName pattern;
- private volatile String domain = "jboss.web";
- private volatile String propertyPattern = this.defaultPropertyPattern();
-
private transient Set<ObjectName> objectNames;
- protected ObjectNamePatternLoadMetricSource(LoadMetricSourceRegistration registration)
+ protected ObjectNamePatternLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
{
- this(registration, ManagementFactory.getPlatformMBeanServer());
+ this(registration, pattern, ManagementFactory.getPlatformMBeanServer());
}
- protected ObjectNamePatternLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server)
+ protected ObjectNamePatternLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
{
super(registration);
+ this.pattern = ObjectName.getInstance(pattern);
this.server = server;
}
-
- protected abstract String defaultPropertyPattern();
-
- public String getDomain()
- {
- return this.domain;
- }
-
- public void setDomain(String domain)
- {
- this.domain = domain;
- }
-
- /**
- * Get the objectNamePattern.
- *
- * @return the objectNamePattern.
- */
- public String getPropertyPattern()
- {
- return this.propertyPattern;
- }
/**
- * Set the objectNamePattern.
- *
- * @param objectNamePattern The objectNamePattern to set.
+ * @{inheritDoc}
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.AbstractLoadMetricSource#prepare()
*/
- public void setPropertyPattern(String propertyPattern)
+ @SuppressWarnings("unchecked")
+ @Override
+ public void prepare()
{
- this.propertyPattern = propertyPattern;
+ 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#open()
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.AbstractLoadMetricSource#cleanup()
*/
- @SuppressWarnings("unchecked")
@Override
- public void open()
+ public void cleanup()
{
- try
- {
- ObjectName name = ObjectName.getInstance(this.domain + ":" + this.propertyPattern);
-
- this.objectNames = name.isPattern() ? this.server.queryNames(name, null) : Collections.singleton(name);
- }
- catch (MalformedObjectNameException e)
- {
- // Should not happen
- throw new RuntimeException(e);
- }
+ this.objectNames = null;
}
-
+
public <T> List<T> getAttributes(String attribute, Class<T> targetClass) throws JMException
{
List<T> list = new ArrayList<T>(this.objectNames.size());
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/RequestProcessorLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -22,6 +22,7 @@
package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
@@ -33,36 +34,52 @@
*/
public class RequestProcessorLoadMetricSource extends ObjectNamePatternLoadMetricSource
{
+ private static final String DEFAULT_PATTERN = "jboss.web:type=GlobalRequestProcessor,*";
+
/**
* Create a new GlobalRequestProcessorLoadMetricSource.
*
* @param registration
+ * @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration)
+ public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
{
- super(registration);
+ super(registration, DEFAULT_PATTERN);
}
+ /**
+ * Create a new GlobalRequestProcessorLoadMetricSource.
+ *
+ * @param registration
+ * @param pattern
+ * @throws MalformedObjectNameException
+ */
+ public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ {
+ super(registration, pattern);
+ }
/**
* Create a new GlobalRequestProcessorLoadMetricSource.
*
* @param registration
* @param server
+ * @throws MalformedObjectNameException
*/
- public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server)
+ public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, server);
+ super(registration, DEFAULT_PATTERN, server);
}
-
+
/**
- * @{inheritDoc}
- * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.ObjectNamePatternLoadMetricSource#defaultPropertyPattern()
+ * Create a new GlobalRequestProcessorLoadMetricSource.
+ *
+ * @param registration
+ * @param pattern
+ * @param server
+ * @throws MalformedObjectNameException
*/
- @Override
- protected String defaultPropertyPattern()
+ public RequestProcessorLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- // return "Catalina:type=GlobalRequestProcessor,name=*";
- // Java 1.5 only allows primitive ObjectName patterns
- return "type=GlobalRequestProcessor,*";
+ super(registration, pattern, server);
}
}
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SessionLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -22,6 +22,7 @@
package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
@@ -33,35 +34,53 @@
*/
public class SessionLoadMetricSource extends ObjectNamePatternLoadMetricSource
{
+ private static final String DEFAULT_PATTERN = "jboss.web:type=Manager,*";
+
/**
* Create a new SessionLoadMetricSource.
*
* @param registration
+ * @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration)
+ public SessionLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
{
- super(registration);
+ super(registration, DEFAULT_PATTERN);
}
+
+ /**
+ * Create a new SessionLoadMetricSource.
+ *
+ * @param registration
+ * @param pattern
+ * @throws MalformedObjectNameException
+ */
+ public SessionLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ {
+ super(registration, pattern);
+ }
/**
* Create a new SessionLoadMetricSource.
*
* @param registration
* @param server
+ * @throws MalformedObjectNameException
*/
- public SessionLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server)
+ public SessionLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, server);
+ super(registration, DEFAULT_PATTERN, server);
}
/**
- * @{inheritDoc}
- * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.ObjectNamePatternLoadMetricSource#defaultObjectNamePattern()
+ * Create a new SessionLoadMetricSource.
+ *
+ * @param registration
+ * @param pattern
+ * @param server
+ * @throws MalformedObjectNameException
*/
- @Override
- protected String defaultPropertyPattern()
+ public SessionLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- // Java 1.5 only allows primitive ObjectName patterns
- return "type=Manager,*";
+ super(registration, pattern, server);
}
}
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/SingleLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -43,20 +43,20 @@
/**
* @{inheritDoc}
- * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#open()
+ * @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#prepare()
*/
- public void open()
+ public void prepare()
{
- // Nothing to open
+ // Nothing to prepare
}
/**
* @{inheritDoc}
* @see org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSource#cleanup()
*/
- public void close()
+ public void cleanup()
{
- // Nothing to close
+ // Nothing to cleanup
}
/**
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-22 16:24:38 UTC (rev 77363)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/modcluster/load/metric/impl/ThreadPoolLoadMetricSource.java 2008-08-22 16:43:18 UTC (rev 77364)
@@ -22,6 +22,7 @@
package org.jboss.web.tomcat.service.modcluster.load.metric.impl;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import org.jboss.web.tomcat.service.modcluster.load.metric.LoadMetricSourceRegistration;
@@ -33,35 +34,53 @@
*/
public class ThreadPoolLoadMetricSource extends ObjectNamePatternLoadMetricSource
{
+ private static final String DEFAULT_PATTERN = "jboss.web:type=ThreadPool,*";
+
/**
* Create a new ThreadPoolLoadMetricSource.
*
* @param registration
+ * @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration)
+ public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration) throws MalformedObjectNameException
{
- super(registration);
+ super(registration, DEFAULT_PATTERN);
}
+
+ /**
+ * Create a new ThreadPoolLoadMetricSource.
+ *
+ * @param registration
+ * @param patterh
+ * @throws MalformedObjectNameException
+ */
+ public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern) throws MalformedObjectNameException
+ {
+ super(registration, pattern);
+ }
/**
* Create a new ThreadPoolLoadMetricSource.
*
* @param registration
* @param server
+ * @throws MalformedObjectNameException
*/
- public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server)
+ public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, MBeanServer server) throws MalformedObjectNameException
{
- super(registration, server);
+ super(registration, DEFAULT_PATTERN, server);
}
/**
- * @{inheritDoc}
- * @see org.jboss.web.tomcat.service.modcluster.load.metric.impl.ObjectNamePatternLoadMetricSource#defaultPropertyPattern()
+ * Create a new ThreadPoolLoadMetricSource.
+ *
+ * @param registration
+ * @param pattern
+ * @param server
+ * @throws MalformedObjectNameException
*/
- @Override
- protected String defaultPropertyPattern()
+ public ThreadPoolLoadMetricSource(LoadMetricSourceRegistration registration, String pattern, MBeanServer server) throws MalformedObjectNameException
{
- // Java 1.5 only allows primitive ObjectName patterns
- return "type=ThreadPool,*";
+ super(registration, pattern, server);
}
}
More information about the jboss-cvs-commits
mailing list