1 package com.atlassian.asap.core.keys.publickey;
2
3 import com.google.common.base.Preconditions;
4 import org.apache.http.HttpResponse;
5 import org.apache.http.client.ServiceUnavailableRetryStrategy;
6 import org.apache.http.protocol.HttpContext;
7
8
9
10
11
12
13
14
15
16
17
18 public class S3ServiceUnavailableRetryStrategy implements ServiceUnavailableRetryStrategy {
19 private final int maxRetries;
20 private final long retryInterval;
21
22
23
24
25
26 public S3ServiceUnavailableRetryStrategy(int maxRetries, long retryInterval) {
27 Preconditions.checkArgument(maxRetries >= 0, "maxRetries must be non-negative");
28 Preconditions.checkArgument(retryInterval >= 0, "retryInterval must be non-negative");
29
30 this.maxRetries = maxRetries;
31 this.retryInterval = retryInterval;
32 }
33
34 @Override
35 public boolean retryRequest(HttpResponse response, int executionCount, HttpContext context) {
36 return response.getStatusLine().getStatusCode() / 100 == 5 &&
37 executionCount <= maxRetries;
38 }
39
40 @Override
41 public long getRetryInterval() {
42 return retryInterval;
43 }
44 }