本文整理汇总了Java中com.github.rholder.retry.RetryerBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java RetryerBuilder.build方法的具体用法?Java RetryerBuilder.build怎么用?Java RetryerBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.rholder.retry.RetryerBuilder
的用法示例。
在下文中一共展示了RetryerBuilder.build方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRetryer
import com.github.rholder.retry.RetryerBuilder; //导入方法依赖的package包/类
/**
* Build Retryer.
* - If Writer implements Retriable, it will use the RetryerBuilder from the writer.
* - Otherwise, it will use DEFAULT writer builder.
*
* - If Gobblin metrics is enabled, it will emit all failure count in to metrics.
*
* @param state
* @return
*/
private Retryer<Void> buildRetryer(State state) {
RetryerBuilder<Void> builder = null;
if (writer instanceof Retriable) {
builder = ((Retriable) writer).getRetryerBuilder();
} else {
builder = createRetryBuilder(state);
}
if (GobblinMetrics.isEnabled(state)) {
final Optional<Meter> retryMeter = Optional.of(Instrumented.getMetricContext(state, getClass()).meter(FAILED_RETRY_WRITES_METER));
builder.withRetryListener(new RetryListener() {
@Override
public <V> void onRetry(Attempt<V> attempt) {
if (attempt.hasException()) {
LOG.warn("Caught exception. This may be retried.", attempt.getExceptionCause());
Instrumented.markMeter(retryMeter);
failedWrites++;
}
}
});
}
return builder.build();
}
示例2: retry
import com.github.rholder.retry.RetryerBuilder; //导入方法依赖的package包/类
/**
* Attempt to make a call, retrying on timeout
* @param times
* @param callable
* @return
* @throws ExecutionException
* @throws RetryException
*/
public static <T> T retry(int times, Callable<T> callable) throws ExecutionException, RetryException {
// Build the retryer
RetryerBuilder<T> builder = RetryerBuilder.newBuilder();
builder.withStopStrategy(StopStrategies.stopAfterAttempt(times));
builder.withWaitStrategy(WaitStrategies.randomWait(2, TimeUnit.SECONDS, 20, TimeUnit.SECONDS));
Retryer<T> retryer = builder.build();
return retryer.call(callable);
}
示例3: init
import com.github.rholder.retry.RetryerBuilder; //导入方法依赖的package包/类
@Override
protected Retryer<Boolean> init(final RetryerBuilder<Boolean> builder) {
builder.retryIfResult(Predicates.or(Predicates.isNull(), Predicates.equalTo(false)));
return builder.build();
}