Skip to content

Commit

Permalink
minimally expose the RetryerBuilder used to create the Retryer instan…
Browse files Browse the repository at this point in the history
…ce (if one exists) #13
  • Loading branch information
rholder committed Jun 20, 2015
1 parent e90fe64 commit 2ddc1fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/main/java/com/github/rholder/retry/Retryer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class Retryer<V> {
private final AttemptTimeLimiter<V> attemptTimeLimiter;
private final Predicate<Attempt<V>> rejectionPredicate;
private final Collection<RetryListener> listeners;
private final RetryerBuilder<V> retryerBuilder;

/**
* Constructor
Expand Down Expand Up @@ -99,7 +100,7 @@ public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter,
@Nonnull WaitStrategy waitStrategy,
@Nonnull BlockStrategy blockStrategy,
@Nonnull Predicate<Attempt<V>> rejectionPredicate) {
this(attemptTimeLimiter, stopStrategy, waitStrategy, blockStrategy, rejectionPredicate, new ArrayList<RetryListener>());
this(attemptTimeLimiter, stopStrategy, waitStrategy, blockStrategy, rejectionPredicate, new ArrayList<RetryListener>(), null);
}

/**
Expand All @@ -120,6 +121,30 @@ public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter,
@Nonnull BlockStrategy blockStrategy,
@Nonnull Predicate<Attempt<V>> rejectionPredicate,
@Nonnull Collection<RetryListener> listeners) {
this(attemptTimeLimiter, stopStrategy, waitStrategy, blockStrategy, rejectionPredicate, listeners, null);
}


/**
* Constructor
*
* @param attemptTimeLimiter to prevent from any single attempt from spinning infinitely
* @param stopStrategy the strategy used to decide when the retryer must stop retrying
* @param waitStrategy the strategy used to decide how much time to sleep between attempts
* @param blockStrategy the strategy used to decide how to block between retry attempts; eg, Thread#sleep(), latches, etc.
* @param rejectionPredicate the predicate used to decide if the attempt must be rejected
* or not. If an attempt is rejected, the retryer will retry the call, unless the stop
* strategy indicates otherwise or the thread is interrupted.
* @param listeners collection of retry listeners
* @param retryerBuilder the builder used to create this instance, may be null
*/
public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter,
@Nonnull StopStrategy stopStrategy,
@Nonnull WaitStrategy waitStrategy,
@Nonnull BlockStrategy blockStrategy,
@Nonnull Predicate<Attempt<V>> rejectionPredicate,
@Nonnull Collection<RetryListener> listeners,
RetryerBuilder<V> retryerBuilder) {
Preconditions.checkNotNull(attemptTimeLimiter, "timeLimiter may not be null");
Preconditions.checkNotNull(stopStrategy, "stopStrategy may not be null");
Preconditions.checkNotNull(waitStrategy, "waitStrategy may not be null");
Expand All @@ -133,6 +158,7 @@ public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter,
this.blockStrategy = blockStrategy;
this.rejectionPredicate = rejectionPredicate;
this.listeners = listeners;
this.retryerBuilder = retryerBuilder;
}

/**
Expand Down Expand Up @@ -194,6 +220,16 @@ public RetryerCallable<V> wrap(Callable<V> callable) {
return new RetryerCallable<V>(this, callable);
}

/**
* Return the {@link RetryerBuilder} used to create this {@link Retryer}
* instance or null if no builder was used.
*
* @return the original {@link RetryerBuilder} used to create this instance
*/
public RetryerBuilder<V> getRetryerBuilder() {
return retryerBuilder;
}

@Immutable
static final class ResultAttempt<R> implements Attempt<R> {
private final R result;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/rholder/retry/RetryerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public Retryer<V> build() {
WaitStrategy theWaitStrategy = waitStrategy == null ? WaitStrategies.noWait() : waitStrategy;
BlockStrategy theBlockStrategy = blockStrategy == null ? BlockStrategies.threadSleepStrategy() : blockStrategy;

return new Retryer<V>(theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, rejectionPredicate, listeners);
return new Retryer<V>(theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, rejectionPredicate, listeners, this);
}

private static final class ExceptionClassPredicate<V> implements Predicate<Attempt<V>> {
Expand Down

0 comments on commit 2ddc1fd

Please sign in to comment.