当前位置: 首页>>代码示例>>Java>>正文


Java Flowable.fromCallable方法代码示例

本文整理汇总了Java中io.reactivex.Flowable.fromCallable方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.fromCallable方法的具体用法?Java Flowable.fromCallable怎么用?Java Flowable.fromCallable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Flowable的用法示例。


在下文中一共展示了Flowable.fromCallable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: callReact

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * This method prepares and executes a reactive based REST communication
 *
 * @param httpRequest,
 *            a prepared {@link HttpRequest} used for api call
 * @param consumerOnSuccess,
 *            the provided consumer that react to http response
 * @param consumerOnError,
 *            the provided consumer that react to http error
 * @param attempts,
 *            the number of attempts to test if an error occurs during the api
 *            call
 */
public static void callReact(HttpRequest httpRequest,
		io.reactivex.functions.Consumer<HttpResponse> consumerOnSuccess,
		io.reactivex.functions.Consumer<Throwable> consumerOnError, int attempts) {
	if (consumerOnSuccess == null) {
		LOGGER.error("Reactive consumer on success cannot be null");
		return;
	}
	// prepare flowable to handle async response
	Flowable<HttpResponse> flowable = Flowable.fromCallable(() -> RestService.callSync(httpRequest, attempts));
	new Thread(() -> {
		if (consumerOnError == null) {
			LOGGER.debug("No consumer on error specified, using a default one");
			flowable.subscribe(consumerOnSuccess, err -> {
                   // unhandled event
                   LOGGER.error("Default consumer onError has received: " + err.getMessage());
               });
		} else {
			flowable.subscribe(consumerOnSuccess, consumerOnError);
		}
		flowable.publish();
	}).start();
}
 
开发者ID:lucapompei,项目名称:ReactiveRest,代码行数:36,代码来源:RestService.java

示例2: getResponse

import io.reactivex.Flowable; //导入方法依赖的package包/类
private Flowable<Response> getResponse(final HttpUrl url) {
    return Flowable.fromCallable(new Callable<Response>() {
        @Override
        public Response call() throws Exception {
            System.out.println(url);
            Request request = ServiceInjector.resolve(ServiceConfiguration.class).getRequestBuilder()
                    .url(url)
                    .build();
            return ServiceInjector.resolve(OkHttpClient.class).newCall(request).execute();
        }
    });
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:13,代码来源:RxEndpointsImpl.java

示例3: getResponseFromPost

import io.reactivex.Flowable; //导入方法依赖的package包/类
private Flowable<Response> getResponseFromPost(final HttpUrl url, final String body) {
    return Flowable.fromCallable(new Callable<Response>() {
        @Override
        public Response call() throws Exception {
            System.out.println(url);
            Request request = ServiceInjector.resolve(ServiceConfiguration.class).getRequestBuilder()
                    .post(RequestBody.create(MediaType.parse("application/json"), body))
                    .url(url)
                    .build();
            return ServiceInjector.resolve(OkHttpClient.class).newCall(request).execute();
        }
    });
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:14,代码来源:RxEndpointsImpl.java

示例4: apply

import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Flowable<String> apply(final Response response) {
    return Flowable.fromCallable(new Callable<String>() {
        @Override
        public String call() throws Exception {
            if (!response.isSuccessful()) {
                throw new IOException(response.message());
            }
            String responseString = response.body().string();
            System.out.println(responseString);
            return responseString;
        }
    });
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:15,代码来源:RxEndpointsImpl.java

示例5: processAsync

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * This method leverages the {@link #process(List)} method to asynchronously)}
 *   handle the dataset
 *
 * @param datasource dataset that should be processed
 */
default Flowable<List<List<Transmutation>>> processAsync(List<T> datasource) {
    return Flowable.fromCallable(() -> process(datasource));
}
 
开发者ID:salesforce,项目名称:pyplyn,代码行数:10,代码来源:ExtractProcessor.java

示例6: processAsync

import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
 * This method leverages the {@link #process(List, List)} method to asynchronously)}
 *   load data to the dataset
 *
 * @param data dataset that should be processed
 * @param destinations where the data should be loaded to
 */
default Flowable<List<Boolean>> processAsync(List<Transmutation> data, List<T> destinations) {
    return Flowable.fromCallable(() -> process(data, destinations));
}
 
开发者ID:salesforce,项目名称:pyplyn,代码行数:11,代码来源:LoadProcessor.java


注:本文中的io.reactivex.Flowable.fromCallable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。