Java Code Examples for io.reactivex.Flowable#onErrorResumeNext()

The following examples show how to use io.reactivex.Flowable#onErrorResumeNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AWSParameterStoreConfigClient.java    From micronaut-aws with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Parameter hierarchy from AWS parameter store.
 * Please note this only returns something if the current node has children and will not return itself.
 *
 *
 * @param path path based on the parameter names PRIORITY_TOP.e. /config/application/.*
 * @param nextToken token to paginate in the resultset from AWS
 * @return Publisher for GetParametersByPathResult
 */
private Publisher<GetParametersByPathResult> getHierarchy(String path, String nextToken) {
    LOG.trace("Retrieving parameters by path {}, pagination requested: {}", path, nextToken != null);
    GetParametersByPathRequest getRequest = new GetParametersByPathRequest()
            .withWithDecryption(awsParameterStoreConfiguration.getUseSecureParameters())
            .withPath(path)
            .withRecursive(true)
            .withNextToken(nextToken);

    Future<GetParametersByPathResult> future = client.getParametersByPathAsync(getRequest);

    Flowable<GetParametersByPathResult> invokeFlowable;
    if (executorService != null) {
        invokeFlowable = Flowable.fromFuture(future, Schedulers.from(executorService));
    } else {
        invokeFlowable = Flowable.fromFuture(future);
    }

    return invokeFlowable.onErrorResumeNext(AWSParameterStoreConfigClient::onGetParametersByPathResult);
}
 
Example 2
Source File: AWSParameterStoreConfigClient.java    From micronaut-aws with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameters from AWS.
 *
 * @param path this is the hierarchy path (via name field) from the property store
 * @return invokeFlowable - converted future from AWS SDK Async
 */
private Publisher<GetParametersResult> getParameters(String path) {

    GetParametersRequest getRequest = new GetParametersRequest().withWithDecryption(awsParameterStoreConfiguration.getUseSecureParameters()).withNames(path);

    Future<GetParametersResult> future = client.getParametersAsync(getRequest);

    Flowable<GetParametersResult> invokeFlowable;
    if (executorService != null) {
        invokeFlowable = Flowable.fromFuture(future, Schedulers.from(executorService));
    } else {
        invokeFlowable = Flowable.fromFuture(future);
    }

    return invokeFlowable.onErrorResumeNext(AWSParameterStoreConfigClient::onGetParametersError);
}
 
Example 3
Source File: RxCacheHelper.java    From RxCache with Apache License 2.0 6 votes vote down vote up
public static <T> Flowable<CacheResult<T>> loadRemoteSyncFlowable(final RxCache rxCache, final String key, final Flowable<T> source, final CacheTarget target, final boolean needEmpty) {
    Flowable<CacheResult<T>> flowable = source
            .flatMap(new Function<T, Publisher<CacheResult<T>>>() {
                @Override
                public Publisher<CacheResult<T>> apply(@NonNull T t) throws Exception {
                    return saveCacheSyncFlowable(rxCache, key, t, target);
                }
            });
    if (needEmpty) {
        flowable = flowable.onErrorResumeNext(new Function<Throwable, Publisher<? extends CacheResult<T>>>() {
            @Override
            public Publisher<? extends CacheResult<T>> apply(@NonNull Throwable throwable) throws Exception {
                return Flowable.empty();
            }
        });
    }
    return flowable;
}
 
Example 4
Source File: RxCacheHelper.java    From RxCache with Apache License 2.0 5 votes vote down vote up
public static <T> Flowable<CacheResult<T>> loadCacheFlowable(final RxCache rxCache, final String key, Type type, final boolean needEmpty) {
    Flowable<CacheResult<T>> flowable = rxCache.load2Flowable(key, type);
    if (needEmpty) {
        flowable = flowable
                .onErrorResumeNext(new Function<Throwable, Publisher<? extends CacheResult<T>>>() {
                    @Override
                    public Publisher<? extends CacheResult<T>> apply(@NonNull Throwable throwable) throws Exception {
                        return Flowable.empty();
                    }
                });
    }
    return flowable;
}