List of usage examples for com.google.common.util.concurrent SettableFuture create
public static <V> SettableFuture<V> create()
From source file:com.mypurecloud.sdk.v2.api.BillingApiAsync.java
/** * Get a report of the billable usages (e.g. licenses and devices utilized) for a given period. * /*ww w . ja va 2s . com*/ * @param request the request object * @param callback the action to perform when the request is completed * @return the future indication when the request has completed */ public Future<ApiResponse<BillingUsageReport>> getBillingReportsBillableusageAsync(ApiRequest<Void> request, final AsyncApiCallback<ApiResponse<BillingUsageReport>> callback) { try { final SettableFuture<ApiResponse<BillingUsageReport>> future = SettableFuture.create(); final boolean shouldThrowErrors = pcapiClient.getShouldThrowErrors(); pcapiClient.invokeAsync(request, new TypeReference<BillingUsageReport>() { }, new AsyncApiCallback<ApiResponse<BillingUsageReport>>() { @Override public void onCompleted(ApiResponse<BillingUsageReport> response) { notifySuccess(future, callback, response); } @Override public void onFailed(Throwable exception) { if (exception instanceof ApiException) { @SuppressWarnings("unchecked") ApiResponse<BillingUsageReport> response = (ApiResponse<BillingUsageReport>) (ApiResponse<?>) exception; notifySuccess(future, callback, response); } if (shouldThrowErrors) { notifyFailure(future, callback, exception); } else { @SuppressWarnings("unchecked") ApiResponse<BillingUsageReport> response = (ApiResponse<BillingUsageReport>) (ApiResponse<?>) (new ApiException( exception)); notifySuccess(future, callback, response); } } }); return future; } catch (Throwable exception) { return Futures.immediateFailedFuture(exception); } }
From source file:com.google.devtools.build.lib.buildeventstream.transports.FileTransport.java
@Override public synchronized Future<Void> close() { if (closing()) { return closeFuture; }// w w w. java2 s. co m closeFuture = SettableFuture.create(); if (writesComplete()) { doClose(); } return closeFuture; }
From source file:com.microsoft.services.controllers.AuthenticationController.java
/** * Description: Calls AuthenticationContext.acquireToken(...) once to initialize with * user's credentials and avoid interactive prompt on later calls. * If all tokens expire, app must call initialize() again to prompt user interactively and * set up authentication context.//w w w . j av a2 s. c om * * @return A signal to wait on before continuing execution. */ public SettableFuture<Boolean> initialize() { final SettableFuture<Boolean> result = SettableFuture.create(); if (verifyAuthenticationContext()) { getAuthenticationContext().acquireToken(this.contextActivity, this.resourceId, ServiceConstants.CLIENT_ID, ServiceConstants.REDIRECT_URL, PromptBehavior.Auto, new AuthenticationCallback<AuthenticationResult>() { @Override public void onSuccess(final AuthenticationResult authenticationResult) { if (authenticationResult != null && authenticationResult.getStatus() == AuthenticationStatus.Succeeded) { dependencyResolver = new ADALDependencyResolver(getAuthenticationContext(), resourceId, ServiceConstants.CLIENT_ID); result.set(true); } } @Override public void onError(Exception t) { result.setException(t); } }); } else { result.setException(new Throwable("Auth context verification failed. Did you set a context activity?")); } return result; }
From source file:org.opendaylight.ofconfig.southbound.impl.api.ver12.helper.AbstractOfconfigVer12HandlerHelper.java
@Override public Future<RpcResult<Void>> doMerge(T request) { SettableFuture<RpcResult<Void>> resultFuture = SettableFuture.create(); try {/*w w w .j av a 2 s .c o m*/ String netconfigId = getNetconfigTopoNodeId(request); Optional<CapableSwitch> capableSwitchOptional = getDeviceCapableSwitch(netconfigId); if (!capableSwitchOptional.isPresent()) { return buildNotFoundResult(netconfigId); } CapableSwitch newCapableSwitch = mergeCapableSwitch(capableSwitchOptional.get(), request); updateDeviceCapableSwitch(newCapableSwitch, netconfigId); updateOfOfconfig(netconfigId); resultFuture.set(RpcResultBuilder.<Void>success().build()); } catch (Exception e) { String netconfigId = getNetconfigTopoNodeId(request); logger.error("merge operation occurr error,netconf topo node id:{}", netconfigId, e); resultFuture.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, "merge operation occurr error,netconf topo node id:{}", netconfigId).build()); } return resultFuture; }
From source file:com.continuuity.weave.zookeeper.ZKOperations.java
public static ListenableFuture<String> watchDeleted(final ZKClient zkClient, final String path) { SettableFuture<String> completion = SettableFuture.create(); watchDeleted(zkClient, path, completion); return completion; }
From source file:com.twitter.heron.statemgr.NullStateManager.java
@Override public ListenableFuture<TopologyAPI.Topology> getTopology(WatchCallback watcher, String topologyName) { return SettableFuture.create(); }
From source file:org.opendaylight.openflowjava.protocol.impl.integration.MockPlugin.java
/** Creates MockPlugin */ public MockPlugin() { LOGGER.trace("Creating MockPlugin"); finishedFuture = SettableFuture.create(); LOGGER.debug("mockPlugin: " + System.identityHashCode(this)); }
From source file:org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl.java
@Override public Future<List<Boolean>> startup() { LOGGER.debug("startup summoned"); ListenableFuture<List<Boolean>> result = SettableFuture.create(); try {//from w w w. j a v a 2 s . c o m if (serverLot.isEmpty()) { throw new IllegalStateException("No servers configured"); } for (ServerFacade server : serverLot) { if (server.getIsOnlineFuture().isDone()) { throw new IllegalStateException("Servers already running"); } } if (switchConnectionHandler == null) { throw new IllegalStateException("switchConnectionHandler is not set"); } List<ListenableFuture<Boolean>> starterChain = new ArrayList<>(); for (ServerFacade server : serverLot) { new Thread(server).start(); ListenableFuture<Boolean> isOnlineFuture = server.getIsOnlineFuture(); starterChain.add(isOnlineFuture); } if (!starterChain.isEmpty()) { result = Futures.allAsList(starterChain); } else { throw new IllegalStateException("No servers configured"); } } catch (Exception e) { SettableFuture<List<Boolean>> exFuture = SettableFuture.create(); exFuture.setException(e); result = exFuture; } return result; }
From source file:com.facebook.buck.rules.AbstractCachingBuildRule.java
protected AbstractCachingBuildRule(BuildRuleParams buildRuleParams) { super(buildRuleParams); this.hasBuildStarted = new AtomicBoolean(false); this.buildRuleResult = SettableFuture.create(); this.buildable = Preconditions.checkNotNull(getBuildable()); }
From source file:org.midonet.midolman.state.zkManagers.TunnelZoneZkManager.java
public Set<TunnelZone.HostConfig> getZoneMembershipsForHosts(UUID zoneId, Set<UUID> hosts) throws StateAccessException, SerializationException { Map<UUID, Future<byte[]>> futures = new HashMap<UUID, Future<byte[]>>(); for (UUID host : hosts) { String zoneMembershipPath = paths.getTunnelZoneMembershipPath(zoneId, host); final SettableFuture<byte[]> f = SettableFuture.create(); zk.asyncGet(zoneMembershipPath, new DirectoryCallback<byte[]>() { @Override//from w w w. j a va 2s.co m public void onTimeout() { f.setException(new TimeoutException()); } @Override public void onError(KeeperException e) { f.setException(e); } @Override public void onSuccess(byte[] data) { f.set(data); } }, null); futures.put(host, f); } Set<TunnelZone.HostConfig> configs = new HashSet<TunnelZone.HostConfig>(); for (Map.Entry<UUID, Future<byte[]>> entry : futures.entrySet()) { try { TunnelZone.HostConfig.Data config = serializer.deserialize(entry.getValue().get(), TunnelZone.HostConfig.Data.class); configs.add(new TunnelZone.HostConfig(entry.getKey(), config)); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); throw new StateAccessException(ie); } catch (ExecutionException ee) { if (ee.getCause() instanceof KeeperException.NoNodeException) { // ignore, membership simply didn't exist } else { throw new StateAccessException(ee.getCause()); } } } return configs; }