Example usage for com.google.common.util.concurrent Futures immediateFuture

List of usage examples for com.google.common.util.concurrent Futures immediateFuture

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures immediateFuture.

Prototype

@CheckReturnValue
public static <V> ListenableFuture<V> immediateFuture(@Nullable V value) 

Source Link

Document

Creates a ListenableFuture which has its value set immediately upon construction.

Usage

From source file:com.metamx.http.client.GoHandlers.java

public static GoHandler passingHandler(final Object retVal) {
    return new GoHandler() {
        @SuppressWarnings("unchecked")
        @Override/*from   w w  w  .  ja  v a 2  s.com*/
        public <Intermediate, Final> ListenableFuture<Final> go(Request request,
                HttpResponseHandler<Intermediate, Final> handler, Duration requestReadTimeout)
                throws Exception {
            return Futures.immediateFuture((Final) retVal);
        }
    };
}

From source file:io.v.v23.syncbase.Batch.java

/**
 * Runs the given batch operation, managing retries and
 * {@link BatchDatabase#commit commit()}/{@link BatchDatabase#abort abort()}s.
 * <p>//from  ww  w . ja  v  a2s .  c om
 * The returned future is guaranteed to be executed on an {@link java.util.concurrent.Executor}
 * specified in {@code context} (see {@link io.v.v23.V#withExecutor}).
 * <p>
 * The returned future will fail with {@link java.util.concurrent.CancellationException} if
 * {@code context} gets canceled.
 *
 * @param context Vanadium context
 * @param db      database on which the batch operation is to be performed
 * @param opts    batch configuration
 * @param op      batch operation
 */
@CheckReturnValue
public static ListenableFuture<Void> runInBatch(VContext context, Database db, BatchOptions opts,
        BatchOperation op) {
    return VFutures.withUserLandChecks(context,
            Futures.transform(Futures.immediateFuture(false), getRetryFn(context, db, opts, op, 0)));
}

From source file:org.opendaylight.controller.messagebus.app.impl.Util.java

public static <T> Future<RpcResult<T>> resultFor(final T output) {
    final RpcResult<T> result = RpcResultBuilder.success(output).build();
    return Futures.immediateFuture(result);
}

From source file:com.facebook.nifty.processor.NiftyProcessorAdapters.java

/**
 * Adapt a {@link TProcessor} to a standard Thrift {@link NiftyProcessor}. Nifty uses this
 * internally to adapt the processors generated by the standard Thrift code generator into
 * instances of {@link NiftyProcessor} usable by {@link com.facebook.nifty.core.NiftyDispatcher}
 *//* w w w  .  j  a v a  2 s.  c om*/
public static NiftyProcessor processorFromTProcessor(final TProcessor standardThriftProcessor) {
    checkProcessMethodSignature();

    return new NiftyProcessor() {
        @Override
        public ListenableFuture<Boolean> process(TProtocol in, TProtocol out, RequestContext requestContext)
                throws TException {
            return Futures.immediateFuture(standardThriftProcessor.process(in, out));
        }
    };
}

From source file:test.SimpleProducerModule.java

@Produces
ListenableFuture<String> str() {
    return Futures.immediateFuture("Hello, World!");
}

From source file:io.v.v23.syncbase.nosql.NoSql.java

/**
 * Runs the given batch operation, managing retries and
 * {@link BatchDatabase#commit commit()}/{@link BatchDatabase#abort abort()}s.
 *
 * @param  ctx        Vanadium context/*from   www . jav  a2s . c o m*/
 * @param  db         database on which the batch operation is to be performed
 * @param  opts       batch configuration
 * @param  op         batch operation
 */
public static ListenableFuture<Void> runInBatch(VContext ctx, Database db, BatchOptions opts,
        BatchOperation op) {
    return Futures.transform(Futures.immediateFuture(false), getRetryFn(ctx, db, opts, op, 0));
}

From source file:io.v.impl.google.rpc.ServerRPCHelper.java

static ListenableFuture<byte[][]> prepare(Invoker invoker, VContext ctx, String method) {
    return Futures.transform(invoker.getMethodTags(ctx, method), new AsyncFunction<VdlValue[], byte[][]>() {
        @Override// ww  w  .j av  a 2s.  co m
        public ListenableFuture<byte[][]> apply(VdlValue[] tags) throws Exception {
            byte[][] vomTags = new byte[tags.length][];
            for (int i = 0; i < tags.length; ++i) {
                vomTags[i] = VomUtil.encode(tags[i], tags[i].vdlType());
            }
            return Futures.immediateFuture(vomTags);
        }
    });
}

From source file:test.ResponseProducerModule.java

@Produces
ListenableFuture<String> greeting() {
    return Futures.immediateFuture("Hello");
}

From source file:org.thingsboard.rule.engine.util.EntitiesRelatedDeviceIdAsyncLoader.java

public static ListenableFuture<DeviceId> findDeviceAsync(TbContext ctx, EntityId originator,
        DeviceRelationsQuery deviceRelationsQuery) {
    DeviceService deviceService = ctx.getDeviceService();
    DeviceSearchQuery query = buildQuery(originator, deviceRelationsQuery);

    ListenableFuture<List<Device>> asyncDevices = deviceService.findDevicesByQuery(ctx.getTenantId(), query);

    return Futures.transformAsync(asyncDevices,
            d -> CollectionUtils.isNotEmpty(d) ? Futures.immediateFuture(d.get(0).getId())
                    : Futures.immediateFuture(null));
}

From source file:org.robotninjas.concurrent.FluentFutures.java

/**
 * Create a {@link org.robotninjas.concurrent.FluentFuture}
 *
 * @param value//w w w.  j  a  v  a2  s. c o  m
 * @param executor
 * @param <Y>
 * @return
 */
public static <Y> FluentFuture<Y> from(Y value, Executor executor) {
    return new FluentDecorator<>(Futures.immediateFuture(value), executor);
}