use of java.util.Random in project camel by apache.
the class OptimisticLockRetryPolicy method doDelay.
public void doDelay(final int retryCounter) throws InterruptedException {
if (retryDelay > 0 || randomBackOff) {
long sleepFor;
sleepFor = exponentialBackOff ? (retryDelay << retryCounter) : (randomBackOff ? new Random().nextInt((int) (maximumRetryDelay > 0 ? maximumRetryDelay : DEFAULT_MAXIMUM_RETRY_DELAY)) : retryDelay);
if (maximumRetryDelay > 0 && sleepFor > maximumRetryDelay) {
sleepFor = maximumRetryDelay;
}
Thread.sleep(sleepFor);
}
}
use of java.util.Random in project camel by apache.
the class FileAsyncStressManually method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:target/filestress?readLock=markerFile&maxMessagesPerPoll=25&move=backup").threads(10).process(new Processor() {
public void process(Exchange exchange) throws Exception {
// simulate some work with random time to complete
Random ran = new Random();
int delay = ran.nextInt(500) + 10;
Thread.sleep(delay);
}
}).to("mock:result");
}
};
}
use of java.util.Random in project camel by apache.
the class FileAsyncStressReadLockNoneTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// leverage the fact that we can limit to max 50 files per poll
// this will result in polling again and potentially picking up files
// that already are in progress
from("file:target/filestress?maxMessagesPerPoll=50&readLock=none").routeId("foo").noAutoStartup().threads(10).process(new Processor() {
public void process(Exchange exchange) throws Exception {
// simulate some work with random time to complete
Random ran = new Random();
int delay = ran.nextInt(250) + 10;
Thread.sleep(delay);
}
}).to("mock:result");
}
};
}
use of java.util.Random in project camel by apache.
the class FileAsyncStressReadLockRenameTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// leverage the fact that we can limit to max 50 files per poll
// this will result in polling again and potentially picking up files
// that already are in progress
from("file:target/filestress?maxMessagesPerPoll=50&readLock=rename").routeId("foo").noAutoStartup().threads(10).process(new Processor() {
public void process(Exchange exchange) throws Exception {
// simulate some work with random time to complete
Random ran = new Random();
int delay = ran.nextInt(250) + 10;
Thread.sleep(delay);
}
}).to("mock:result");
}
};
}
use of java.util.Random in project camel by apache.
the class FileAsyncStressTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// leverage the fact that we can limit to max 50 files per poll
// this will result in polling again and potentially picking up files
// that already are in progress
from("file:target/filestress?maxMessagesPerPoll=50").routeId("foo").noAutoStartup().threads(10).process(new Processor() {
public void process(Exchange exchange) throws Exception {
// simulate some work with random time to complete
Random ran = new Random();
int delay = ran.nextInt(50) + 10;
Thread.sleep(delay);
}
}).to("mock:result");
}
};
}
Aggregations