/** * Converts an {@link ApolloStoreOperation} to a Single. * * @param operation the ApolloStoreOperation to convert * @param <T> the value type * @return the converted Single */ @NotNull public static <T> Single<T> from(@NotNull final ApolloStoreOperation<T> operation) { checkNotNull(operation, "operation == null"); return Single.create(new Single.OnSubscribe<T>() { @Override public void call(final SingleSubscriber<? super T> subscriber) { operation.enqueue(new ApolloStoreOperation.Callback<T>() { @Override public void onSuccess(T result) { subscriber.onSuccess(result); } @Override public void onFailure(Throwable t) { subscriber.onError(t); } }); } }); }
/** * Emits the results of {@code AsyncHandlers} obtained from * {@code handlerSupplier} for HTTP requests obtained obtained by calling * {@code requestTemplate}. * * @param requestTemplate called to start the HTTP request with an * {@code AysncHandler} that builds the HTTP response and * propagates results to the returned {@code Single}. The * {@code Future} that is returned by {@code requestTemplate} * will be used to cancel the request when the {@code Single} is * unsubscribed. * @param handlerSupplier supplies the desired {@code AsyncHandler} * instances that are used to produce results * @return a {@code Single} that executes new requests on subscription by * calling {@code requestTemplate} and that emits the results * produced by the {@code AsyncHandlers} supplied by * {@code handlerSupplier} * @throws NullPointerException if at least one of the parameters is * {@code null} */ public static <T> Single<T> create(Func1<? super AsyncHandler<?>, ? extends Future<?>> requestTemplate, Func0<? extends AsyncHandler<? extends T>> handlerSupplier) { requireNonNull(requestTemplate); requireNonNull(handlerSupplier); return Single.create(subscriber -> { final AsyncHandler<?> bridge = createBridge(subscriber, handlerSupplier.call()); final Future<?> responseFuture = requestTemplate.call(bridge); subscriber.add(Subscriptions.from(responseFuture)); }); }
public Single<T> observe() { return Single.create(subscriber -> addListener((EVCacheGetOperationListener<T>) future -> { try { subscriber.onSuccess(get()); } catch (Throwable e) { subscriber.onError(e); } }) ); }
public Single<Map<String, T>> observe() { return Single.create(subscriber -> addListener(future -> { try { subscriber.onSuccess(get()); } catch (Throwable e) { subscriber.onError(e); } }) ); }
public Single<Map<String, T>> getSome(long to, TimeUnit units, boolean throwException, boolean hasZF, Scheduler scheduler) { final Stopwatch operationDuration = EVCacheMetricsFactory.getStatsTimer(appName, serverGroup, metricName).start(); return observe().timeout(to, units, Single.create(subscriber -> { try { final Collection<Operation> timedoutOps = new HashSet<Operation>();
public Single<T> get(long duration, TimeUnit units, boolean throwException, boolean hasZF, Scheduler scheduler) { return observe().timeout(duration, units, Single.create(subscriber -> { // whenever timeout occurs, continuous timeout counter will increase by 1. MemcachedConnection.opTimedOut(op); if (op != null) op.timeOut(); if (!hasZF) EVCacheMetricsFactory.getCounter(appName, null, serverGroup.getName(), appName + "-get-CheckedOperationTimeout", DataSourceType.COUNTER).increment(); if (throwException) { subscriber.onError(new CheckedOperationTimeoutException("Timed out waiting for operation", op)); } else { if (isCancelled()) { if (hasZF) EVCacheMetricsFactory.getCounter(appName, null, serverGroup.getName(), appName + "-get-Cancelled", DataSourceType.COUNTER).increment(); } subscriber.onSuccess(objRef.get()); } }), scheduler).doAfterTerminate(new Action0() { @Override public void call() { } } ); }
/** * Converts an 2.x SingleSource (the base type of 2.x Single) into a * 1.x Single, 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 <T> the value type * @param source the source 2.x SingleSource instance, not null * @return the new 1.x Single instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static <T> rx.Single<T> toV1Single(io.reactivex.SingleSource<T> source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Single.create(new SingleV2ToSingleV1<T>(source)); }
/** * Converts an 2.x MaybeSource (the base type of 2.x Maybe) into a * 1.x Single, composing cancellation (unsubscription) through and * signalling NoSuchElementException if the MaybeSource is empty. * <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 Single instance * @throws NullPointerException if {@code source} is null */ @io.reactivex.annotations.SchedulerSupport(io.reactivex.annotations.SchedulerSupport.NONE) public static <T> rx.Single<T> toV1Single(io.reactivex.MaybeSource<T> source) { io.reactivex.internal.functions.ObjectHelper.requireNonNull(source, "source is null"); return rx.Single.create(new MaybeV2ToSingleV1<T>(source)); }
/** * Get a connection from the pool. * @return */ public Single<io.reactiverse.rxjava.pgclient.PgConnection> rxGetConnection() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { getConnection(fut); })); }
/** * Like {@link io.reactiverse.rxjava.pgclient.PgTransaction#rollback} with an handler to be notified when the transaction rollback has completed * @return */ public Single<Void> rxRollback() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { rollback(fut); })); }
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxQuery(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { query(sql, fut); })); }
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, arguments, fut); })); }
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedBatch(String sql, List<io.reactiverse.rxjava.pgclient.Tuple> batch) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedBatch(sql, batch, fut); })); }
/** * Connect the subscriber to Postgres. * @return a reference to this, so the API can be used fluently */ public Single<Void> rxConnect() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { connect(fut); })); }
/** * Like {@link io.reactiverse.rxjava.pgclient.PgClient#connect} with options build from the environment variables. * @param vertx * @return */ public static Single<io.reactiverse.rxjava.pgclient.PgConnection> rxConnect(io.vertx.rxjava.core.Vertx vertx) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { connect(vertx, fut); })); }
/** * Prepare and execute a query. * @param sql the prepared query SQL * @return a reference to this, so the API can be used fluently */ public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, fut); })); }
/** * Prepare and execute a query. * @param sql the prepared query SQL * @param arguments the list of arguments * @return a reference to this, so the API can be used fluently */ public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, arguments, fut); })); }
/** * Create a prepared query. * @param sql the sql * @return */ public Single<io.reactiverse.rxjava.pgclient.PgPreparedQuery> rxPrepare(String sql) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { prepare(sql, fut); })); }
public Single<io.reactiverse.rxjava.pgclient.PgRowSet> rxPreparedQuery(String sql, io.reactiverse.rxjava.pgclient.Tuple arguments) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { preparedQuery(sql, arguments, fut); })); }
/** * Block the given address for the given multicast address and notifies the once * the operation completes. * @param multicastAddress the address for which you want to block the source address * @param sourceToBlock the source address which should be blocked. You will not receive an multicast packets for it anymore. * @return a reference to this, so the API can be used fluently */ public Single<io.vertx.rxjava.core.datagram.DatagramSocket> rxBlockMulticastGroup(String multicastAddress, String sourceToBlock) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { blockMulticastGroup(multicastAddress, sourceToBlock, fut); })); }