Author: pferraro
Date: 2008-10-24 13:50:17 -0400 (Fri, 24 Oct 2008)
New Revision: 1999
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java
Log:
Change meaning of history property to only encompass old values. i.e. history=0 means no
decay.
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-10-24
16:24:07 UTC (rev 1998)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-10-24
17:50:17 UTC (rev 1999)
@@ -29,9 +29,7 @@
import java.util.Map;
import java.util.Set;
-import org.apache.catalina.util.StringManager;
import org.jboss.logging.Logger;
-import org.jboss.modcluster.Constants;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
@@ -45,13 +43,12 @@
public class DynamicLoadBalanceFactorProvider implements LoadBalanceFactorProvider,
DynamicLoadBalanceFactorProviderMBean
{
private final Logger log = Logger.getLogger(this.getClass());
- private final StringManager sm = StringManager.getManager(Constants.Package);
private final Map<LoadMetricSource<LoadContext>,
Collection<LoadMetric<LoadContext>>> metrics = new
LinkedHashMap<LoadMetricSource<LoadContext>,
Collection<LoadMetric<LoadContext>>>();
private final Map<LoadMetric<LoadContext>, List<Double>> loadHistory
= new HashMap<LoadMetric<LoadContext>, List<Double>>();
private volatile int decayFactor = 2;
- private volatile int history = 10;
+ private volatile int history = 9;
public DynamicLoadBalanceFactorProvider(Set<LoadMetric<LoadContext>>
metrics)
{
@@ -139,18 +136,20 @@
if (queue == null)
{
- queue = new ArrayList<Double>(this.history);
+ queue = new ArrayList<Double>(this.history + 1);
this.loadHistory.put(metric, queue);
}
else
{
- for (int i = queue.size(); i >= this.history; --i)
+ // History could have changed, so prune queue accordingly
+ for (int i = (queue.size() - 1); i >= this.history; --i)
{
- queue.remove(i - 1);
+ queue.remove(i);
}
}
+ // Add new load to the front
queue.add(0, new Double(load));
return queue;
@@ -196,12 +195,7 @@
*/
public void setDecayFactor(int decayFactor)
{
- if (decayFactor <= 0)
- {
- throw new
IllegalArgumentException(this.sm.getString("modcluster.error.nonPositiveAttribute",
"decayFactor", String.valueOf(decayFactor)));
- }
-
- this.decayFactor = decayFactor;
+ this.decayFactor = Math.max(1, decayFactor);
}
/**
@@ -219,11 +213,6 @@
*/
public void setHistory(int history)
{
- if (history <= 0)
- {
- throw new
IllegalArgumentException(this.sm.getString("modcluster.error.nonPositiveAttribute",
"history", String.valueOf(history)));
- }
-
- this.history = history;
+ this.history = Math.max(0, history);
}
}
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-10-24
16:24:07 UTC (rev 1998)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-10-24
17:50:17 UTC (rev 1999)
@@ -36,7 +36,6 @@
/**
* Sets the number of historical load values to consider when calculating the load
balance factor.
* @param history
- * @throws IllegalArgumentException if specified value is not a positive number
*/
void setHistory(int history);
@@ -49,7 +48,6 @@
/**
* Sets the exponential decay factor to be applied to historical load values.
* @param decayFactor the new decay factor
- * @throws IllegalArgumentException if specified value is not a positive number
*/
void setDecayFactor(int decayFactor);
}
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java 2008-10-24
16:24:07 UTC (rev 1998)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/DynamicLoadBalanceFactorProviderTestCase.java 2008-10-24
17:50:17 UTC (rev 1999)
@@ -63,7 +63,7 @@
EasyMock.verify(this.metric1, this.metric2, this.metric3);
EasyMock.reset(this.metric1, this.metric2, this.metric3);
- this.provider.setHistory(2);
+ this.provider.setHistory(1);
}
@Test
Show replies by date