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

The following examples show how to use io.reactivex.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: CallExecuteObservable.java    From retrocache with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
    // Since Call is a one-shot type, clone it for each new observer.
    Call<T> call = mOriginalCall.clone();
    observer.onSubscribe(new CallDisposable(call));

    boolean terminated = false;
    try {
        Response<T> response = getResponse(call);
        if (mCachingActive && !mCachingSystem.contains(CacheUtils.urlToKey(mOriginalCall.request().url()))) {
            mCachingSystem.put(
                    CacheUtils.urlToKey(call.request().url()), CacheUtils.responseToBytes(mRetrofit, response, mResponseType, mAnnotations));
        }
        if (!call.isCanceled()) {
            observer.onNext(response);
        }
        if (!call.isCanceled()) {
            terminated = true;
            observer.onComplete();
        }
    } catch (Throwable t) {
        Exceptions.throwIfFatal(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));
            }
        }
    }
}
 
Example 2
Source File: ProgressEventObservable.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super ProgressEvent> observer) {
    if (!Preconditions.checkMainThread(observer)) {
        return;
    }
    Listener listener = new Listener(button, observer);
    observer.onSubscribe(listener);
    button.setOnProgressChangeListener(listener);
}
 
Example 3
Source File: ProgressObservable.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Float> observer) {
    if (!Preconditions.checkMainThread(observer)) {
        return;
    }
    Listener listener = new Listener(button, observer);
    observer.onSubscribe(listener);
    button.setOnProgressChangeListener(listener);
}
 
Example 4
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));
    }
}
 
Example 5
Source File: StateChangeObservable.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super CameraButton.State> observer) {
    if (!Preconditions.checkMainThread(observer)) {
        return;
    }
    Listener listener = new Listener(button, observer);
    observer.onSubscribe(listener);
    button.setOnStateChangeListener(listener);
}
 
Example 6
Source File: ClientStateObservable.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super RxBleClient.State> observer) {
    if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
        observer.onSubscribe(Disposables.empty());
        observer.onComplete();
        return;
    }

    checkPermissionUntilGranted(locationServicesStatus, timerScheduler)
            .flatMapObservable(new Function<Boolean, Observable<RxBleClient.State>>() {
                @Override
                public Observable<RxBleClient.State> apply(Boolean permissionWasInitiallyGranted) {
                    Observable<RxBleClient.State> stateObservable = checkAdapterAndServicesState(
                            rxBleAdapterWrapper,
                            bleAdapterStateObservable,
                            locationServicesOkObservable
                    )
                            .distinctUntilChanged();
                    return permissionWasInitiallyGranted
                            /*
                             * If permission was granted from the beginning then the first value is not a change. The above Observable
                             * does emit value at the moment of subscription.
                             */
                            ? stateObservable.skip(1)
                            : stateObservable;
                }
            })
            .subscribe(observer);
}
 
Example 7
Source File: PhotoEventObservable.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super PhotoEvent> observer) {
    if (!Preconditions.checkMainThread(observer)) {
        return;
    }
    Listener listener = new Listener(button, observer);
    observer.onSubscribe(listener);
    button.setOnPhotoEventListener(listener);
}
 
Example 8
Source File: CellClickObservable.java    From Tangram-Android with MIT License 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super ClickExposureCellOp> observer) {
    if (!Preconditions.checkMainThread(observer)) {
        return;
    }
    if (mListener == null) {
        mListener = new RxClickListener(mRxClickExposureEvent, observer);
    } else {
        mListener.setRxClickExposureEvent(mRxClickExposureEvent);
        mListener.setObserver(observer);
    }
    observer.onSubscribe(mListener);
    mRxClickExposureEvent.getArg1().setOnClickListener(mListener);
}
 
Example 9
Source File: CallEnqueueObservable.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
    // Since Call is a one-shot type, clone it for each new observer.
    Call<T> call = originalCall.clone();
    CallCallback<T> callback = new CallCallback<>(call, observer);
    observer.onSubscribe(callback);
    call.execute(callback);
}
 
