-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WFLY-3624 ConsistentHashFactory needs to be configurable via XML
Also add capacity-factor.
- Loading branch information
Showing
19 changed files
with
550 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
.../main/java/org/jboss/as/clustering/controller/validation/DoubleRangeValidatorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014, Red Hat, Inc., 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.as.clustering.controller.validation; | ||
|
||
import org.jboss.as.clustering.logging.ClusteringLogger; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.operations.validation.ModelTypeValidator; | ||
import org.jboss.as.controller.operations.validation.ParameterValidator; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
|
||
/** | ||
* A builder for creating a range validator for {@link ModelType#DOUBLE} parameters. | ||
* @author Paul Ferraro | ||
*/ | ||
public class DoubleRangeValidatorBuilder implements ParameterValidatorBuilder { | ||
private Bound upperBound; | ||
private Bound lowerBound; | ||
private boolean allowsUndefined = false; | ||
private boolean allowsExpression = false; | ||
|
||
/** | ||
* Sets an inclusive lower bound of this validator. | ||
* @param lowerBound the lower bound | ||
*/ | ||
public DoubleRangeValidatorBuilder lowerBound(double value) { | ||
this.lowerBound = new Bound(value, false); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets an exclusive lower bound of this validator. | ||
* @param lowerBound the lower bound | ||
*/ | ||
public DoubleRangeValidatorBuilder lowerBoundExclusive(double value) { | ||
this.lowerBound = new Bound(value, true); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the inclusive upper bound of this validator. | ||
* @param upperBound the upper bound | ||
*/ | ||
public DoubleRangeValidatorBuilder upperBound(double value) { | ||
this.upperBound = new Bound(value, false); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the exclusive upper bound of this validator. | ||
* @param upperBound the upper bound | ||
*/ | ||
public DoubleRangeValidatorBuilder upperBoundExclusive(double value) { | ||
this.upperBound = new Bound(value, true); | ||
return this; | ||
} | ||
|
||
/** | ||
* Indicates whether {@link ModelType#UNDEFINED} is allowed | ||
* @param allowsUndefined indicates whether {@link ModelType#UNDEFINED} is allowed | ||
*/ | ||
public DoubleRangeValidatorBuilder allowUndefined(boolean allowsUndefined) { | ||
this.allowsUndefined = allowsUndefined; | ||
return this; | ||
} | ||
|
||
/** | ||
* Indicates whether {@link ModelType#EXPRESSION} is allowed | ||
* @param allowExpressions whether {@link ModelType#EXPRESSION} is allowed | ||
*/ | ||
public DoubleRangeValidatorBuilder allowExpression(boolean allowsExpressions) { | ||
this.allowsExpression = allowsExpressions; | ||
return this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public ParameterValidator build() { | ||
return new DoubleRangeValidator(this.lowerBound, this.upperBound, this.allowsUndefined, this.allowsExpression); | ||
} | ||
|
||
private static class Bound { | ||
private final double value; | ||
private final boolean exclusive; | ||
|
||
Bound(double value, boolean exclusive) { | ||
this.value = value; | ||
this.exclusive = exclusive; | ||
} | ||
|
||
double getValue() { | ||
return this.value; | ||
} | ||
|
||
boolean isExclusive() { | ||
return this.exclusive; | ||
} | ||
} | ||
|
||
private class DoubleRangeValidator extends ModelTypeValidator { | ||
private final Bound lowerBound; | ||
private final Bound upperBound; | ||
|
||
/** | ||
* Creates an upper- and lower-bounded validator. | ||
* @param lowerBound the lower bound | ||
* @param lowerBound the upper bound | ||
* @param nullable indicates whether {@link ModelType#UNDEFINED} is allowed | ||
* @param allowExpressions whether {@link ModelType#EXPRESSION} is allowed | ||
*/ | ||
DoubleRangeValidator(Bound lowerBound, Bound upperBound, boolean nullable, boolean allowExpressions) { | ||
super(ModelType.DOUBLE, nullable, allowExpressions, false); | ||
this.lowerBound = lowerBound; | ||
this.upperBound = upperBound; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void validateParameter(String parameterName, ModelNode parameterValue) throws OperationFailedException { | ||
super.validateParameter(parameterName, parameterValue); | ||
if (parameterValue.isDefined() && parameterValue.getType() != ModelType.EXPRESSION) { | ||
double value = parameterValue.asDouble(); | ||
if (this.lowerBound != null) { | ||
double bound = this.lowerBound.getValue(); | ||
boolean exclusive = this.lowerBound.isExclusive(); | ||
if ((value < bound) || (exclusive && (value == bound))) { | ||
throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? ">" : ">=", bound); | ||
} | ||
} | ||
if (this.upperBound != null) { | ||
double bound = this.upperBound.getValue(); | ||
boolean exclusive = this.upperBound.isExclusive(); | ||
if ((value > bound) || (exclusive && (value == bound))) { | ||
throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? "<" : "<=", bound); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/org/jboss/as/clustering/controller/validation/ParameterValidatorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014, Red Hat, Inc., 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.as.clustering.controller.validation; | ||
|
||
import org.jboss.as.controller.operations.validation.ParameterValidator; | ||
|
||
public interface ParameterValidatorBuilder { | ||
/** | ||
* Builds the validator. | ||
* @return a parameter validator | ||
*/ | ||
ParameterValidator build(); | ||
} |
46 changes: 46 additions & 0 deletions
46
clustering/common/src/main/java/org/jboss/as/clustering/logging/ClusteringLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014, Red Hat, Inc., 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.as.clustering.logging; | ||
|
||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.logging.BasicLogger; | ||
import org.jboss.logging.Logger; | ||
import org.jboss.logging.annotations.Message; | ||
import org.jboss.logging.annotations.MessageLogger; | ||
|
||
/** | ||
* @author Paul Ferraro | ||
*/ | ||
@MessageLogger(projectCode = "WFLYCLCOM", length = 4) | ||
public interface ClusteringLogger extends BasicLogger { | ||
|
||
String ROOT_LOGGER_CATEGORY = "org.jboss.as.clustering"; | ||
|
||
/** | ||
* The root logger. | ||
*/ | ||
ClusteringLogger ROOT_LOGGER = Logger.getMessageLogger(ClusteringLogger.class, ROOT_LOGGER_CATEGORY); | ||
|
||
@Message(id = 1, value = "%2$g is not a valid value for parameter %1$s. The value must be %3$s %4$g") | ||
OperationFailedException parameterValueOutOfBounds(String name, double value, String relationalOperator, double bound); | ||
} |
69 changes: 69 additions & 0 deletions
69
...test/java/org/jboss/as/clustering/controller/validation/DoubleRangeValidatorTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014, Red Hat, Inc., 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.as.clustering.controller.validation; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.operations.validation.ParameterValidator; | ||
import org.jboss.dmr.ModelNode; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Paul Ferraro | ||
*/ | ||
public class DoubleRangeValidatorTestCase { | ||
|
||
@Test | ||
public void testFloat() { | ||
ParameterValidator validator = new DoubleRangeValidatorBuilder().lowerBound(Float.MIN_VALUE).upperBound(Float.MAX_VALUE).build(); | ||
assertFalse(isValid(validator, new ModelNode(Double.MAX_VALUE))); | ||
assertFalse(isValid(validator, new ModelNode(Double.MIN_VALUE))); | ||
assertTrue(isValid(validator, new ModelNode(Float.MAX_VALUE))); | ||
assertTrue(isValid(validator, new ModelNode(Float.MIN_VALUE))); | ||
} | ||
|
||
@Test | ||
public void testExclusive() { | ||
int lower = 0; | ||
ParameterValidator validator = new DoubleRangeValidatorBuilder().lowerBoundExclusive(lower).build(); | ||
assertFalse(isValid(validator, new ModelNode(0))); | ||
assertTrue(isValid(validator, new ModelNode(0.1))); | ||
assertTrue(isValid(validator, new ModelNode(Double.MAX_VALUE))); | ||
|
||
int upper = 1; | ||
validator = new DoubleRangeValidatorBuilder().upperBoundExclusive(upper).build(); | ||
assertTrue(isValid(validator, new ModelNode(Double.MIN_VALUE))); | ||
assertTrue(isValid(validator, new ModelNode(0.99))); | ||
assertFalse(isValid(validator, new ModelNode(1))); | ||
} | ||
|
||
static boolean isValid(ParameterValidator validator, ModelNode value) { | ||
try { | ||
validator.validateParameter("test", value); | ||
return true; | ||
} catch (OperationFailedException e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.