Java Code Examples for io.reactivex.rxjava3.core.Observer#onSubscribe()

The following examples show how to use io.reactivex.rxjava3.core.Observer#onSubscribe() . 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: BehaviorRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> observer) {
    BehaviorDisposable<T> bs = new BehaviorDisposable<T>(observer, this);
    observer.onSubscribe(bs);
    add(bs);
    if (bs.cancelled) {
        remove(bs);
    } else {
        bs.emitFirst();
    }
}
 
Example 2
Source File: ReplayRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> observer) {
    ReplayDisposable<T> rs = new ReplayDisposable<T>(observer, this);
    observer.onSubscribe(rs);

    if (!rs.cancelled) {
        if (add(rs)) {
            if (rs.cancelled) {
                remove(rs);
                return;
            }
        }
        buffer.replay(rs);
    }
}
 
Example 3
Source File: PublishRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> t) {
    PublishDisposable<T> ps = new PublishDisposable<T>(t, this);
    t.onSubscribe(ps);
    add(ps);
    // if cancellation happened while a successful add, the remove() didn't work
    // so we need to do it again
    if (ps.isDisposed()) {
        remove(ps);
    }
}
 
Example 4
Source File: BehaviorRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> observer) {
    BehaviorDisposable<T> bs = new BehaviorDisposable<T>(observer, this);
    observer.onSubscribe(bs);
    add(bs);
    if (bs.cancelled) {
        remove(bs);
    } else {
        bs.emitFirst();
    }
}
 
Example 5
Source File: ReplayRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> observer) {
    ReplayDisposable<T> rs = new ReplayDisposable<T>(observer, this);
    observer.onSubscribe(rs);

    if (!rs.cancelled) {
        if (add(rs)) {
            if (rs.cancelled) {
                remove(rs);
                return;
            }
        }
        buffer.replay(rs);
    }
}
 
Example 6
Source File: PublishRelay.java    From RxRelay with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> t) {
    PublishDisposable<T> ps = new PublishDisposable<T>(t, this);
    t.onSubscribe(ps);
    add(ps);
    // if cancellation happened while a successful add, the remove() didn't work
    // so we need to do it again
    if (ps.isDisposed()) {
        remove(ps);
    }
}
 
Example 7
Source File: ObserverCircuitBreaker.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    if (circuitBreaker.tryAcquirePermission()) {
        upstream.subscribe(new CircuitBreakerObserver(downstream));
    } else {
        downstream.onSubscribe(EmptyDisposable.INSTANCE);
        downstream.onError(createCallNotPermittedException(circuitBreaker));
    }
}
 
Example 8
Source File: ObserverBulkhead.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    if (bulkhead.tryAcquirePermission()) {
        upstream.subscribe(new BulkheadObserver(downstream));
    } else {
        downstream.onSubscribe(EmptyDisposable.INSTANCE);
        downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead));
    }
}
 
Example 9
Source File: ObserverRateLimiter.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    long waitDuration = rateLimiter.reservePermission();
    if (waitDuration >= 0) {
        if (waitDuration > 0) {
            Completable.timer(waitDuration, TimeUnit.NANOSECONDS)
                .subscribe(() -> upstream.subscribe(new RateLimiterObserver(downstream)));
        } else {
            upstream.subscribe(new RateLimiterObserver(downstream));
        }
    } else {
        downstream.onSubscribe(EmptyDisposable.INSTANCE);
        downstream.onError(createRequestNotPermitted(rateLimiter));
    }
}