Java Code Examples for io.reactivex.plugins.RxJavaPlugins#setOnObservableAssembly()

The following examples show how to use io.reactivex.plugins.RxJavaPlugins#setOnObservableAssembly() . 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: RxJavaAssemblyTracking.java    From RxJava2Debug with Apache License 2.0 6 votes vote down vote up
/**
 * Disable the assembly tracking.
 */
public static void disable() {
    if (lock.compareAndSet(false, true)) {

        RxJavaPlugins.setOnCompletableAssembly(null);
        RxJavaPlugins.setOnSingleAssembly(null);
        RxJavaPlugins.setOnMaybeAssembly(null);

        RxJavaPlugins.setOnObservableAssembly(null);
        RxJavaPlugins.setOnFlowableAssembly(null);
        RxJavaPlugins.setOnConnectableObservableAssembly(null);
        RxJavaPlugins.setOnConnectableFlowableAssembly(null);

        RxJavaPlugins.setOnParallelAssembly(null);

        lock.set(false);
    }
}
 
Example 2
Source File: AssemblyHooksExample.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
RxJavaPlugins.setOnObservableAssembly(o -> {
    if (o instanceof ObservableFromArray) {
        return new ObservableFromArray<>(new Integer[] { 4, 5, 6 });
    }
    return o;
});

Observable.just(1, 2, 3)
.filter(v -> v > 3)
.test()
.assertResult(4, 5, 6);

RxJavaPlugins.setOnObservableAssembly(null);
}
 
Example 3
Source File: RequestContextAssembly.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Disable {@link RequestContext} during operators.
 */
public static synchronized void disable() {
    if (!enabled) {
        return;
    }
    RxJavaPlugins.setOnObservableAssembly(oldOnObservableAssembly);
    oldOnObservableAssembly = null;
    RxJavaPlugins.setOnConnectableObservableAssembly(oldOnConnectableObservableAssembly);
    oldOnConnectableObservableAssembly = null;
    RxJavaPlugins.setOnCompletableAssembly(oldOnCompletableAssembly);
    oldOnCompletableAssembly = null;
    RxJavaPlugins.setOnSingleAssembly(oldOnSingleAssembly);
    oldOnSingleAssembly = null;
    RxJavaPlugins.setOnMaybeAssembly(oldOnMaybeAssembly);
    oldOnMaybeAssembly = null;
    RxJavaPlugins.setOnFlowableAssembly(oldOnFlowableAssembly);
    oldOnFlowableAssembly = null;
    RxJavaPlugins.setOnConnectableFlowableAssembly(oldOnConnectableFlowableAssembly);
    oldOnConnectableFlowableAssembly = null;
    RxJavaPlugins.setOnParallelAssembly(oldOnParallelAssembly);
    oldOnParallelAssembly = null;
    enabled = false;
}
 
Example 4
Source File: HelperTest.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Test
public void testToObservableAssemblyHook() {
  FakeStream<String> stream = new FakeStream<>();
  try {
    final Observable<String> justMe = Observable.just("me");
    RxJavaPlugins.setOnObservableAssembly(new Function<Observable, Observable>() {
      @Override public Observable apply(Observable f) {
        return justMe;
      }
    });
    Observable<String> observable = ObservableHelper.toObservable(stream);
    assertSame(observable, justMe);
    Observable<String> observableFn = ObservableHelper.toObservable(stream, identity());
    assertSame(observableFn, justMe);
  } finally {
    RxJavaPlugins.reset();
  }
}
 
Example 5
Source File: RxJavaHooksUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenObservable_whenAssembled_shouldExecuteTheHook() {

    RxJavaPlugins.setOnObservableAssembly(observable -> {
        hookCalled = true;
        return observable;
    });

    Observable.range(1, 10);
    assertTrue(hookCalled);
}
 
Example 6
Source File: CurrentTraceContextAssemblyTracking.java    From brave with Apache License 2.0 5 votes vote down vote up
/** Disables the validation hooks be resetting the assembled hooks to none. */
public static void disable() {
  RxJavaPlugins.setOnCompletableAssembly(null);
  RxJavaPlugins.setOnSingleAssembly(null);
  RxJavaPlugins.setOnMaybeAssembly(null);
  RxJavaPlugins.setOnObservableAssembly(null);
  RxJavaPlugins.setOnFlowableAssembly(null);

  RxJavaPlugins.setOnConnectableObservableAssembly(null);
  RxJavaPlugins.setOnConnectableFlowableAssembly(null);

  RxJavaPlugins.setOnParallelAssembly(null);

  enabled = false;
}