Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1571714 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ok2c committed Feb 25, 2014
1 parent 5d11a3e commit 013ed18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.apache.http.impl.client.cache;

import org.apache.http.annotation.ThreadSafe;
import org.apache.http.util.Args;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
Expand All @@ -48,7 +49,8 @@
*
* The following equation is used to calculate the delay for a specific revalidation request:
* <pre>
* delay = {@link #getInitialExpiryInMillis()} * Math.pow({@link #getBackOffRate()}, {@link AsynchronousValidationRequest#getConsecutiveFailedAttempts()} - 1))
* delay = {@link #getInitialExpiryInMillis()} * Math.pow({@link #getBackOffRate()},
* {@link AsynchronousValidationRequest#getConsecutiveFailedAttempts()} - 1))
* </pre>
* The resulting delay won't exceed {@link #getMaxExpiryInMillis()}.
*
Expand Down Expand Up @@ -117,16 +119,16 @@ private static ScheduledThreadPoolExecutor createThreadPoolFromCacheConfig(
final long backOffRate,
final long initialExpiryInMillis,
final long maxExpiryInMillis) {
this.executor = checkNotNull("executor", executor);
this.backOffRate = checkNotNegative("backOffRate", backOffRate);
this.initialExpiryInMillis = checkNotNegative("initialExpiryInMillis", initialExpiryInMillis);
this.maxExpiryInMillis = checkNotNegative("maxExpiryInMillis", maxExpiryInMillis);
this.executor = Args.notNull(executor, "Executor");
this.backOffRate = Args.notNegative(backOffRate, "BackOffRate");
this.initialExpiryInMillis = Args.notNegative(initialExpiryInMillis, "InitialExpiryInMillis");
this.maxExpiryInMillis = Args.notNegative(maxExpiryInMillis, "MaxExpiryInMillis");
}

@Override
public void schedule(
final AsynchronousValidationRequest revalidationRequest) {
checkNotNull("revalidationRequest", revalidationRequest);
Args.notNull(revalidationRequest, "RevalidationRequest");
final int consecutiveFailedAttempts = revalidationRequest.getConsecutiveFailedAttempts();
final long delayInMillis = calculateDelayInMillis(consecutiveFailedAttempts);
executor.schedule(revalidationRequest, delayInMillis, TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -160,13 +162,21 @@ protected long calculateDelayInMillis(final int consecutiveFailedAttempts) {
}
}

/**
* @deprecated Use {@link org.apache.http.util.Args#notNull(Object, String)}
*/
@Deprecated
protected static <T> T checkNotNull(final String parameterName, final T value) {
if (value == null) {
throw new IllegalArgumentException(parameterName + " may not be null");
}
return value;
}

/**
* @deprecated Use {@link org.apache.http.util.Args#notNegative(long, String)}
*/
@Deprecated
protected static long checkNotNegative(final String parameterName, final long value) {
if (value < 0) {
throw new IllegalArgumentException(parameterName + " may not be negative");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.apache.http.impl.client.cache;

import org.apache.http.annotation.ThreadSafe;
import org.apache.http.util.Args;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -69,10 +70,7 @@ public ImmediateSchedulingStrategy(final CacheConfig cacheConfig) {

@Override
public void schedule(final AsynchronousValidationRequest revalidationRequest) {
if (revalidationRequest == null) {
throw new IllegalArgumentException("AsynchronousValidationRequest may not be null");
}

Args.notNull(revalidationRequest, "AsynchronousValidationRequest");
executor.execute(revalidationRequest);
}

Expand Down

0 comments on commit 013ed18

Please sign in to comment.