當前位置: 首頁>>代碼示例>>Java>>正文


Java RxJavaPlugins類代碼示例

本文整理匯總了Java中io.reactivex.plugins.RxJavaPlugins的典型用法代碼示例。如果您正苦於以下問題:Java RxJavaPlugins類的具體用法?Java RxJavaPlugins怎麽用?Java RxJavaPlugins使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RxJavaPlugins類屬於io.reactivex.plugins包,在下文中一共展示了RxJavaPlugins類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resultThrowingInOnSuccessDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:MaybeThrowingTest.java

示例2: onComplete

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override
public void onComplete(@NonNull Task<Void> task) {
    if (isDisposed()) return;
    if (!task.isSuccessful()) {
        Exception exception = task.getException();
        if (terminated) {
            RxJavaPlugins.onError(exception);
        } else {
            try {
                terminated = true;
                observer.onError(exception);
            } catch (Throwable t) {
                Exceptions.throwIfFatal(t);
                RxJavaPlugins.onError(new CompositeException(task.getException(), t));
            }
        }
    }
}
 
開發者ID:niqo01,項目名稱:RxTask,代碼行數:19,代碼來源:ObservableTaskCallback.java

示例3: schedule

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
    if (run == null) throw new NullPointerException("run == null");
    if (unit == null) throw new NullPointerException("unit == null");

    if (disposed) {
        return Disposables.disposed();
    }

    run = RxJavaPlugins.onSchedule(run);

    ScheduledRunnable scheduled = new ScheduledRunnable(handler, run);

    Message message = Message.obtain(handler, scheduled);
    message.obj = this; // Used as token for batch disposal of this worker's runnables.

    handler.sendMessageDelayed(message, Math.max(0L, unit.toMillis(delay)));

    // Re-check disposed state for removing in case we were racing a call to dispose().
    if (disposed) {
        handler.removeCallbacks(scheduled);
        return Disposables.disposed();
    }

    return scheduled;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:HandlerScheduler.java

示例4: directScheduleOnceWithDelayUsesHook

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test
public void directScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter, 1, MINUTES);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:HandlerSchedulerTest.java

示例5: workerScheduleOnceUsesHook

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test
public void workerScheduleOnceUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:HandlerSchedulerTest.java

示例6: workerScheduleOnceWithDelayUsesHook

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test
public void workerScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, 1, MINUTES);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:HandlerSchedulerTest.java

示例7: run

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override
public void run() {
    Runnable r = get();
    if (r != null && compareAndSet(r, null)) {
        try {
            try {
                r.run();
            } catch (Throwable ex) {
                Exceptions.throwIfFatal(ex);
                RxJavaPlugins.onError(ex);
            }
        } finally {
            remove(this);
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava2Swing,代碼行數:17,代碼來源:AsyncSwingScheduler.java

示例8: onResponse

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override public void onResponse(Call<T> call, Response<T> response) {
  if (call.isCanceled()) return;

  try {
    observer.onNext(response);

    if (!call.isCanceled()) {
      terminated = true;
      observer.onComplete();
    }
  } catch (Throwable t) {
    if (terminated) {
      RxJavaPlugins.onError(t);
    } else if (!call.isCanceled()) {
      try {
        observer.onError(t);
      } catch (Throwable inner) {
        Exceptions.throwIfFatal(inner);
        RxJavaPlugins.onError(new CompositeException(t, inner));
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:CallEnqueueObservable.java

示例9: subscribeActual

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override
protected void subscribeActual(MaybeObserver<? super T> s) {
    MaybeObserver<? super T> observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachMaybeObserver<>(observer, this.compositeDisposable));
}
 
開發者ID:cp949,項目名稱:DisposableAttach,代碼行數:19,代碼來源:AttachDisposableMaybe.java

示例10: subscribeActual

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> s) {
    SingleObserver<? super T> observer;
    try {
        observer = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachSingleObserver<>(observer, this.compositeDisposable));
}
 
開發者ID:cp949,項目名稱:DisposableAttach,代碼行數:19,代碼來源:AttachDisposableSingle.java

示例11: responseThrowingInOnSuccessDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:MaybeThrowingTest.java

示例12: throwingInOnCompleteDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void throwingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> errorRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!errorRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
      }
    }
  });

  RecordingCompletableObserver observer = observerRule.create();
  final RuntimeException e = new RuntimeException();
  service.completable().subscribe(new ForwardingCompletableObserver(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  assertThat(errorRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:CompletableThrowingTest.java

示例13: bodyThrowingInOnCompleteDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingObserver<String> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingObserver<String>(observer) {
    @Override public void onComplete() {
      throw e;
    }
  });

  observer.assertAnyValue();
  assertThat(throwableRef.get()).isSameAs(e);

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:ObservableThrowingTest.java

示例14: bodyThrowingInOnSuccessDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void bodyThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<String> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.body().subscribe(new ForwardingObserver<String>(observer) {
    @Override public void onSuccess(String value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:SingleThrowingTest.java

示例15: responseThrowingInOnSuccessDeliveredToPlugin

import io.reactivex.plugins.RxJavaPlugins; //導入依賴的package包/類
@Test public void responseThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
    @Override public void onSuccess(Response<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:SingleThrowingTest.java


注:本文中的io.reactivex.plugins.RxJavaPlugins類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。