@@ -0,0 +1,1918 @@
+/*%0A * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0%0A * (the %22License%22). You may not use this work except in compliance with the License, which is%0A * available at www.apache.org/licenses/LICENSE-2.0%0A *%0A * This software is distributed on an %22AS IS%22 basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,%0A * either express or implied, as more fully set forth in the License.%0A *%0A * See the NOTICE file distributed with this work for information regarding copyright ownership.%0A */%0A%0Apackage alluxio.retry;%0A%0Aimport alluxio.util.CommonUtils;%0A%0Aimport com.google.common.base.Preconditions;%0A%0Aimport javax.annotation.concurrent.NotThreadSafe;%0A%0A/**%0A * An option which allows retrying based on a maximum retry timeout.%0A */%0A@NotThreadSafe%0Apublic class TimeoutRetry implements RetryPolicy %7B%0A%0A  private final long mRetryTimeoutMs;%0A  private final long mSleepMs;%0A  private long mStartMs = 0;%0A  private int mCount = 0;%0A%0A  /**%0A   * Constructs a retry facility which allows a maximum retry timeout.%0A   *%0A   * @param retryTimeoutMs maximum period of time to retry for, in milliseconds%0A   * @param sleepMs time in milliseconds to sleep before retrying%0A   */%0A  public TimeoutRetry(long retryTimeoutMs, int sleepMs) %7B%0A    Preconditions.checkArgument(retryTimeoutMs %3E 0, %22Retry timeout must be a positive number%22);%0A    Preconditions.checkArgument(sleepMs %3E= 0, %22sleepMs cannot be negative%22);%0A    mRetryTimeoutMs = retryTimeoutMs;%0A    mSleepMs = sleepMs;%0A  %7D%0A%0A  @Override%0A  public int getRetryCount() %7B%0A    return mCount;%0A  %7D%0A%0A  @Override%0A  public boolean attemptRetry() %7B%0A    if (mCount == 0) %7B%0A      // first attempt%0A      mStartMs = CommonUtils.getCurrentMs();%0A      mCount++;%0A      return true;%0A    %7D%0A%0A    if (mSleepMs %3E 0) %7B%0A      CommonUtils.sleepMs(mSleepMs);%0A    %7D%0A    if ((CommonUtils.getCurrentMs() - mStartMs) %3C= mRetryTimeoutMs) %7B%0A      mCount++;%0A      return true;%0A    %7D%0A    return false;%0A  %7D%0A%7D%0A

Add a timeout retry class