本文整理了Java中rx.Single.onErrorResumeNext()
方法的一些代码示例,展示了Single.onErrorResumeNext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.onErrorResumeNext()
方法的具体详情如下:
包路径:rx.Single
类名称:Single
方法名:onErrorResumeNext
暂无
代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway
static Single<DatabaseAccount> getDatabaseAccountFromAnyLocationsAsync(
URL defaultEndpoint, List<String> locations, Func1<URL, Single<DatabaseAccount>> getDatabaseAccountFn) {
return getDatabaseAccountFn.call(defaultEndpoint).onErrorResumeNext(
e -> {
logger.error("Fail to reach global gateway [{}], [{}]", defaultEndpoint, e.getMessage());
if (locations.isEmpty()) {
return Single.error(e);
}
rx.Observable<rx.Observable<DatabaseAccount>> obs = rx.Observable.range(0, locations.size())
.map(index -> getDatabaseAccountFn.call(LocationHelper.getLocationEndpoint(defaultEndpoint, locations.get(index))).toObservable());
// iterate and get the database account from the first non failure, otherwise get the last error.
rx.Observable<DatabaseAccount> res = rx.Observable.concatDelayError(obs).first().single();
return res.toSingle().doOnError(
innerE -> {
logger.error("Fail to reach location any of locations", String.join(",", locations), innerE.getMessage());
});
});
}
代码示例来源:origin: georocket/georocket
/**
* Check if the given URI exists by sending an empty request
* @param uri uri to check
* @return an observable emitting <code>true</code> if the request
* was successful or <code>false</code> otherwise
*/
private Single<Boolean> exists(String uri) {
return client.performRequest(HttpMethod.HEAD, uri)
.map(o -> true)
.onErrorResumeNext(t -> {
if (t instanceof HttpException && ((HttpException)t).getStatusCode() == 404) {
return Single.just(false);
}
return Single.error(t);
});
}
代码示例来源:origin: georocket/georocket
.flatMap(crs -> merger.merge(crs, p.getLeft(), out)
.onErrorResumeNext(t -> {
if (t instanceof IllegalStateException) {
代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway
private Single<DocumentCollection> ResolveByPartitionKeyRangeIdentityAsync(PartitionKeyRangeIdentity partitionKeyRangeIdentity) {
// if request is targeted at specific partition using x-ms-documentd-partitionkeyrangeid header,
// which contains value "<collectionrid>,<partitionkeyrangeid>", then resolve to collection rid in this header.
if (partitionKeyRangeIdentity != null && partitionKeyRangeIdentity.getCollectionRid() != null) {
return this.resolveByRidAsync(partitionKeyRangeIdentity.getCollectionRid())
.onErrorResumeNext(e -> {
if (e instanceof NotFoundException) {
// This is signal to the upper logic either to refresh
// collection cache and retry.
return Single.error(new InvalidPartitionException(RMResources.InvalidDocumentCollection));
}
return Single.error(e);
});
}
return Single.just(null);
}
代码示例来源:origin: org.jboss.hal/hal-dmr
@Override
public Completable call(FlowContext context) {
Operation operation = new Operation.Builder(address, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(operation)
.doOnSuccess(result -> context.push(200))
.onErrorResumeNext(throwable -> {
if (throwable instanceof DispatchFailure) {
context.push(404);
return Single.just(new ModelNode());
} else {
return Single.error(throwable);
}
})
.toCompletable();
}
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void test() throws Exception {
Observable.fromCallable(() -> { throw new IOException(); })
.toSingle()
.subscribeOn(Schedulers.computation())
.toObservable()
.toSingle()
.onErrorResumeNext(v -> Single.just(1))
.subscribe(System.out::println, Throwable::printStackTrace);
Thread.sleep(1000);
}
代码示例来源:origin: com.couchbase.client/core-io
.onErrorResumeNext(new Func1<Throwable, Single<? extends ChannelFuture>>() {
@Override
public Single<? extends ChannelFuture> call(Throwable throwable) {
代码示例来源:origin: couchbase/couchbase-jvm-core
.onErrorResumeNext(new Func1<Throwable, Single<? extends ChannelFuture>>() {
@Override
public Single<? extends ChannelFuture> call(Throwable throwable) {
代码示例来源:origin: io.vertx/vertx-rx-java
@Override
public Single<T> call(Single<T> upstream) {
return sqlConnection.rxSetAutoCommit(false).toCompletable()
.andThen(upstream)
.flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item)))
.onErrorResumeNext(throwable -> {
return sqlConnection.rxRollback().toCompletable().onErrorComplete()
.andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete())
.andThen(Single.error(throwable));
}).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item)));
}
}
代码示例来源:origin: vert-x3/vertx-rx
@Override
public Single<T> call(Single<T> upstream) {
return sqlConnection.rxSetAutoCommit(false).toCompletable()
.andThen(upstream)
.flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item)))
.onErrorResumeNext(throwable -> {
return sqlConnection.rxRollback().toCompletable().onErrorComplete()
.andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete())
.andThen(Single.error(throwable));
}).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item)));
}
}
内容来源于网络,如有侵权,请联系作者删除!