@Override public Observable<T> call(Observable<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .concatWith(sqlConnection.rxCommit().toCompletable().toObservable()) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Observable.error(throwable)); }).concatWith(sqlConnection.rxSetAutoCommit(true).toCompletable().toObservable()); } }
@Override public Observable<T> call(Observable<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .concatWith(sqlConnection.rxCommit().toCompletable().toObservable()) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Observable.error(throwable)); }).concatWith(sqlConnection.rxSetAutoCommit(true).toCompletable().toObservable()); } }
@Override public Completable call(Completable upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .andThen(sqlConnection.rxCommit().toCompletable()) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Completable.error(throwable)); }).andThen(sqlConnection.rxSetAutoCommit(true).toCompletable()); } }
@Override public Completable call(Completable upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .andThen(sqlConnection.rxCommit().toCompletable()) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Completable.error(throwable)); }).andThen(sqlConnection.rxSetAutoCommit(true).toCompletable()); } }
@Override public void start() { log.info("Launching importer ..."); store = new RxStore(StoreFactory.createStore(getVertx())); String storagePath = config().getString(ConfigConstants.STORAGE_FILE_PATH); incoming = storagePath + "/incoming"; vertx.eventBus().<JsonObject>localConsumer(AddressConstants.IMPORTER_IMPORT) .toObservable() .onBackpressureBuffer() // unlimited buffer .flatMapCompletable(msg -> { // call onImport() but ignore errors. onImport() will handle errors for us. return onImport(msg).onErrorComplete(); }, false, MAX_PARALLEL_IMPORTS) .subscribe(v -> { // ignore }, err -> { // This is bad. It will unsubscribe the consumer from the eventbus! // Should never happen anyhow. If it does, something else has // completely gone wrong. log.fatal("Could not import file", err); }); vertx.eventBus().localConsumer(AddressConstants.IMPORTER_PAUSE, this::onPause); }
@Override public Single<T> call(Single<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item))) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Single.error(throwable)); }).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item))); } }
@Override public Single<T> call(Single<T> upstream) { return sqlConnection.rxSetAutoCommit(false).toCompletable() .andThen(upstream) .flatMap(item -> sqlConnection.rxCommit().toCompletable().andThen(Single.just(item))) .onErrorResumeNext(throwable -> { return sqlConnection.rxRollback().toCompletable().onErrorComplete() .andThen(sqlConnection.rxSetAutoCommit(true).toCompletable().onErrorComplete()) .andThen(Single.error(throwable)); }).flatMap(item -> sqlConnection.rxSetAutoCommit(true).toCompletable().andThen(Single.just(item))); } }