Example usage for com.google.common.util.concurrent SettableFuture set

List of usage examples for com.google.common.util.concurrent SettableFuture set

Introduction

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

Prototype

@Override
    public boolean set(@Nullable V value) 

Source Link

Usage

From source file:org.opendaylight.ofconfig.southbound.impl.api.AbstractHandleHelper.java

protected Future<RpcResult<Void>> buildNotFoundResult(String nodeId) {

    SettableFuture<RpcResult<Void>> resultFuture = SettableFuture.create();

    RpcResult<Void> rpcResult = RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
            "No corresponding nodes are found in the topology,nodeId:" + nodeId).build();

    resultFuture.set(rpcResult);
    return resultFuture;

}

From source file:org.apache.spark.network.client.TransportClient.java

/**
 * Synchronously sends an opaque message to the RpcHandler on the server-side, waiting for up to
 * a specified timeout for a response./*from w  w w  . ja v a2 s.  c  om*/
 */
public byte[] sendRpcSync(byte[] message, long timeoutMs) {
    final SettableFuture<byte[]> result = SettableFuture.create();

    sendRpc(message, new RpcResponseCallback() {
        @Override
        public void onSuccess(byte[] response) {
            result.set(response);
        }

        @Override
        public void onFailure(Throwable e) {
            result.setException(e);
        }
    });

    try {
        return result.get(timeoutMs, TimeUnit.MILLISECONDS);
    } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.opendaylight.controller.cluster.databroker.actors.dds.RemoteProxyTransaction.java

private void completeExists(final SettableFuture<Boolean> future, final Response<?, ?> response) {
    LOG.debug("Exists request completed with {}", response);

    if (response instanceof ExistsTransactionSuccess) {
        future.set(((ExistsTransactionSuccess) response).getExists());
    } else {/*  w  w w  .j a v  a2s.  c o m*/
        failFuture(future, response);
    }
}

From source file:com.facebook.presto.operator.ExchangeClient.java

private synchronized void notifyBlockedCallers() {
    List<SettableFuture<?>> callers = ImmutableList.copyOf(blockedCallers);
    blockedCallers.clear();/*from ww  w  . ja va 2s .  co  m*/
    for (SettableFuture<?> blockedCaller : callers) {
        blockedCaller.set(null);
    }
}

From source file:org.retrostore.android.net.DataFetcher.java

/**
 * Turn the synchronous API requests into an asynchronous one and return a listenable future
 * with the result./*from  w  w w .  ja va  2  s .c  om*/
 */
public ListenableFuture<List<App>> getAppsAsync() {
    final SettableFuture<List<App>> future = SettableFuture.create();
    mRequestExecutor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                List<App> apps = mClient.fetchApps(0, 100);
                updateCache(apps);
                future.set(apps);
            } catch (ApiException e) {
                future.setException(e);
            }
        }
    });
    return future;
}

From source file:com.navercorp.nbasearc.gcp.GatewayConnectionPool.java

private SettableFuture<?> closeVirtualConnections() {
    final SettableFuture<?> future = SettableFuture.create();

    if (vcConcurrentSet.isEmpty()) {
        future.set(null);
    } else {// w w  w .  jav a 2 s .co m
        for (VirtualConnection vc : vcConcurrentSet) {
            vc.close().addListener(new Runnable() {
                @Override
                public void run() {
                    if (vcConcurrentSet.isEmpty()) {
                        future.set(null);
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }

    return future;
}

From source file:org.onosproject.store.trivial.impl.SimpleFlowRuleStore.java

@Override
public void batchOperationComplete(FlowRuleBatchEvent event) {
    final Long batchId = event.subject().batchId();
    SettableFuture<CompletedBatchOperation> future = pendingFutures.getIfPresent(batchId);
    if (future != null) {
        future.set(event.result());
        pendingFutures.invalidate(batchId);
    }/*w ww .ja  va 2  s.  c om*/
    notifyDelegate(event);
}

From source file:com.google.pubsub.flic.controllers.Controller.java

/**
 * Gets the results for all available types.
 *
 * @return the map from type to result, every type running is a valid key
 *//*  w w w.  ja  v a 2 s. c  om*/
public Map<Client.ClientType, LoadtestStats> getStatsForAllClientTypes() {
    final Map<Client.ClientType, LoadtestStats> results = new HashMap<>();
    List<ListenableFuture<Void>> resultFutures = new ArrayList<>();
    for (Client.ClientType type : Client.ClientType.values()) {
        SettableFuture<Void> resultFuture = SettableFuture.create();
        resultFutures.add(resultFuture);
        executor.submit(() -> {
            try {
                results.put(type, getStatsForClientType(type));
                resultFuture.set(null);
            } catch (Throwable t) {
                resultFuture.setException(t);
            }
        });
    }
    try {
        Futures.allAsList(resultFutures).get();
    } catch (ExecutionException | InterruptedException e) {
        log.error("Failed health check, will return results accumulated during test up to now.",
                e instanceof ExecutionException ? e.getCause() : e);
    }
    return results;
}

From source file:org.robotninjas.util.composition.FunctionComposition.java

public AsyncFunction<I, O> buildAsyncFunction() {

    return new AsyncFunction<I, O>() {
        @Override/*from   ww  w  . jav  a2  s.  c  om*/
        public ListenableFuture<O> apply(I input) throws Exception {
            final SettableFuture<I> start = SettableFuture.create();
            ListenableFuture<O> end = buildChain(start);
            start.set(input);
            return end;
        }
    };

}

From source file:org.opendaylight.messenger.impl.MessengerService.java

@Override
public Future<RpcResult<SendMessageOutput>> sendMessage(SendMessageInput input) {
    final SettableFuture<RpcResult<SendMessageOutput>> futureResult = SettableFuture.create();
    if (messProv.sendMessage(input.getMessId(), input.getMessageSource(), input.getMessageDest(),
            input.getText())) {/* www .j av a 2s . com*/
        final SendMessageOutput messOutput = new SendMessageOutputBuilder().setMessageId(input.getMessId())
                .build();
        futureResult.set(RpcResultBuilder.<SendMessageOutput>success(messOutput).build());
    } else {
        futureResult.set(RpcResultBuilder.<SendMessageOutput>failed().build());
    }
    return futureResult;
}