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:com.android.camera.device.MultiCameraDeviceLifecycle.java

private void completeShutdown() {
    if (mShutdownFuture != null) {
        mLogger.i("Completing shutdown.");
        SettableFuture<Void> shutdownFuture = mShutdownFuture;
        mShutdownFuture = null;/*from   www.java  2s .c o m*/
        shutdownFuture.set(null);
    }
}

From source file:org.retrostore.android.view.ImageLoader.java

public ListenableFuture<Bitmap> loadAsBitmapAsync(final String url, final int width, final int height) {
    final SettableFuture<Bitmap> future = SettableFuture.create();
    final Context context = mCtx.get();
    if (context == null) {
        future.setException(new RuntimeException("Context invalid."));
        return future;
    }//from w w w.j av a2 s. c o  m

    mExecutor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                future.set(Glide.with(context).load(url).asBitmap().into(width, height).get());
            } catch (InterruptedException | ExecutionException e) {
                Log.e(TAG, "Could not load image as bitmap.", e);
                future.setException(e);
            }
        }
    });
    return future;
}

From source file:org.apache.qpid.server.security.auth.manager.AbstractAuthenticationManager.java

private ListenableFuture<Void> performDelete() {
    final SettableFuture<Void> futureResult = SettableFuture.create();
    addFutureCallback(closeAsync(), new FutureCallback<Void>() {
        @Override//  w ww . j  av  a  2s  .  c  o m
        public void onSuccess(final Void result) {
            try {
                tidyUp();
                futureResult.set(null);
            } catch (Exception e) {
                futureResult.setException(e);
            }
        }

        @Override
        public void onFailure(final Throwable t) {
            try {
                tidyUp();
            } finally {
                futureResult.setException(t);
            }
        }

        private void tidyUp() {
            deleted();
            setState(State.DELETED);
            _eventLogger.message(AuthenticationProviderMessages.DELETE(getName()));
        }
    }, getTaskExecutor());

    return futureResult;
}

From source file:org.apache.gobblin.r2.D2ClientProxy.java

private D2Client buildClient(D2ClientBuilder builder) {
    D2Client d2 = builder.build();/*from w  w  w. j  a va  2 s. c o  m*/
    final SettableFuture<None> d2ClientFuture = SettableFuture.create();
    d2.start(new Callback<None>() {
        @Override
        public void onError(Throwable e) {
            d2ClientFuture.setException(e);
        }

        @Override
        public void onSuccess(None none) {
            d2ClientFuture.set(none);
        }
    });

    try {
        // Synchronously wait for d2 to start
        d2ClientFuture.get();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
    return d2;
}

From source file:org.opendaylight.controller.cluster.sharding.ShardProxyTransaction.java

@Override
public ListenableFuture<Boolean> validate() {
    LOG.debug("Validating transaction for shard {}", shardRoot);

    checkTransactionReadied();//ww w  .  j  ava  2  s  . c o  m
    final List<ListenableFuture<Boolean>> futures = cohorts.stream()
            .map(DOMStoreThreePhaseCommitCohort::canCommit).collect(Collectors.toList());
    final SettableFuture<Boolean> ret = SettableFuture.create();

    Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Boolean>>() {
        @Override
        public void onSuccess(final List<Boolean> result) {
            ret.set(true);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            ret.setException(throwable);
        }
    }, MoreExecutors.directExecutor());

    return ret;
}

From source file:org.robotninjas.barge.jaxrs.client.BargeJaxRsClient.java

@Override
public ListenableFuture<RequestVoteResponse> requestVote(RequestVote request) {
    final SettableFuture<RequestVoteResponse> result = SettableFuture.create();

    client.target(baseUri).path("/raft/vote").request().async()
            .post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE), new InvocationCallback<Response>() {
                @Override/*  w  ww .  j  av  a  2 s. c o  m*/
                public void completed(Response response) {
                    result.set(response.readEntity(RequestVoteResponse.class));
                }

                @Override
                public void failed(Throwable throwable) {
                    result.setException(throwable);
                }
            });

    return result;
}

From source file:org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils.java

/**
 * Update mcast macs for this elan.//from   www  .jav  a2  s  .c o  m
 * for all dpns in this elan  recompute and update broadcast group
 * for all l2gw devices in this elan recompute and update remote mcast mac entry
 *
 * @param elanName
 *            the elan name
 * @param device
 *            the device
 * @param updateThisDevice
 *            the update this device
 * @return the listenable future
 */
