use of java.util.Random in project camel by apache.
the class ConsulKeyValueWatchTest method doPreSetup.
@Override
public void doPreSetup() {
key = generateKey();
client = getConsul().keyValueClient();
random = new Random();
}
use of java.util.Random in project camel by apache.
the class EhcacheTestSupport method generateRandomArrayOfInt.
protected static int[] generateRandomArrayOfInt(int size, int lower, int upper) {
Random random = new Random();
int[] array = new int[size];
Arrays.setAll(array, i -> random.nextInt(upper - lower) + lower);
return array;
}
use of java.util.Random in project camel by apache.
the class ExpressionBuilder method randomExpression.
/**
* Returns a random number between min and max
*/
public static Expression randomExpression(final int min, final int max) {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
Random random = new Random();
int randomNum = random.nextInt(max - min) + min;
return randomNum;
}
@Override
public String toString() {
return "random";
}
};
}
use of java.util.Random in project camel by apache.
the class ExpressionBuilder method randomExpression.
/**
* Returns a random number between min and max
*/
public static Expression randomExpression(final String min, final String max) {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
int num1 = simpleExpression(min).evaluate(exchange, Integer.class);
int num2 = simpleExpression(max).evaluate(exchange, Integer.class);
Random random = new Random();
int randomNum = random.nextInt(num2 - num1) + num1;
return randomNum;
}
@Override
public String toString() {
return "random";
}
};
}
use of java.util.Random in project camel by apache.
the class RedeliveryPolicy method calculateRedeliveryDelay.
/**
* Calculates the new redelivery delay based on the last one
*
* @param previousDelay previous redelivery delay
* @param redeliveryCounter number of previous redelivery attempts
* @return the calculate delay
*/
public long calculateRedeliveryDelay(long previousDelay, int redeliveryCounter) {
if (ObjectHelper.isNotEmpty(delayPattern)) {
// calculate delay using the pattern
return calculateRedeliverDelayUsingPattern(delayPattern, redeliveryCounter);
}
// calculate the delay using the conventional parameters
long redeliveryDelayResult;
if (previousDelay == 0) {
redeliveryDelayResult = redeliveryDelay;
} else if (useExponentialBackOff && backOffMultiplier > 1) {
redeliveryDelayResult = Math.round(backOffMultiplier * previousDelay);
} else {
redeliveryDelayResult = previousDelay;
}
if (useCollisionAvoidance) {
/*
* First random determines +/-, second random determines how far to
* go in that direction. -cgs
*/
Random random = getRandomNumberGenerator();
double variance = (random.nextBoolean() ? collisionAvoidanceFactor : -collisionAvoidanceFactor) * random.nextDouble();
redeliveryDelayResult += redeliveryDelayResult * variance;
}
// ensure the calculated result is not bigger than the max delay (if configured)
if (maximumRedeliveryDelay > 0 && redeliveryDelayResult > maximumRedeliveryDelay) {
redeliveryDelayResult = maximumRedeliveryDelay;
}
return redeliveryDelayResult;
}
Aggregations