From b3fdc557e14873f808a169a1750b8889584f8f3a Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 1 Jan 2017 14:16:57 +0100 Subject: [PATCH] Required call to onCompleted() --- .../service/impl/AwesomeBusinessLogicImpl.java | 5 +++++ .../service/impl/RxJavaBusinessLogicImpl.java | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/AwesomeBusinessLogicImpl.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/AwesomeBusinessLogicImpl.java index f41af5d..f81e8f6 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/AwesomeBusinessLogicImpl.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/AwesomeBusinessLogicImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import de.spring.webservices.domain.Car; import de.spring.webservices.rest.business.service.AwesomeBusinessLogic; +import rx.exceptions.Exceptions; @Service("awesomeBusinessLogic") public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic { @@ -65,5 +66,9 @@ public class AwesomeBusinessLogicImpl implements AwesomeBusinessLogic { public Car createThrowable(Car car) throws IOException { throw new IOException("createThrowable FATAL ERROR"); + // Spring sees both exceptions. + // It seems like calling Exceptions.propagate(ex) in RxJava code is only required + // for no RuntimeExceptions :/ + // throw new RuntimeException("createThrowable FATAL ERROR"); } } diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java index c747c7f..771fb40 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java @@ -37,6 +37,7 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic { @Override public void call(Subscriber> observer) { observer.onNext( awesomeBusinessLogic.findAll(pageRequest)); + observer.onCompleted(); } }).subscribeOn(Schedulers.io()); } @@ -47,22 +48,25 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic { @Override public void call(Subscriber> observer) { observer.onNext( awesomeBusinessLogic.findAll(pageRequest)); + observer.onCompleted(); } }).subscribeOn(Schedulers.io()); } @Override public Observable findById(long id) { - return Observable.create((Subscriber observer) -> - observer.onNext( awesomeBusinessLogic.findById(id))) - .subscribeOn(Schedulers.io()); + return Observable.create((Subscriber observer) -> { + observer.onNext( awesomeBusinessLogic.findById(id)); + observer.onCompleted(); + }).subscribeOn(Schedulers.io()); } @Override public Observable create(Car car) { - return Observable.create((Subscriber observer) -> - observer.onNext(awesomeBusinessLogic.create(car))) - .subscribeOn(Schedulers.io()); + return Observable.create((Subscriber observer) -> { + observer.onNext(awesomeBusinessLogic.create(car)); + observer.onCompleted(); + }).subscribeOn(Schedulers.io()); } @Override @@ -71,6 +75,7 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic { try { observer.onNext(awesomeBusinessLogic.createThrowable(car)); + observer.onCompleted(); } catch (IOException ex) { // I could use this implementation. Instead, I will wrap my exception because // that is what you would be doing if you were using any other method from RxJava (like map() for example) @@ -80,9 +85,6 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic { Exceptions.propagate(ex); } - - // No idea when to use this stuff :( - // observer.onCompleted(); }).subscribeOn(Schedulers.io()); } -- 2.1.4