List of usage examples for com.google.common.util.concurrent SettableFuture create
public static <V> SettableFuture<V> create()
From source file:com.microsoft.directoryservices.odata.DirectoryObjectOperations.java
/** * checkMemberGroups listenable future./*from ww w. j av a 2s . c om*/ * @param groupIds the groupIds * @return the listenable future */ public ListenableFuture<String> checkMemberGroups(java.util.List<String> groupIds) { final SettableFuture<String> result = SettableFuture.create(); java.util.Map<String, Object> map = new java.util.HashMap<String, Object>(); map.put("groupIds", groupIds); Request request = getResolver().createRequest(); request.setVerb(HttpVerb.POST); request.setContent(serializeToJsonByteArray(map, getResolver())); String parameters = getFunctionParameters(map); request.getUrl().appendPathComponent("checkMemberGroups(" + parameters + ")"); ListenableFuture<ODataResponse> future = oDataExecute(request); return transformToEntityListenableFuture(transformToStringListenableFuture(future), String.class, getResolver()); }
From source file:c5db.replication.InternalReplicationRequest.java
private InternalReplicationRequest(List<ByteBuffer> data, QuorumConfiguration config) { this.data = data; this.config = config; this.logReceiptFuture = SettableFuture.create(); }
From source file:com.android.builder.internal.packaging.zip.compress.ExecutorCompressor.java
@NonNull @Override// ww w .j a v a2s. co m public ListenableFuture<CompressionResult> compress(@NonNull final CloseableByteSource source) { final SettableFuture<CompressionResult> future = SettableFuture.create(); mExecutor.execute(() -> { try { future.set(immediateCompress(source)); } catch (Exception e) { future.setException(e); } }); return future; }
From source file:org.opendaylight.genius.utils.clustering.ClusteringUtils.java
public static ListenableFuture<Boolean> checkNodeEntityOwner(EntityOwnershipService entityOwnershipService, Entity entity, long sleepBetweenRetries, int maxRetries) { SettableFuture<Boolean> checkNodeEntityfuture = SettableFuture.create(); CheckEntityOwnerTask checkEntityOwnerTask = new CheckEntityOwnerTask(entityOwnershipService, entity, checkNodeEntityfuture, sleepBetweenRetries, maxRetries); getDataStoreJobCoordinator().enqueueJob(entityOwnershipService.toString(), checkEntityOwnerTask); return checkNodeEntityfuture; }
From source file:org.anhonesteffort.chnlbrkr.stream.ChannelStreamerFactory.java
public ListenableFuture<ChannelStreamer> create(IdleChnlzrConnection connection, WriteQueuingContext client, ChannelRequest.Reader request) { MessageBuilder capabilities = CapnpUtil.builder(connection.getCapabilitiesMessage()); SettableFuture<ChannelRequestHandler> requestFuture = SettableFuture.create(); SettableFuture<ChannelStreamer> streamFuture = SettableFuture.create(); ChannelRequestHandler requestHandler = new ChannelRequestHandler(requestFuture, request, connection.getId(), config.chnlzrRequestAnswerTimeoutMs()); connection.getContext().pipeline().replace(connection, "request", requestHandler); Futures.addCallback(requestFuture, new ChannelRequestCallback(streamFuture, client, capabilities)); return streamFuture; }
From source file:com.microsoft.directoryservices.odata.UserOperations.java
/** * assignLicense listenable future./*w w w . j a v a 2s . c om*/ * @param addLicenses the addLicenses @param removeLicenses the removeLicenses * @return the listenable future */ public ListenableFuture<User> assignLicense(java.util.List<AssignedLicense> addLicenses, java.util.List<java.util.UUID> removeLicenses) { final SettableFuture<User> result = SettableFuture.create(); java.util.Map<String, Object> map = new java.util.HashMap<String, Object>(); map.put("addLicenses", addLicenses); map.put("removeLicenses", removeLicenses); Request request = getResolver().createRequest(); request.setVerb(HttpVerb.POST); request.setContent(serializeToJsonByteArray(map, getResolver())); String parameters = getFunctionParameters(map); request.getUrl().appendPathComponent("assignLicense(" + parameters + ")"); ListenableFuture<ODataResponse> future = oDataExecute(request); return transformToEntityListenableFuture(transformToStringListenableFuture(future), User.class, getResolver()); }
From source file:org.anhonesteffort.p25.chnlzr.ChnlzrController.java
public ListenableFuture<SamplesSourceHandler> createSourceFor(ChannelRequest.Reader request) { P25DcodrMetrics.getInstance().chnlzrRequest(request.getCenterFrequency()); ListenableFuture<ChnlzrConnectionHandler> connectFuture = factory.create(chnlzrHost); SettableFuture<SamplesSourceHandler> sourceFuture = SettableFuture.create(); Futures.addCallback(connectFuture, new ChnlzrConnectionCallback(sourceFuture, request)); return sourceFuture; }
From source file:com.microsoft.office365.connect.DiscoveryController.java
/** * Provides information about the service that corresponds to the provided * capability./*from ww w .ja v a2 s. c o m*/ * @param capability A string that contains the capability of the service that * is going to be discovered. * @return A signal to wait on before continuing execution. The signal contains the * ServiceInfo object with extra information about discovered service. */ public SettableFuture<ServiceInfo> getServiceInfo(final String capability) { final SettableFuture<ServiceInfo> result = SettableFuture.create(); // First, look in the locally cached services. if (mServices != null) { boolean serviceFound = false; for (ServiceInfo service : mServices) { if (service.getcapability().equals(capability)) { Log.i(TAG, "getServiceInfo - " + service.getserviceName() + " service for " + capability + " was found in local cached services"); result.set(service); serviceFound = true; break; } } if (!serviceFound) { NoSuchElementException noSuchElementException = new NoSuchElementException( "The " + capability + " capability was not found in the local cached services."); Log.e(TAG, "getServiceInfo - " + noSuchElementException.getMessage()); result.setException(noSuchElementException); } } else { // The services have not been cached yet. Go ask the discovery service. AuthenticationManager.getInstance().setResourceId(Constants.DISCOVERY_RESOURCE_ID); ADALDependencyResolver dependencyResolver = (ADALDependencyResolver) AuthenticationManager.getInstance() .getDependencyResolver(); DiscoveryClient discoveryClient = new DiscoveryClient(Constants.DISCOVERY_RESOURCE_URL, dependencyResolver); try { ListenableFuture<List<ServiceInfo>> future = discoveryClient.getservices().read(); Futures.addCallback(future, new FutureCallback<List<ServiceInfo>>() { @Override public void onSuccess(final List<ServiceInfo> services) { Log.i(TAG, "getServiceInfo - Services discovered\n"); // Save the discovered services to serve further requests from the local cache. mServices = services; boolean serviceFound = false; for (ServiceInfo service : services) { if (service.getcapability().equals(capability)) { Log.i(TAG, "getServiceInfo - " + service.getserviceName() + " service for " + capability + " was found in services retrieved from discovery"); result.set(service); serviceFound = true; break; } } if (!serviceFound) { NoSuchElementException noSuchElementException = new NoSuchElementException( "The " + capability + " capability was not found in the user services."); Log.e(TAG, "getServiceInfo - " + noSuchElementException.getMessage()); result.setException(noSuchElementException); } } @Override public void onFailure(Throwable t) { Log.e(TAG, "getServiceInfo - " + t.getMessage()); result.setException(t); } }); } catch (Exception e) { Log.e(TAG, "getServiceInfo - " + e.getMessage()); result.setException(e); } } return result; }
From source file:io.v.v23.syncbase.nosql.NoSql.java
private static ListenableFuture<Boolean> tryBatch(final VContext ctx, final Database db, final BatchOptions opts, final BatchOperation op) { final SettableFuture<Boolean> ret = SettableFuture.create(); Futures.addCallback(db.beginBatch(ctx, opts), new FutureCallback<BatchDatabase>() { @Override//from w w w .ja va 2 s . c om public void onFailure(Throwable t) { ret.setException(t); } @Override public void onSuccess(final BatchDatabase batch) { Futures.addCallback(op.run(batch), new FutureCallback<Void>() { @Override public void onFailure(final Throwable t) { Futures.addCallback(batch.abort(ctx), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { ret.setException(t); } @Override public void onFailure(Throwable newT) { ret.setException(t); } }); } @Override public void onSuccess(Void result) { Futures.addCallback(batch.commit(ctx), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { ret.set(true); // success } @Override public void onFailure(Throwable t) { if (t instanceof ConcurrentBatchException) { // retry ret.set(false); } else { ret.setException(t); } } }); } }); } }); return ret; }
From source file:com.microsoftopentechnologies.auth.browser.BrowserLauncherDefault.java
@Override public ListenableFuture<Void> browseAsync(String url, String redirectUrl, String callbackUrl, String windowTitle, boolean noShell) { SettableFuture<Void> future = SettableFuture.create(); executorService.submit(new LauncherTask(future, url, redirectUrl, callbackUrl, windowTitle, noShell)); return future; }