本文整理了Java中rx.Single.retryWhen()
方法的一些代码示例,展示了Single.retryWhen()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.retryWhen()
方法的具体详情如下:
包路径:rx.Single
类名称:Single
方法名:retryWhen
暂无
代码示例来源:origin: georocket/georocket
/**
* Perform an HTTP request and convert the response to a JSON object
* @param method the HTTP method
* @param uri the request URI
* @param body the body to send in the request (may be {@code null})
* @return a single emitting the parsed response body (may be
* {@code null} if no body was received)
*/
public Single<JsonObject> performRequest(HttpMethod method, String uri, Buffer body) {
return performRequestNoRetry(method, uri, body).retryWhen(errors -> {
Observable<Throwable> o = errors.flatMap(error -> {
if (error instanceof HttpException) {
// immediately forward HTTP errors, don't retry
return Observable.error(error);
}
return Observable.just(error);
});
return RxUtils.makeRetry(5, 1000, log).call(o);
});
}
代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway
@SuppressWarnings("unused")
static private <T> Single<T> executeRetry(Func0<Single<T>> callbackMethod,
Func1<Exception, Single<Long>> callShouldRetry, Action1<Exception> preRetryCallback) {
return Single.defer(() -> {
return callbackMethod.call();
}).retryWhen(toRetryWhenFunc(callShouldRetry, preRetryCallback));
}
代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway
static public <T> Single<T> executeRetry(Func0<Single<T>> callbackMethod,
IRetryPolicy retryPolicy,
Action1<Throwable> preRetryCallback) {
return Single.defer(() -> {
// TODO: is defer required?
return callbackMethod.call();
}).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy));
}
代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway
static public <T> Single<T> executeRetry(Func0<Single<T>> callbackMethod,
IRetryPolicy retryPolicy) {
return Single.defer(() -> {
// TODO: is defer required?
return callbackMethod.call();
}).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy));
}
代码示例来源:origin: georocket/georocket
/**
* Wait 60 seconds or until Elasticsearch is up and running, whatever
* comes first
* @param client the client to use to check if Elasticsearch is running
* @return a Completable that will complete when Elasticsearch is running
*/
public Completable waitUntilElasticsearchRunning(
ElasticsearchClient client) {
final Throwable repeat = new NoStackTraceThrowable("");
return Single.defer(client::isRunning).flatMap(running -> {
if (!running) {
return Single.error(repeat);
}
return Single.just(running);
}).retryWhen(errors -> {
Observable<Throwable> o = errors.flatMap(t -> {
if (t == repeat) {
// Elasticsearch is still not up, retry
return Observable.just(t);
}
// forward error
return Observable.error(t);
});
// retry for 60 seconds
return RxUtils.makeRetry(60, 1000, null).call(o);
}).toCompletable();
}
内容来源于网络,如有侵权,请联系作者删除!