Code cleanups

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1571714 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-02-25 14:45:14 +00:00
parent 5d11a3e751
commit 013ed18c5c
2 changed files with 18 additions and 10 deletions

View File

@ -27,6 +27,7 @@
package org.apache.http.impl.client.cache; package org.apache.http.impl.client.cache;
import org.apache.http.annotation.ThreadSafe; import org.apache.http.annotation.ThreadSafe;
import org.apache.http.util.Args;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -48,7 +49,8 @@ import java.util.concurrent.TimeUnit;
* *
* The following equation is used to calculate the delay for a specific revalidation request: * The following equation is used to calculate the delay for a specific revalidation request:
* <pre> * <pre>
* delay = {@link #getInitialExpiryInMillis()} * Math.pow({@link #getBackOffRate()}, {@link AsynchronousValidationRequest#getConsecutiveFailedAttempts()} - 1)) * delay = {@link #getInitialExpiryInMillis()} * Math.pow({@link #getBackOffRate()},
* {@link AsynchronousValidationRequest#getConsecutiveFailedAttempts()} - 1))
* </pre> * </pre>
* The resulting delay won't exceed {@link #getMaxExpiryInMillis()}. * The resulting delay won't exceed {@link #getMaxExpiryInMillis()}.
* *
@ -117,16 +119,16 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
final long backOffRate, final long backOffRate,
final long initialExpiryInMillis, final long initialExpiryInMillis,
final long maxExpiryInMillis) { final long maxExpiryInMillis) {
this.executor = checkNotNull("executor", executor); this.executor = Args.notNull(executor, "Executor");
this.backOffRate = checkNotNegative("backOffRate", backOffRate); this.backOffRate = Args.notNegative(backOffRate, "BackOffRate");
this.initialExpiryInMillis = checkNotNegative("initialExpiryInMillis", initialExpiryInMillis); this.initialExpiryInMillis = Args.notNegative(initialExpiryInMillis, "InitialExpiryInMillis");
this.maxExpiryInMillis = checkNotNegative("maxExpiryInMillis", maxExpiryInMillis); this.maxExpiryInMillis = Args.notNegative(maxExpiryInMillis, "MaxExpiryInMillis");
} }
@Override @Override
public void schedule( public void schedule(
final AsynchronousValidationRequest revalidationRequest) { final AsynchronousValidationRequest revalidationRequest) {
checkNotNull("revalidationRequest", revalidationRequest); Args.notNull(revalidationRequest, "RevalidationRequest");
final int consecutiveFailedAttempts = revalidationRequest.getConsecutiveFailedAttempts(); final int consecutiveFailedAttempts = revalidationRequest.getConsecutiveFailedAttempts();
final long delayInMillis = calculateDelayInMillis(consecutiveFailedAttempts); final long delayInMillis = calculateDelayInMillis(consecutiveFailedAttempts);
executor.schedule(revalidationRequest, delayInMillis, TimeUnit.MILLISECONDS); executor.schedule(revalidationRequest, delayInMillis, TimeUnit.MILLISECONDS);
@ -160,6 +162,10 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
} }
} }
/**
* @deprecated Use {@link org.apache.http.util.Args#notNull(Object, String)}
*/
@Deprecated
protected static <T> T checkNotNull(final String parameterName, final T value) { protected static <T> T checkNotNull(final String parameterName, final T value) {
if (value == null) { if (value == null) {
throw new IllegalArgumentException(parameterName + " may not be null"); throw new IllegalArgumentException(parameterName + " may not be null");
@ -167,6 +173,10 @@ public class ExponentialBackOffSchedulingStrategy implements SchedulingStrategy
return value; return value;
} }
/**
* @deprecated Use {@link org.apache.http.util.Args#notNegative(long, String)}
*/
@Deprecated
protected static long checkNotNegative(final String parameterName, final long value) { protected static long checkNotNegative(final String parameterName, final long value) {
if (value < 0) { if (value < 0) {
throw new IllegalArgumentException(parameterName + " may not be negative"); throw new IllegalArgumentException(parameterName + " may not be negative");

View File

@ -27,6 +27,7 @@
package org.apache.http.impl.client.cache; package org.apache.http.impl.client.cache;
import org.apache.http.annotation.ThreadSafe; import org.apache.http.annotation.ThreadSafe;
import org.apache.http.util.Args;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -69,10 +70,7 @@ public class ImmediateSchedulingStrategy implements SchedulingStrategy {
@Override @Override
public void schedule(final AsynchronousValidationRequest revalidationRequest) { public void schedule(final AsynchronousValidationRequest revalidationRequest) {
if (revalidationRequest == null) { Args.notNull(revalidationRequest, "AsynchronousValidationRequest");
throw new IllegalArgumentException("AsynchronousValidationRequest may not be null");
}
executor.execute(revalidationRequest); executor.execute(revalidationRequest);
} }