List of usage examples for com.google.common.util.concurrent Futures transform
public static <I, O> ListenableFuture<O> transform(ListenableFuture<I> input, Function<? super I, ? extends O> function)
From source file:io.v.impl.google.rpc.StreamImpl.java
@Override public ListenableFuture<Object> recv(final Type type) { ListenableFutureCallback<byte[]> callback = new ListenableFutureCallback<>(); nativeRecv(nativeRef, callback);//from w w w .j a va 2 s . c o m return VFutures.withUserLandChecks(ctx, Futures.transform(callback.getVanillaFuture(), new AsyncFunction<byte[], Object>() { @Override public ListenableFuture<Object> apply(byte[] result) throws Exception { return Futures.immediateFuture(VomUtil.decode(result, type)); } })); }
From source file:com.noorq.casser.core.operation.AbstractStreamOperation.java
public ListenableFuture<PreparedStreamOperation<E>> prepareAsync() { final O _this = (O) this; return Futures.transform(prepareStatementAsync(), new Function<PreparedStatement, PreparedStreamOperation<E>>() { @Override/* w w w .j a v a 2s . co m*/ public PreparedStreamOperation<E> apply(PreparedStatement preparedStatement) { return new PreparedStreamOperation<E>(preparedStatement, _this); } }); }
From source file:com.noorq.casser.core.operation.AbstractOptionalOperation.java
public ListenableFuture<PreparedOptionalOperation<E>> prepareAsync() { final O _this = (O) this; return Futures.transform(prepareStatementAsync(), new Function<PreparedStatement, PreparedOptionalOperation<E>>() { @Override/* w w w. j ava 2s .co m*/ public PreparedOptionalOperation<E> apply(PreparedStatement preparedStatement) { return new PreparedOptionalOperation<E>(preparedStatement, _this); } }); }
From source file:io.v.v23.syncbase.nosql.RowImpl.java
@Override public ListenableFuture<Object> get(VContext ctx, final Type type) { return Futures.transform(client.get(ctx, schemaVersion), new AsyncFunction<byte[], Object>() { @Override// w w w . j ava 2 s . c om public ListenableFuture<Object> apply(byte[] data) throws Exception { return Futures.immediateFuture(VomUtil.decode(data, type)); } }); }
From source file:org.robotninjas.concurrent.FluentFutureTask.java
@Override public <Y> FluentFuture<Y> transform(Function<V, Y> func) { return new FluentDecorator<>(Futures.transform(this, func)); }
From source file:com.skcraft.concurrency.DeferredImpl.java
@Override public Deferred<Void> thenRunAsync(final Runnable task, ListeningExecutorService executor) { return new DeferredImpl<Void>(Futures.transform(future, new Function<I, Void>() { @Override/*from w w w. ja v a 2 s . c o m*/ public Void apply(I input) { task.run(); return null; } }), defaultExecutor); }
From source file:io.v.v23.V23TestUtil.java
/** * Asserts that the given future is executed on the provided thread. * <p>/*w ww.j a va 2 s .c o m*/ * Note that this check is inherently racey: if the future has already completed, there is * no way to check on which thread it got executed. Therefore, this method should be executed * as close possible to the future's creation, to reduce the chance of the race happening. * Additionally, the future could be created with an executor that delays execution for a time * period that sufficient to all but prohibit races (e.g., 100ms). */ public static <T> void assertRunsOnThread(ListenableFuture<T> future, final Thread thread) { try { assertThat(future.isDone()).isFalse(); Futures.transform(future, new AsyncFunction<T, Void>() { @Override public ListenableFuture<Void> apply(T input) throws Exception { assertThat(Thread.currentThread()).isEqualTo(thread); return Futures.immediateFuture(null); } }).get(); } catch (Exception e) { Truth.assertWithMessage("error asserting executor").that(e.getMessage()).isEmpty(); } }
From source file:com.facebook.presto.split.SampledSplitSource.java
@Override public ListenableFuture<List<Split>> getNextBatch(int maxSize) { ListenableFuture<List<Split>> batch = splitSource.getNextBatch(maxSize); return Futures.transform(batch, splits -> splits.stream().filter(input -> ThreadLocalRandom.current().nextDouble() < sampleRatio) .collect(toImmutableList())); }
From source file:io.v.v23.syncbase.RowImpl.java
@Override public <T> ListenableFuture<T> get(VContext ctx, final Class<T> clazz) { return VFutures.withUserLandChecks(ctx, Futures.transform(client.get(ctx, this.batchHandle), new AsyncFunction<VdlAny, T>() { @Override//from w w w. j a v a2 s .c om public ListenableFuture<T> apply(VdlAny vdlAny) throws Exception { final byte[] encodedBytes = VomUtil.encode(vdlAny, VdlAny.VDL_TYPE); final Object decodedObject = VomUtil.decode(encodedBytes, clazz); return Futures.immediateFuture((T) decodedObject); } })); }
From source file:com.google.pubsub.clients.adapter.AdapterTask.java
@Override public ListenableFuture<RunResult> doRun() { return Futures.transform(stub.execute(LoadtestProto.ExecuteRequest.getDefaultInstance()), response -> RunResult.fromMessages(response.getReceivedMessagesList(), response.getLatenciesList())); }