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


Java SingleObserver.onSubscribe方法代碼示例

本文整理匯總了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);
}
 
開發者ID:noorulhaq,項目名稱:reactive.loanbroker.system,代碼行數:20,代碼來源:RxJava2FutureUtils.java

示例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);
        }
    };
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:25,代碼來源:SubscribeOnlyOnceSingleOperator.java

示例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);
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:21,代碼來源:SubscribeOnlyOnceTest.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-jdbc,代碼行數:19,代碼來源:MemberSingle.java

示例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);
    }
}
 
開發者ID:roadhouse-dev,項目名稱:RxDbflow,代碼行數:17,代碼來源:DBFlowBaseSingle.java

示例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();
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:17,代碼來源:CircuitBreakerSingleObserverTest.java

示例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();
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:17,代碼來源:CircuitBreakerSingleObserverTest.java

示例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);
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:17,代碼來源:BulkheadSingleObserverTest.java

示例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);
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:17,代碼來源:BulkheadSingleObserverTest.java

示例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);
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:17,代碼來源:BulkheadSingleObserverTest.java

示例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);
}
 
開發者ID:lukas-krecan,項目名稱:future-converter,代碼行數:20,代碼來源:RxJava2FutureUtils.java

示例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);
}
 
開發者ID:niqo01,項目名稱:RxTask,代碼行數:8,代碼來源:SingleTask.java

示例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();
}
 
開發者ID:resilience4j,項目名稱:resilience4j,代碼行數:16,代碼來源:CircuitBreakerSingleObserverTest.java


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