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


Java Observer.onComplete方法代碼示例

本文整理匯總了Java中io.reactivex.Observer.onComplete方法的典型用法代碼示例。如果您正苦於以下問題:Java Observer.onComplete方法的具體用法?Java Observer.onComplete怎麽用?Java Observer.onComplete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.Observer的用法示例。


在下文中一共展示了Observer.onComplete方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flatMap

import io.reactivex.Observer; //導入方法依賴的package包/類
private static <T> Function<HttpResponseResult<T>, ObservableSource<T>> flatMap() {
    return new Function<HttpResponseResult<T>, ObservableSource<T>>() {
        @Override
        public ObservableSource<T> apply(@NonNull final HttpResponseResult<T> tHttpResponseResult) throws Exception {
            return new Observable<T>() {
                @Override
                protected void subscribeActual(Observer<? super T> observer) {
                    if (tHttpResponseResult.isSuccess()) {
                        observer.onNext(tHttpResponseResult.getResult());
                        observer.onComplete();
                    } else {
                        observer.onError(new HttpResponseException(tHttpResponseResult.getMsg(), tHttpResponseResult.getState()));
                    }
                }
            };
        }
    };
}
 
開發者ID:sundevin,項目名稱:rxjava2_retrofit2,代碼行數:19,代碼來源:ResultTransformer.java

示例2: doOnEmpty

import io.reactivex.Observer; //導入方法依賴的package包/類
public static <T> ObservableOperator<T, T> doOnEmpty(Action
                                                             action) {
    return new ObservableOperator<T, T>() {
        @Override
        public Observer<? super T> apply(Observer<? super T>
                                                 observer) throws Exception {
            return new DisposableObserver<T>() {
                boolean isEmpty = true;

                @Override
                public void onNext(T value) {
                    isEmpty = false;
                    observer.onNext(value);
                }

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

                @Override
                public void onComplete() {
                    if (isEmpty) {
                        try {
                            action.run();
                        } catch (Exception e) {
                            onError(e);
                            return;
                        }
                    }
                    observer.onComplete();
                }
            };
        }
    };
}
 
開發者ID:PacktPublishing,項目名稱:Learning-RxJava,代碼行數:37,代碼來源:Ch9_7.java

示例3: subscribeActual

import io.reactivex.Observer; //導入方法依賴的package包/類
@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));
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:CallExecuteObservable.java

示例4: subscribeActual

import io.reactivex.Observer; //導入方法依賴的package包/類
@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));
            }
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:CallExecuteObservable.java

示例5: wrapObserver

import io.reactivex.Observer; //導入方法依賴的package包/類
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);
        }
    };
}
 
開發者ID:MFlisar,項目名稱:RxBus2,代碼行數:30,代碼來源:RxSubscriptionUtil.java

示例6: wrapObserver

import io.reactivex.Observer; //導入方法依賴的package包/類
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);
        }
    };
}
 
開發者ID:MFlisar,項目名稱:RxBus2,代碼行數:31,代碼來源:RxBusUtil.java

示例7: wrap

import io.reactivex.Observer; //導入方法依賴的package包/類
/**
 * @see Observable#subscribe(Observer)
 */
public <T> Observer<? super T> wrap(final Observer<? super T> observer) {
    LambdaObserver<? super T> disposableObserver = new LambdaObserver<>(
            new Consumer<T>() {
                @Override
                public void accept(T t) throws Exception {
                    observer.onNext(t);
                }
            },
            new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    observer.onError(throwable);
                }
            },
            new Action() {
                @Override
                public void run() throws Exception {
                    observer.onComplete();
                }
            },
            new Consumer<Disposable>() {
                @Override
                public void accept(Disposable disposable) throws Exception {
                    observer.onSubscribe(disposable);
                }
            }
    );

    return handleObserver(disposableObserver);
}
 
開發者ID:jzallas,項目名稱:RxDisposal,代碼行數:34,代碼來源:SubscriptionDecorator.java

示例8: testWrapObserver

import io.reactivex.Observer; //導入方法依賴的package包/類
@Test
public void testWrapObserver() throws Exception {
    String testString = "test";
    Throwable testThrowable = mock(Throwable.class);
    Disposable testDisposable = mock(Disposable.class);

    Observer<? super String> testObserver = mockSubscriptionDecorator.wrap(mockObserver);
    validateDisposableDelegated(testObserver);

    testObserver.onNext(testString);
    verify(mockObserver, times(1))
            .onNext(testString);

    testObserver.onError(testThrowable);
    verify(mockObserver, times(1))
            .onError(testThrowable);

    testObserver = mockSubscriptionDecorator.wrap(mockObserver);

    testObserver.onComplete();
    verify(mockObserver, times(1))
            .onComplete();

    testObserver = mockSubscriptionDecorator.wrap(mockObserver);

    testObserver.onSubscribe(testDisposable);
    verify(mockObserver, times(1))
            .onSubscribe(argThat(validateDisposeIsDelegated(testDisposable)));
}
 
開發者ID:jzallas,項目名稱:RxDisposal,代碼行數:30,代碼來源:SubscriptionDecoratorTest.java

示例9: subscribeActual

import io.reactivex.Observer; //導入方法依賴的package包/類
@Override
protected void subscribeActual(Observer<? super ProgressBean<Response<T>>> observer) {
    // Since Call is a one-shot type, clone it for each new observer.
    Call<T> call = originalCall.clone();

    Utils.replaceToProgressRequestBody(call, this);

    observer.onSubscribe(new CallDisposable(call));

    mObserver = observer;

    boolean terminated = false;
    try {
        Response<T> response = call.execute();
        if (!call.isCanceled()) {
            observer.onNext(
                    new ProgressBean<>(mTotal, mTotal, 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));
            }
        }
    }
}
 
