Slide 20
Slide 20 text
public Response intercept(Chain chain) throws IOException {
long delay = minRequestDelay;
if( minRequestDelay != maxRequestDelay ) {
delay = (long) ((random.nextDouble() * (maxRequestDelay -
minRequestDelay)) + minRequestDelay);
}
long end = System.currentTimeMillis() + delay;
long now = System.currentTimeMillis();
while( now < end ) {
try {
Thread.sleep( end - now);
} catch (InterruptedException e) {
// Nothing to do here, timing controlled by outer loop.
}
now = System.currentTimeMillis();
}
return chain.proceed(chain.request());
}