private Completable tryConnectHosts() { if (stopped) { LOGGER.debug("Not trying to connect to hosts, already stopped."); return Completable.complete(); } transitionState(LifecycleState.CONNECTING); List<InetSocketAddress> hosts = remoteHosts.get(); Completable chain = tryConnectHost(hosts.get(0)); for (int i = 1; i < hosts.size(); i++) { final InetSocketAddress h = hosts.get(i); chain = chain.onErrorResumeNext(new Func1<Throwable, Completable>() { @Override public Completable call(Throwable throwable) { LOGGER.warn("Could not get config from Node, trying next in list.", throwable); return tryConnectHost(h); } }); } return chain; }
private void startRefreshLocationTimerAsync(boolean initialization) { if (this.isClosed) { logger.info("startRefreshLocationTimerAsync: nothing to do, it is closed"); return; } logger.debug("registering a refresh in [{}] ms", this.backgroundRefreshLocationTimeIntervalInMS); LocalDateTime now = LocalDateTime.now(); int delayInMillis = initialization ? 0: this.backgroundRefreshLocationTimeIntervalInMS; Observable.timer(delayInMillis, TimeUnit.MILLISECONDS) .toSingle().flatMapCompletable( t -> { if (this.isClosed) { logger.warn("client already closed"); return Completable.error(new IllegalStateException("Client already closed")); } logger.debug("startRefreshLocationTimerAsync() - Invoking refresh, I was registered on [{}]", now); Single<DatabaseAccount> databaseAccountObs = GlobalEndpointManager.getDatabaseAccountFromAnyLocationsAsync(this.defaultEndpoint, new ArrayList<>(this.connectionPolicy.getPreferredLocations()), url -> this.getDatabaseAccountAsync(url)).toObservable().toSingle(); return databaseAccountObs.flatMapCompletable(dbAccount -> { logger.debug("db account retrieved"); return this.refreshLocationPrivateAsync(dbAccount); }); }).onErrorResumeNext(ex -> { logger.error("startRefreshLocationTimerAsync() - Unable to refresh database account from any location. Exception: {}", ex.toString(), ex); this.startRefreshLocationTimerAsync(); return Completable.complete(); }).toObservable().subscribeOn(scheduler).toBlocking().toFuture(); }
/** * Initializes the underlying connections (not the streams) and sets up everything as needed. * * @return a {@link Completable} signaling that the connect phase has been completed or failed. */ public Completable connect() { if (!conductor.disconnected()) { // short-circuit connect attempt if the conductor is already connecting/connected. LOGGER.debug("Ignoring duplicate connect attempt, already connecting/connected."); return Completable.complete(); } if (env.dataEventHandler() == null) { throw new IllegalArgumentException("A DataEventHandler needs to be provided!"); } if (env.controlEventHandler() == null) { throw new IllegalArgumentException("A ControlEventHandler needs to be provided!"); } LOGGER.info("Connecting to seed nodes and bootstrapping bucket {}.", meta(env.bucket())); return conductor.connect().onErrorResumeNext(new Func1<Throwable, Completable>() { @Override public Completable call(Throwable throwable) { return conductor.stop() .andThen(Completable.error(new BootstrapException("Could not connect to Cluster/Bucket", throwable))); } }); }
@Override public Completable syncTriggersAsync() { return manager().inner().webApps().syncFunctionTriggersAsync(resourceGroupName(), name()) .toCompletable() .onErrorResumeNext(new Func1<Throwable, Completable>() { @Override public Completable call(Throwable throwable) { if (throwable instanceof CloudException && ((CloudException) throwable).response().code() == 200) { return Completable.complete(); } else { return Completable.error(throwable); } } }); }
@Override public Completable call(Short partition) { PartitionState partitionState = sessionState().get(partition); return conductor.startStreamForPartition( partition, partitionState.getLastUuid(), partitionState.getStartSeqno(), partitionState.getEndSeqno(), partitionState.getSnapshotStartSeqno(), partitionState.getSnapshotEndSeqno() ).onErrorResumeNext(new Func1<Throwable, Completable>() { @Override public Completable call(Throwable throwable) { if (throwable instanceof RollbackException) { // We ignore rollbacks since they are handled out of band by the user. return Completable.complete(); } else { return Completable.error(throwable); } } }); } })
@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()); } }