Skip to content

Document new hook management facility #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DavidMGross opened this issue Jun 14, 2016 · 2 comments
Open

Document new hook management facility #262

DavidMGross opened this issue Jun 14, 2016 · 2 comments
Labels

Comments

@DavidMGross
Copy link
Collaborator

See ReactiveX/RxJava#4007

As of the filing of this issue, it's still in the planning/proposal stage, but if it gets merged, it'll need some documentation.

Hooks are currently documented over at the RxJava wiki (https://github.com/ReactiveX/RxJava/wiki/Plugins) but it's probably time to consolidate the RxJava documentation over here (see also #238).

@DavidMGross
Copy link
Collaborator Author

From the 1.1.7 release notes:

PR #4007 introduced a new way of hooking into the lifecycle of the base reactive types (Observable, Single, Completable) and the Schedulers. The original RxJavaPlugins' design was too much focused on class-initialization time hooking and didn't properly allow hooking up different behavior after that. There is a reset() available on it but sometimes that doesn't work as expected.

The new class rx.plugins.RxJavaHooks allows changing the hooks at runtime, allowing tests to temporarily hook onto an internal behavior and then un-hook once the test completed.

RxJavaHooks.setOnObservableCreate(s -> {
System.out.println("Observable created");
return s;
});

Observable.just(1).subscribe(System.out::println);

RxJavaHooks.reset();
// or
RxJavaHooks.setOnObservableCreate(null);
It is now also possible to override what Schedulers the Schedulers.computation(), .io() and .newThread() returns without the need to fiddle with Schedulers' own reset behavior:

RxJavaHooks.setOnComputationScheduler(current -> Schedulers.immediate());

Observable.just(1).subscribeOn(Schedulers.computation())
.subscribe(v -> System.out.println(Thread.currentThread()));
By default, all RxJavaHooks delegate to the original RxJavaPlugins callbacks so if you have hooks the old way, they still work. RxJavaHooks.reset() resets to this delegation and RxJavaHooks.clear() clears all hooks (i.e., everything becomes a pass-through hook).

@DavidMGross
Copy link
Collaborator Author

See also ReactiveX/RxJava#4173 for GenericScheduledExecutorService facility in RxJavaHooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant