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

The following examples show how to use io.reactivex.Observer#onComplete() . 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: UpWalletTickerService.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {

            observer.onNext(response.body());
            observer.onComplete();
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 2
Source File: BlockExplorerClient.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
          return new DisposableObserver<Response<T>>() {
              @Override
              public void onNext(Response<T> response) {
                  observer.onNext(response.body());
                  observer.onComplete();
              }

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

              @Override
              public void onComplete() {
                  observer.onComplete();
              }
          };
}
 
Example 3
Source File: MercuryWalletTickerService.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 4
Source File: CoinmarketcapTickerService.java    From ETHWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 5
Source File: MaybeConsumers.java    From science-journal with Apache License 2.0 6 votes vote down vote up
/**
 * Allows a function that takes a MaybeConsumer to pipe a single success value to the given
 * Observer (which may also be accepting values from other places)
 *
 * @return a {@link MaybeConsumer<T>} that pipes {@link MaybeConsumer#success(Object)} to {@link
 *     Observer#onNext(Object)}, and {@link MaybeConsumer#fail(Exception)} to {@link
 *     Observer#onError(Throwable)}
 */
public static <T> MaybeConsumer<T> fromObserver(Observer<T> o) {
  return new MaybeConsumer<T>() {
    @Override
    public void success(T value) {
      // if value is null, just report empty
      if (value != null) {
        o.onNext(value);
      }
      o.onComplete();
    }

    @Override
    public void fail(Exception e) {
      o.onError(e);
    }
  };
}
 
Example 6
Source File: BlockExplorerClient.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super retrofit2.Response<T>> apply(Observer<? super T> observer) throws Exception {
          return new DisposableObserver<Response<T>>() {
              @Override
              public void onNext(Response<T> response) {
                  observer.onNext(response.body());
                  observer.onComplete();
              }

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

              @Override
              public void onComplete() {
                  observer.onComplete();
              }
          };
}
 
Example 7
Source File: TrustWalletTickerService.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception {
    return new DisposableObserver<Response<T>>() {
        @Override
        public void onNext(Response<T> response) {
            observer.onNext(response.body());
            observer.onComplete();
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 8
Source File: CallEnqueueObservable.java    From retrocache with Apache License 2.0 6 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super Response<T>> observer) {
    if (mCachingActive && mCachingSystem.contains(CacheUtils.urlToKey(mOriginalCall.request().url()))) {
        byte[] data = mCachingSystem.get(CacheUtils.urlToKey(mOriginalCall.request().url()));
        if (data != null) {
            final T convertedData = CacheUtils.bytesToResponse(mRetrofit, mResponseType, mAnnotations, data);
            observer.onNext(Response.success(convertedData));
            observer.onComplete();
        }
        return;
    }
    // Since Call is a one-shot type, clone it for each new mObserver.
    Call<T> call = mOriginalCall.clone();
    CallCallback<T> callback = new CallCallback<>(call, observer, mCachingSystem, mResponseType, mAnnotations, mRetrofit, mCachingActive);
    observer.onSubscribe(callback);
    call.enqueue(callback);
}
 
Example 9
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 10
Source File: EthplorerTokenService.java    From Upchain-wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 11
Source File: CallExecuteObservable.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();
    observer.onSubscribe(new CallDisposable(call));

    boolean terminated = false;
    try {
        Response<T> response = call.execute();
        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 12
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 13
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 14
Source File: Helpers.java    From jobson with Apache License 2.0 5 votes vote down vote up
private static void streamInto(InputStream inputStream, Observer<byte[]> observer) throws IOException {
    byte[] bytes = new byte[STDIO_BUFFER_LEN_IN_BYTES];

    int bufLen;
    while((bufLen = inputStream.read(bytes, 0, STDIO_BUFFER_LEN_IN_BYTES)) != -1) {
        // Copy is necessary because observers might assume the buffer is
        // immutable, coming from an observable.
        byte[] outputBytes = new byte[bufLen];
        arraycopy(bytes, 0, outputBytes, 0, bufLen);
        observer.onNext(outputBytes);
    }
    observer.onComplete();
}
 
Example 15
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 16
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 17
Source File: LcObservableJust.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Override
protected void subscribeActual(Observer<? super T> downstream) {
    downstream.onSubscribe(this);

    if (disposed) {
        return;
    }
    downstream.onNext(value);
    if (disposed) {
        return;
    }
    downstream.onComplete();
}
 
Example 18
Source File: EthplorerTokenService.java    From trust-wallet-android-source with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

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

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    };
}
 
Example 19
Source File: SubscriptionProxy.java    From RxGroups with Apache License 2.0 5 votes vote down vote up
DisposableObserver<? super T> disposableWrapper(final Observer<? super T> observer) {
  return new DisposableObserver<T>() {
    @Override public void onNext(@NonNull T t) {
      observer.onNext(t);
    }

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

    @Override public void onComplete() {
      observer.onComplete();
    }
  };
}
 
Example 20
Source File: EthplorerTokenService.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Observer<? super Response<EthplorerResponse>> apply(Observer<? super EthplorerResponse> observer) throws Exception {
    return new DisposableObserver<Response<EthplorerResponse>>() {
        @Override
        public void onNext(Response<EthplorerResponse> response) {
            EthplorerResponse body = response.body();
            if (body != null && body.error == null) {
                observer.onNext(body);
                observer.onComplete();
            } else {
                if (body != null) {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(body.error.code, body.error.message)));
                } else {
                    observer.onError(new ApiErrorException(new ErrorEnvelope(UNKNOWN, "Service not available")));
                }
            }
        }

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

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