本文整理匯總了Java中io.reactivex.SingleObserver.onSubscribe方法的典型用法代碼示例。如果您正苦於以下問題:Java SingleObserver.onSubscribe方法的具體用法?Java SingleObserver.onSubscribe怎麽用?Java SingleObserver.onSubscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.SingleObserver
的用法示例。
在下文中一共展示了SingleObserver.onSubscribe方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: subscribeActual
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> observer) {
ValueSourceDisposable disposable = new ValueSourceDisposable();
valueSource.addCallbacks(
result -> {
try {
observer.onSuccess(result);
} catch (Throwable e) {
observer.onError(e);
}
},
ex -> {
if (!disposable.isDisposed()) {
observer.onError(ex);
}
}
);
observer.onSubscribe(disposable);
}
示例2: apply
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
public SingleObserver<? super T> apply(final SingleObserver<? super T> observer) {
return new SingleObserver<T>() {
@Override
public void onSubscribe(Disposable d) {
if (subscribedOnce.getAndSet(true)) {
throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " +
"concurrently. Use Flowable.share() instead.");
} else {
observer.onSubscribe(d);
}
}
@Override
public void onSuccess(T t) {
observer.onSuccess(t);
}
@Override
public void onError(Throwable e) {
observer.onError(e);
}
};
}
示例3: subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void subscribeOnlyOnceSingleOperatorErrorsWhenMultipleSubscribe() {
SubscribeOnlyOnceSingleOperator<Object> op = new SubscribeOnlyOnceSingleOperator<Object>();
SingleObserver<Object> innerSub = mock(SingleObserver.class);
final Disposable disposable = mock(Disposable.class);
final SingleObserver<Object> outerSub = op.apply(innerSub);
outerSub.onSubscribe(disposable);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() {
outerSub.onSubscribe(disposable);
}
})
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("cannot directly subscribe to a gRPC service multiple times");
verify(innerSub, times(1)).onSubscribe(disposable);
}
示例4: subscribeActual
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super Member<T>> observer) {
// the action of checking out a member from the pool is implemented as a
// subscription to the singleton MemberSingle
MemberSingleObserver<T> md = new MemberSingleObserver<T>(observer, this);
observer.onSubscribe(md);
if (pool.isClosed()) {
observer.onError(new PoolClosedException());
return;
}
add(md);
if (md.isDisposed()) {
remove(md);
}
requested.incrementAndGet();
log.debug("subscribed");
drain();
}
示例5: subscribeActual
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super Container> observer) {
observer.onSubscribe(EmptyDisposable.INSTANCE);
try {
Container v = run();
if (v != null) {
observer.onSuccess(v);
} else {
observer.onError(new NullPointerException("The callable returned a null value"));
}
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
observer.onError(e);
}
}
示例6: shouldHonorDisposedWhenCallingOnSuccess
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldHonorDisposedWhenCallingOnSuccess() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
decoratedObserver.onSuccess(1);
// Then
verify(childObserver, never()).onSuccess(any());
assertSingleSuccessfulCall();
}
示例7: shouldHonorDisposedWhenCallingOnError
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldHonorDisposedWhenCallingOnError() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
decoratedObserver.onError(new IllegalStateException());
// Then
verify(childObserver, never()).onError(any());
assertSingleFailedCall();
}
示例8: shouldHonorDisposedWhenCallingOnSuccess
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldHonorDisposedWhenCallingOnSuccess() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
decoratedObserver.onSuccess(1);
// Then
verify(childObserver, never()).onSuccess(any());
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
示例9: shouldHonorDisposedWhenCallingOnError
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldHonorDisposedWhenCallingOnError() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
decoratedObserver.onError(new IllegalStateException());
// Then
verify(childObserver, never()).onError(any());
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
示例10: shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
bulkhead.isCallPermitted();
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
// Then
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}
示例11: subscribeActual
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> observer) {
ValueSourceDisposable disposable = new ValueSourceDisposable();
valueSource.addCallbacks(
result -> {
try {
observer.onSuccess(result);
} catch (Throwable e) {
observer.onError(e);
}
},
ex -> {
if (!disposable.isDisposed()) {
observer.onError(ex);
}
}
);
observer.onSubscribe(disposable);
}
示例12: subscribeActual
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Override
protected void subscribeActual(SingleObserver<? super T> observer) {
Task<T> task = run();
SingleTaskCallback<T> callback = new SingleTaskCallback(task, observer);
observer.onSubscribe(callback);
task.addOnCompleteListener(callback);
}
示例13: shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe
import io.reactivex.SingleObserver; //導入方法依賴的package包/類
@Test
public void shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
// Given
Disposable disposable = mock(Disposable.class);
SingleObserver childObserver = mock(SingleObserver.class);
SingleObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
circuitBreaker.transitionToOpenState();
decoratedObserver.onSubscribe(disposable);
// When
((Disposable) decoratedObserver).dispose();
// Then
assertNoRegisteredCall();
}