本文整理匯總了Java中io.reactivex.plugins.RxJavaPlugins.setInitIoSchedulerHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java RxJavaPlugins.setInitIoSchedulerHandler方法的具體用法?Java RxJavaPlugins.setInitIoSchedulerHandler怎麽用?Java RxJavaPlugins.setInitIoSchedulerHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.plugins.RxJavaPlugins
的用法示例。
在下文中一共展示了RxJavaPlugins.setInitIoSchedulerHandler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import io.reactivex.plugins.RxJavaPlugins; //導入方法依賴的package包/類
/**
* Registers an {@link RxJavaPlugins#errorHandler} with RxJava that provides a default error handling strategy of forwarding exceptions to the execution error handler.
* <p>
* This method is idempotent.
* It only needs to be called once per JVM, regardless of how many Ratpack applications are running within the JVM.
* <p>
* For a Java application, a convenient place to call this is in the handler factory implementation.
* <pre class="java">{@code
* import ratpack.error.ServerErrorHandler;
* import ratpack.rx.RxRatpack;
* import ratpack.test.embed.EmbeddedApp;
* import rx.Observable;
* import static org.junit.Assert.assertEquals;
* <p>
* public class Example {
* public static void main(String... args) throws Exception {
* RxRatpack.initialize(); // must be called once for the life of the JVM
* <p>
* EmbeddedApp.fromHandlers(chain -> chain
* .register(s -> s
* .add(ServerErrorHandler.class, (ctx, throwable) ->
* ctx.render("caught by error handler: " + throwable.getMessage())
* )
* )
* .get(ctx -> Observable.<String>error(new Exception("!")).subscribe(ctx::render))
* ).test(httpClient ->
* assertEquals("caught by error handler: !", httpClient.getText())
* );
* }
* }
* }</pre>
*/
@SuppressWarnings("unchecked")
public static void initialize() {
RxJavaPlugins.setErrorHandler(new ErrorHandler());
RxJavaPlugins.setInitComputationSchedulerHandler(c -> DefaultSchedulers.getComputationScheduler());
RxJavaPlugins.setInitIoSchedulerHandler(c -> DefaultSchedulers.getIoScheduler());
RxJavaPlugins.setOnObservableSubscribe((observable, observer) -> new ExecutionBackedObserver<>(observer));
RxJavaPlugins.setOnFlowableSubscribe(((flowable, subscriber) -> new ExecutionBackedSubscriber<>(subscriber)));
}