本文整理匯總了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()));
}
}
};
}
};
}
示例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();
}
};
}
};
}
示例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));
}
}
}
}
示例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));
}
}
}
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
示例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)));
}
示例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();
}
示例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();
}
}
};
}
示例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();
}
}
};
}
示例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();
}
}
};
}
示例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);
}
}
示例15: validateOnComplete
import io.reactivex.Observer; //導入方法依賴的package包/類
private void validateOnComplete(Observer<? super String> testObserver) throws Exception {
testObserver.onComplete();
verify(mockOnComplete, times(1))
.run();
}