public ListenableFuture<Void> updateMcastMacsForAllElanDevices(String elanName, L2GatewayDevice device,
        boolean updateThisDevice) {

    SettableFuture<Void> ft = SettableFuture.create();
    ft.set(null);

    ElanInstance elanInstance = elanInstanceManager.getElanInstanceByName(elanName);
    elanInterfaceManager.updateRemoteBroadcastGroupForAllElanDpns(elanInstance);

    List<DpnInterfaces> dpns = elanUtils.getInvolvedDpnsInElan(elanName);

    ConcurrentMap<String, L2GatewayDevice> devices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);

    List<IpAddress> dpnsTepIps = getAllTepIpsOfDpns(device, dpns);
    List<IpAddress> l2GwDevicesTepIps = getAllTepIpsOfL2GwDevices(devices);
    // if (allTepIps.size() < 2) {
    // LOG.debug("no other devices are found in the elan {}", elanName);
    // return ft;
    // }

    WriteTransaction transaction = broker.newWriteOnlyTransaction();
    if (updateThisDevice) {
        preapareRemoteMcastMacEntry(transaction, elanName, device, dpnsTepIps, l2GwDevicesTepIps);
    }

    // TODO: Need to revisit below logic as logical switches might not be
    // present to configure RemoteMcastMac entry
    for (L2GatewayDevice otherDevice : devices.values()) {
        if (!otherDevice.getDeviceName().equals(device.getDeviceName())) {
            preapareRemoteMcastMacEntry(transaction, elanName, otherDevice, dpnsTepIps, l2GwDevicesTepIps);
        }
    }
    return transaction.submit();

}

From source file:org.robotninjas.barge.jaxrs.client.BargeJaxRsClient.java

@Override
public ListenableFuture<AppendEntriesResponse> appendEntries(AppendEntries request) {
    final SettableFuture<AppendEntriesResponse> result = SettableFuture.create();

    client.target(baseUri).path("/raft/entries").request().async()
            .post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE), new InvocationCallback<Response>() {
                @Override//w w  w.j  a v  a  2s  . c  om
                public void completed(Response response) {
                    result.set(response.readEntity(AppendEntriesResponse.class));
                }

                @Override
                public void failed(Throwable throwable) {
                    result.setException(throwable);
                }
            });

    return result;
}

From source file:zipkin.storage.cassandra.DeduplicatingExecutor.java

/**
 * @param session which conditionally executes bound statements
 * @param ttl how long the results of statements are remembered, in milliseconds.
 *//*from  w  w  w  .j  a va2 s .c o  m*/
DeduplicatingExecutor(Session session, long ttl) {
    this.session = session;
    this.cache = CacheBuilder.newBuilder().expireAfterWrite(ttl, TimeUnit.MILLISECONDS).ticker(new Ticker() {
        @Override
        public long read() {
            return nanoTime();
        }
    })
            // TODO: maximum size or weight
            .build(new CacheLoader<BoundStatementKey, ListenableFuture<Void>>() {
                @Override
                public ListenableFuture<Void> load(final BoundStatementKey key) {
                    ListenableFuture<?> cassandraFuture = executeAsync(key.statement);

                    // Drop the cassandra future so that we don't hold references to cassandra state for
                    // long periods of time.
                    final SettableFuture<Void> disconnectedFuture = SettableFuture.create();
                    Futures.addCallback(cassandraFuture, new FutureCallback<Object>() {

                        @Override
                        public void onSuccess(Object result) {
                            disconnectedFuture.set(null);
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            cache.invalidate(key);
                            disconnectedFuture.setException(t);
                        }
                    });
                    return disconnectedFuture;
                }
            });
}

From source file:org.kurento.jsonrpc.internal.ws.PendingRequests.java

public void handleResponse(Response<JsonElement> response) {

    SettableFuture<Response<JsonElement>> responseFuture = pendingRequests.remove(response.getId());

    if (responseFuture == null) {
        // TODO It is necessary to do something else? Who is watching this?
        log.warn(/*w  w w .j  ava  2  s .  c  om*/
                "Received response {} with an id not registered as pending request. Maybe the request timed out",
                response);
    } else {
        responseFuture.set(response);
    }
}