本文整理汇总了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);
}
示例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));
}
}
}
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
}
示例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));
}
}
}
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}