/** * Converts an {@link ApolloPrefetch} to a Completable. * * @param prefetch the ApolloPrefetch to convert * @return the converted Completable */ @NotNull public static Completable from(@NotNull final ApolloPrefetch prefetch) { checkNotNull(prefetch, "prefetch == null"); return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) { final Subscription subscription = getSubscription(subscriber, prefetch); prefetch.enqueue(new ApolloPrefetch.Callback() { @Override public void onSuccess() { if (!subscription.isUnsubscribed()) { subscriber.onCompleted(); } } @Override public void onFailure(@NotNull ApolloException e) { Exceptions.throwIfFatal(e); if (!subscription.isUnsubscribed()) { subscriber.onError(e); } } }); } }); }
/** * Converts an 2.x CompletableSource (the base type of 2.x Completable) into a * 1.x Completable, composing cancellation (unsubscription) through. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>The method does not operate by default on a particular {@code Scheduler}.</dd> * </dl> * @param source the source 2.x CompletableSource instance, not null * @return the new 1.x Completable instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static rx.Completable toV1Completable(io.reactivex.CompletableSource source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Completable.create(new CompletableV2ToCompletableV1(source)); }
/** * Converts an 2.x MaybeSource (the base type of 2.x Maybe) into a * 1.x Completable, composing cancellation (unsubscription) through * and ignoring the success value. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>The method does not operate by default on a particular {@code Scheduler}.</dd> * </dl> * @param <T> the source's value type * @param source the source 2.x MaybeSource instance, not null * @return the new 1.x Completable instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static <T> rx.Completable toV1Completable(io.reactivex.MaybeSource<T> source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Completable.create(new MaybeV2ToCompletableV1<T>(source)); }
/** * Initializes the session state from beginning to no end. */ private Completable initFromBeginningToInfinity() { return Completable.create(new Completable.OnSubscribe() { @Override public void call(CompletableSubscriber subscriber) { LOGGER.info("Initializing state from beginning to no end."); try { sessionState().setToBeginningWithNoEnd(numPartitions()); subscriber.onCompleted(); } catch (Exception ex) { LOGGER.warn("Failed to initialize state from beginning to no end.", ex); subscriber.onError(ex); } } }); }
private static Completable asSnackObservableInternal(Snackbar snackbar) { return Completable.create(new Completable.OnSubscribe() { @Override public void call(CompletableSubscriber completableSubscriber) { Snackbar.Callback snackbarCallback = new Snackbar.Callback() { @Override public void onShown(Snackbar snackbar) { super.onShown(snackbar); // does nothing } @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); snackbar.removeCallback(this); completableSubscriber.onCompleted(); } }; snackbar.addCallback(snackbarCallback); snackbar.show(); } }); }
@Override public Completable stop() { stopped = true; return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) { LOGGER.debug("Initiating streaming config provider shutdown on channel."); transitionState(LifecycleState.DISCONNECTING); if (channel != null) { Channel ch = channel; channel = null; ch.close().addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { transitionState(LifecycleState.DISCONNECTED); if (future.isSuccess()) { LOGGER.debug("Streaming config provider channel shutdown completed."); subscriber.onCompleted(); } else { LOGGER.warn("Error during streaming config provider shutdown!", future.cause()); subscriber.onError(future.cause()); } } }); } else { subscriber.onCompleted(); } } }); }
return Completable.create(new Completable.OnSubscribe() { @Override public void call(CompletableSubscriber subscriber) {
public Completable disconnect() { return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) {
public Completable connect() { return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) {
/** * Converst a Publisher into a Completable by ignoring all onNext values and emitting * onError or onComplete only. * @param publisher the Publisher instance to convert * @return the Completable instance * @since 1.1 * @throws NullPointerException if publisher is null */ public static Completable toCompletable(Publisher<?> publisher) { if (publisher == null) { throw new NullPointerException("publisher"); } return Completable.create(new PublisherAsCompletable(publisher)); }
public Completable closeStream(final short vbid) { return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) { if (state() != LifecycleState.CONNECTED) { subscriber.onError(new NotConnectedException()); return; } LOGGER.debug("Closing Stream against {} with vbid: {}", inetAddress, vbid); ByteBuf buffer = Unpooled.buffer(); DcpCloseStreamRequest.init(buffer); DcpCloseStreamRequest.vbucket(buffer, vbid); sendRequest(buffer).addListener(new DcpResponseListener() { @Override public void operationComplete(Future<DcpResponse> future) throws Exception { streamIsOpen.set(vbid, false); if (future.isSuccess()) { future.getNow().buffer().release(); LOGGER.debug("Closed Stream against {} with vbid: {}", inetAddress, vbid); subscriber.onCompleted(); } else { LOGGER.debug("Failed close Stream against {} with vbid: {}", inetAddress, vbid); subscriber.onError(future.cause()); } } }); } }); }
@Override public Completable adapt(Call call) { Completable completable = Completable.create(new CompletableCallOnSubscribe(call)); if (scheduler != null) { return completable.subscribeOn(scheduler); } return completable; } }
@CheckResult @NonNull public static <T> Completable createCompletable( @NonNull StorIOSQLite storIOSQLite, @NonNull PreparedOperation<T> operation ) { throwExceptionIfRxJavaIsNotAvailable("asRxCompletable()"); final Completable completable = Completable.create(OnSubscribeExecuteAsBlockingCompletable.newInstance(operation)); return subscribeOn(storIOSQLite, completable); }
public Completable openStream(final short vbid, final long vbuuid, final long startSeqno, final long endSeqno, final long origSnapshotStartSeqno, final long origSnapshotEndSeqno) { return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) {
/** * Converts an 2.x CompletableSource (the base type of 2.x Completable) into a * 1.x Completable, composing cancellation (unsubscription) through. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>The method does not operate by default on a particular {@code Scheduler}.</dd> * </dl> * @param source the source 2.x CompletableSource instance, not null * @return the new 1.x Completable instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static rx.Completable toV1Completable(io.reactivex.CompletableSource source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Completable.create(new CompletableV2ToCompletableV1(source)); }
/** * Converts an 2.x MaybeSource (the base type of 2.x Maybe) into a * 1.x Completable, composing cancellation (unsubscription) through * and ignoring the success value. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>The method does not operate by default on a particular {@code Scheduler}.</dd> * </dl> * @param <T> the source's value type * @param source the source 2.x MaybeSource instance, not null * @return the new 1.x Completable instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static <T> rx.Completable toV1Completable(io.reactivex.MaybeSource<T> source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Completable.create(new MaybeV2ToCompletableV1<T>(source)); }
/** * Helper method to rollback the partition state and stop/restart the stream. * * The stream is stopped (if not already done). Then: * * The rollback seqno state is applied. Note that this will also remove all the failover logs for the partition * that are higher than the given seqno, since the server told us we are ahead of it. * * Finally, the stream is restarted again. * * @param partition the partition id * @param seqno the sequence number to rollback to */ public Completable rollbackAndRestartStream(final short partition, final long seqno) { return stopStreaming(partition) .andThen(Completable.create(new Completable.OnSubscribe() { @Override public void call(CompletableSubscriber subscriber) { sessionState().rollbackToPosition(partition, seqno); subscriber.onCompleted(); } })) .andThen(startStreaming(partition)); }
static Completable writeToDatabase(Object data) { return Completable.create(s -> { doAsyncWrite(data, // callback for successful completion () -> s.onCompleted(), // callback for failure with Throwable error -> s.onError(error)); }); }
loopShutdown = Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) {
.group(env.eventLoopGroup()); return Completable.create(new Completable.OnSubscribe() { @Override public void call(final CompletableSubscriber subscriber) {