Example 10
Source File: LcObservableRange.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Integer> downstream) {
    downstream.onSubscribe(this);

    for (int i = start; i < end; i++) {
        if (disposed) {
            return;
        }
        downstream.onNext(i);
    }
    if (disposed) {
        return;
    }
    downstream.onComplete();
}
 
Example 11
Source File: ViewClickObservable.java    From Tangram-Android with MIT License 5 votes vote down vote up
@Override protected void subscribeActual(Observer<? super Object> observer) {
    if (!checkMainThread(observer)) {
        return;
    }
    Listener listener = new Listener(view, observer);
    observer.onSubscribe(listener);
    view.setOnClickListener(listener);
}
 
Example 12
Source File: JSONArrayObservable.java    From Tangram-Android with MIT License 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> observer) {
    FromJsonArrayDisposable<T> d = new FromJsonArrayDisposable<T>(observer, mJson);
    observer.onSubscribe(d);
    if (d.fusionMode) {
        return;
    }
    d.run();
}
 
Example 13
Source File: RxBusUtil.java    From RxBus2 with Apache License 2.0 5 votes vote down vote up
public static <T> Observer<T> wrapObserver(Observer<T> observer, IRxBusQueue isResumedProvider)
{
    return new Observer<T>()
    {
        @Override
        public void onSubscribe(Disposable d) {
            observer.onSubscribe(d);
        }

        @Override
        public void onComplete()
        {
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e)
        {
            observer.onError(e);
        }


        @Override
        public void onNext(T t)
        {
            if (RxUtil.safetyQueueCheck(t, isResumedProvider))
                observer.onNext(t);
        }
    };
}
 
Example 14
Source File: RxSubscriptionUtil.java    From RxBus2 with Apache License 2.0 5 votes vote down vote up
public static <T> Observer<T> wrapObserver(Observer<T> observer, IRxBusQueue isResumedProvider)
{
    return new Observer<T>()
    {
        @Override
        public void onSubscribe(Disposable d) {
            observer.onSubscribe(d);
        }

        @Override
        public void onComplete()
        {
            observer.onComplete();
        }

        @Override
        public void onError(Throwable e)
        {
            observer.onError(e);
        }

        @Override
        public void onNext(T t)
        {
            if (RxUtil.safetyQueueCheck(t, isResumedProvider))
                observer.onNext(t);
        }
    };
}
 
Example 15
Source File: OnGlobalPlaceObservable.java    From okuki with Apache License 2.0 4 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Place> observer) {
    Listener listener = new Listener(okuki, observer);
    observer.onSubscribe(listener);
    okuki.addGlobalListener(listener);
}
 
Example 16
Source File: BannerSelectedObservable.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
    observer.onSubscribe(mBannerListener);
    mBannerListener.addObserver(observer);
}
 
Example 17
Source File: BannerScrolledObservable.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super ScrollEvent> observer) {
    observer.onSubscribe(mBannerListener);
    mBannerListener.addObserver(observer);
}
 
Example 18
Source File: QueryObservable.java    From floatingsearchview with Apache License 2.0 4 votes vote down vote up
@Override
protected void subscribeListener(Observer<? super CharSequence> observer) {
    Listener listener = new Listener(view, observer, minQueryLength);
    observer.onSubscribe(listener);
    view.setOnQueryChangeListener(listener);
}
 
Example 19
Source File: OnPlaceObservable.java    From okuki with Apache License 2.0 4 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super P> observer) {
    Listener<P> listener = new Listener<>(okuki, placeClass, observer);
    observer.onSubscribe(listener);
    okuki.addPlaceListener(listener);
}
 
Example 20
Source File: PatternLockViewProgressObservable.java    From PatternLockView with Apache License 2.0 4 votes vote down vote up
@Override
protected void subscribeListener(Observer<? super PatternLockProgressEvent> observer) {
    InternalListener internalListener = new InternalListener(mPatternLockView, observer);
    observer.onSubscribe(internalListener);
    mPatternLockView.addPatternLockListener(internalListener);
}