開發者ID:imfms,項目名稱:retrofit-rxjava-request-with-progress,代碼行數:38,代碼來源:CallExecuteWithProgressObservable.java

示例10: streamInto

import io.reactivex.Observer; //導入方法依賴的package包/類
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();
}
 
開發者ID:adamkewley,項目名稱:jobson,代碼行數:14,代碼來源:Helpers.java

示例11: apply

import io.reactivex.Observer; //導入方法依賴的package包/類
@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) {
            if (isDisposed()) {
                return;
            }
            observer.onNext(response.body());
            observer.onComplete();
        }

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

        @Override
        public void onComplete() {
            if (!isDisposed()) {
                observer.onComplete();
            }
        }
    };
}
 
開發者ID:TrustWallet,項目名稱:trust-wallet-android,代碼行數:28,代碼來源:TrustWalletTickerService.java

示例12: apply

import io.reactivex.Observer; //導入方法依賴的package包/類
@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) {
            if (isDisposed()) {
                return;
            }
            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) {
            if (!isDisposed()) {
                observer.onError(e);
            }
        }

        @Override
        public void onComplete() {
            if (!isDisposed()) {
                observer.onComplete();
            }
        }
    };
}
 
開發者ID:TrustWallet,項目名稱:trust-wallet-android,代碼行數:37,代碼來源:EthplorerTokenService.java

示例13: apply

import io.reactivex.Observer; //導入方法依賴的package包/類
@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) {
                  if (isDisposed()) {
                      return;
                  }
                  observer.onNext(response.body());
                  observer.onComplete();
              }

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

              @Override
              public void onComplete() {
                  if (!isDisposed()) {
                      observer.onComplete();
                  }
              }
          };
}
 
開發者ID:TrustWallet,項目名稱:trust-wallet-android,代碼行數:28,代碼來源:BlockExplorerClient.java

示例14: subscribeActual

import io.reactivex.Observer; //導入方法依賴的package包/類
@Override
protected void subscribeActual(Observer<? super T> observer) {
    Call call = originalCall.clone();
    observer.onSubscribe(new ANDisposable(call));
    boolean doNotSwallowError = false;
    Response okHttpResponse = null;
    try {
        final long startTime = System.currentTimeMillis();
        final long startBytes = TrafficStats.getTotalRxBytes();
        okHttpResponse = call.execute();
        final long timeTaken = System.currentTimeMillis() - startTime;
        if (okHttpResponse.cacheResponse() == null) {
            final long finalBytes = TrafficStats.getTotalRxBytes();
            final long diffBytes;
            if (startBytes == TrafficStats.UNSUPPORTED || finalBytes == TrafficStats.UNSUPPORTED) {
                diffBytes = okHttpResponse.body().contentLength();
            } else {
                diffBytes = finalBytes - startBytes;
            }
            ConnectionClassManager.getInstance().updateBandwidth(diffBytes, timeTaken);
            Utils.sendAnalytics(request.getAnalyticsListener(), timeTaken,
                    (request.getRequestBody() != null &&
                            request.getRequestBody().contentLength() != 0) ?
                            request.getRequestBody().contentLength() : -1,
                    okHttpResponse.body().contentLength(), false);
        } else if (request.getAnalyticsListener() != null) {
            if (okHttpResponse.networkResponse() == null) {
                Utils.sendAnalytics(request.getAnalyticsListener(), timeTaken, 0, 0, true);
            } else {
                Utils.sendAnalytics(request.getAnalyticsListener(), timeTaken,
                        (request.getRequestBody() != null && request.getRequestBody().contentLength() != 0) ?
                                request.getRequestBody().contentLength() : -1, 0, true);
            }
        }
        if (okHttpResponse.code() >= 400) {
            if (!call.isCanceled()) {
                observer.onError(Utils.getErrorForServerResponse(new ANError(okHttpResponse),
                        request, okHttpResponse.code()));
            }
        } else {
            ANResponse<T> response = request.parseResponse(okHttpResponse);
            if (!response.isSuccess()) {
                if (!call.isCanceled()) {
                    observer.onError(response.getError());
                }
            } else {
                if (!call.isCanceled()) {
                    observer.onNext(response.getResult());
                }
                if (!call.isCanceled()) {
                    doNotSwallowError = true;
                    observer.onComplete();
                }
            }
        }
    } catch (IOException ioe) {
        if (!call.isCanceled()) {
            observer.onError(Utils.getErrorForConnection(new ANError(ioe)));
        }
    } catch (Exception e) {
        Exceptions.throwIfFatal(e);
        if (doNotSwallowError) {
            RxJavaPlugins.onError(e);
        } else if (!call.isCanceled()) {
            try {
                observer.onError(Utils.getErrorForNetworkOnMainThreadOrConnection(e));
            } catch (Exception e1) {
                Exceptions.throwIfFatal(e1);
                RxJavaPlugins.onError(new CompositeException(e, e1));
            }
        }
    } finally {
        SourceCloseUtil.close(okHttpResponse, request);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:76,代碼來源:Rx2InternalNetworking.java

示例15: validateOnComplete

import io.reactivex.Observer; //導入方法依賴的package包/類
private void validateOnComplete(Observer<? super String> testObserver) throws Exception {
    testObserver.onComplete();
    verify(mockOnComplete, times(1))
            .run();
}
 
開發者ID:jzallas,項目名稱:RxDisposal,代碼行數:6,代碼來源:SubscriptionDecoratorTest.java


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