|
8 | 8 | import java.util.concurrent.ExecutionException; |
9 | 9 | import java.util.concurrent.TimeUnit; |
10 | 10 | import java.util.stream.Collectors; |
| 11 | + |
11 | 12 | import com.google.common.annotations.VisibleForTesting; |
12 | 13 | import com.google.common.base.Ticker; |
13 | 14 | import com.google.common.cache.CacheBuilder; |
@@ -77,25 +78,22 @@ LoadingCache<ConfigProperty, String> getCache() { |
77 | 78 | public String load(@NonNull ConfigProperty key) { |
78 | 79 | TransientConfigException lastException = null; |
79 | 80 | for (int attempt = 0; attempt < MAX_TRANSIENT_RETRIES; attempt++) { |
80 | | - if (attempt > 0) { |
81 | | - try { |
82 | | - if (transientRetryDelayMs > 0) Thread.sleep(transientRetryDelayMs); |
83 | | - } catch (InterruptedException ie) { |
84 | | - Thread.currentThread().interrupt(); |
85 | | - throw new TransientConfigException("Config load for " + key.name() + " interrupted during retry", ie); |
86 | | - } |
87 | | - log.log(Level.WARNING, "Retrying config property {0}, attempt {1}/{2}", |
88 | | - new Object[]{key.name(), attempt + 1, MAX_TRANSIENT_RETRIES}); |
89 | | - } |
90 | 81 | try { |
91 | 82 | return delegate.getConfigPropertyAsOptional(key).orElse(NEGATIVE_VALUE); |
92 | 83 | } catch (TransientConfigException e) { |
93 | 84 | lastException = e; |
94 | | - log.log(Level.WARNING, "Transient failure on attempt {0}/{1} for config property {2}", |
95 | | - new Object[]{attempt + 1, MAX_TRANSIENT_RETRIES, key.name()}); |
| 85 | + log.log(Level.WARNING, String.format("Transient failure on attempt {0}/{1} for config property {2}", |
| 86 | + attempt + 1, MAX_TRANSIENT_RETRIES, key.name())); |
| 87 | + } |
| 88 | + try { |
| 89 | + if (transientRetryDelayMs > 0) |
| 90 | + Thread.sleep(transientRetryDelayMs); |
| 91 | + } catch (InterruptedException ie) { |
| 92 | + Thread.currentThread().interrupt(); |
| 93 | + throw new TransientConfigException("Config load for " + key.name() + " interrupted during retry", ie); |
96 | 94 | } |
97 | 95 | } |
98 | | - throw Objects.requireNonNull(lastException); |
| 96 | + throw lastException; |
99 | 97 | } |
100 | 98 |
|
101 | 99 | @Override |
|
0 commit comments