public DefaultRetryPolicyFactory() { this( new FlexibleBoundedExponentialBackoffRetry( TimeUnit.MILLISECONDS.toNanos(125), TimeUnit.SECONDS.toNanos(10), 100, TimeUnit.MINUTES.toNanos(3))); }
@Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (currentPolicy == null) { return new FlexibleBoundedExponentialBackoffRetry(0, 0, 2, Long.MAX_VALUE); } else { return currentPolicy; } }
private RetryPolicyFactory getRetryTwicePolicyFactory() { return new RetryPolicyFactory() { @Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (currentPolicy == null) { return new FlexibleBoundedExponentialBackoffRetry(0, 0, 2, Long.MAX_VALUE); } else { return currentPolicy; } } }; }
public RetryPolicyFactory parse(Config retryPolicyConfig) { final Config boundedExponentialBackoffRetryConfig = new Configs().getConfig(retryPolicyConfig, BOUNDED_EXPONENTIAL_BACKOFF_RETRY_NAME); final long baseSleepTime = new Configs() .getNanoseconds(boundedExponentialBackoffRetryConfig, "baseSleepTime", TimeUnit.MILLISECONDS.toNanos(125)); final long maxSleepTime = new Configs() .getNanoseconds(boundedExponentialBackoffRetryConfig, "maxSleepTime", TimeUnit.SECONDS.toNanos(10)); final int maxRetries = new Configs() .getInt(boundedExponentialBackoffRetryConfig, "maxRetries", 100); final long maxElapsedTime = new Configs() .getNanoseconds(boundedExponentialBackoffRetryConfig, "maxElapsedTime", TimeUnit.SECONDS.toNanos(3 * 60)); LOG.debug("Parsed retry policy BoundedExponentialBackoffRetry with " + "baseSleepTime:{}, maxSleepTime:{}, maxRetries:{}, maxElapsedTime:{}", new Object[]{baseSleepTime, maxSleepTime, maxRetries, maxElapsedTime}); if (maxRetries <= 0 || maxElapsedTime <= 0) { return null; } return new DefaultRetryPolicyFactory( new FlexibleBoundedExponentialBackoffRetry(baseSleepTime, maxSleepTime, maxRetries, maxElapsedTime)); }
int maxRetries = 100; long maxElapsedTimeNanos = 5000; RetryPolicy policy = new FlexibleBoundedExponentialBackoffRetry( baseSleepTimeNanos, maxSleepNanos, maxRetries, maxElapsedTimeNanos); long elapsedTimeNanos = 10; policy = new FlexibleBoundedExponentialBackoffRetry( TimeUnit.SECONDS.toNanos(2), TimeUnit.SECONDS.toNanos(3), 100, TimeUnit.SECONDS.toNanos(4)); assertEquals( policy = new FlexibleBoundedExponentialBackoffRetry(0, 0, maxRetries, maxElapsedTimeNanos); sleeper = new CountingSleeper(); assertTrue(policy.allowRetry(0, elapsedTimeNanos, sleeper)); policy = new FlexibleBoundedExponentialBackoffRetry( Long.MAX_VALUE, Long.MAX_VALUE, maxRetries, maxElapsedTimeNanos); sleeper = new CountingSleeper(); new FlexibleBoundedExponentialBackoffRetry( -1, maxSleepNanos-1, maxRetries, maxElapsedTimeNanos); fail(); new FlexibleBoundedExponentialBackoffRetry( baseSleepTimeNanos, maxSleepNanos, -1, maxElapsedTimeNanos); fail(); new FlexibleBoundedExponentialBackoffRetry( baseSleepTimeNanos, baseSleepTimeNanos-1, maxRetries, maxElapsedTimeNanos); fail();
SolrClient solr = new RetryingSolrServer( failingSolrServer, new DefaultRetryPolicyFactory(new FlexibleBoundedExponentialBackoffRetry( TimeUnit.MILLISECONDS.toNanos(1), TimeUnit.MILLISECONDS.toNanos(1000),