List of usage examples for com.google.common.util.concurrent Futures immediateFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFuture(@Nullable V value)
From source file:org.opendaylight.sxp.route.ClusterSanityWatchdogInstance.java
@Override public synchronized ListenableFuture<Void> closeServiceInstance() { LOG.debug("Watched service fall asleep - tearing down scheduler"); datastoreAccess.close();/*from w ww .j a v a2 s .c o m*/ timer.cancel(true); isActive.set(false); return Futures.immediateFuture(null); }
From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java
@Override public <T> Future<Set<T>> putIfUntouched(Map<T, CasValues> values, Expiration expiration) { return Futures.immediateFuture(memcacheService.putIfUntouched(values, expiration)); }
From source file:org.opendaylight.faas.fabric.general.EndPointRegister.java
@Override public Future<RpcResult<RegisterEndpointOutput>> registerEndpoint(RegisterEndpointInput input) { final RpcResultBuilder<RegisterEndpointOutput> resultBuilder = RpcResultBuilder .<RegisterEndpointOutput>success(); final RegisterEndpointOutputBuilder outputBuilder = new RegisterEndpointOutputBuilder(); final FabricId fabricid = input.getFabricId(); final FabricInstance fabricObj = FabricInstanceCache.INSTANCE.retrieveFabric(fabricid); if (fabricObj == null) { return Futures.immediateFailedFuture(new IllegalArgumentException("fabric is not exist!")); }/*from w w w. ja v a 2 s. c om*/ Uuid epId = input.getEndpointUuid(); if (epId == null) { epId = new Uuid(UUID.randomUUID().toString()); } final Uuid newepId = epId; final InstanceIdentifier<Endpoint> eppath = Constants.DOM_ENDPOINTS_PATH.child(Endpoint.class, new EndpointKey(newepId)); EndpointBuilder epBuilder = new EndpointBuilder(); epBuilder.setEndpointUuid(newepId); epBuilder.setGateway(input.getGateway()); epBuilder.setIpAddress(input.getIpAddress()); epBuilder.setLocation(input.getLocation()); epBuilder.setLogicalLocation(input.getLogicalLocation()); epBuilder.setMacAddress(input.getMacAddress()); epBuilder.setPublicIp(input.getPublicIp()); epBuilder.setOwnFabric(fabricid); ReadWriteTransaction trans = dataBroker.newReadWriteTransaction(); trans.put(LogicalDatastoreType.OPERATIONAL, eppath, epBuilder.build(), true); CheckedFuture<Void, TransactionCommitFailedException> future = trans.submit(); return Futures.transform(future, new AsyncFunction<Void, RpcResult<RegisterEndpointOutput>>() { @Override public ListenableFuture<RpcResult<RegisterEndpointOutput>> apply(Void input) throws Exception { outputBuilder.setEndpointId(newepId); return Futures.immediateFuture(resultBuilder.withResult(outputBuilder.build()).build()); } }, executor); }
From source file:com.microsoft.azure.keyvault.cryptography.RsaKey.java
@Override public ListenableFuture<Pair<byte[], String>> wrapKeyAsync(final byte[] key, final String algorithm) throws NoSuchAlgorithmException { if (key == null) { throw new IllegalArgumentException("key"); }/*from ww w. ja va2 s .c o m*/ // Interpret the requested algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm) ? getDefaultKeyWrapAlgorithm() : algorithm); Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithmName); } AsymmetricEncryptionAlgorithm algo = (AsymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform; ListenableFuture<Pair<byte[], String>> result; try { transform = algo.CreateEncryptor(_keyPair, _provider); result = Futures.immediateFuture(Pair.of(transform.doFinal(key), algorithmName)); } catch (Exception e) { result = Futures.immediateFailedFuture(e); } return result; }
From source file:org.opendaylight.controller.config.yang.sxp.controller.conf.SxpControllerInstance.java
@Override public synchronized ListenableFuture<Void> closeServiceInstance() { LOG.warn("Clustering provider closed service for {}", this.getClass().getSimpleName()); dataChangeListenerRegistrations.forEach(ListenerRegistration<DataTreeChangeListener>::close); dataChangeListenerRegistrations.clear(); Configuration.getNodes().forEach(n -> { if (n instanceof SxpDatastoreNode) { ((SxpDatastoreNode) n).close(); } else {// w w w. ja v a2 s . c om n.shutdown(); } }); datastoreAccess.close(); return Futures.immediateFuture(null); }
From source file:com.spotify.folsom.client.binary.DefaultBinaryMemcacheClient.java
private ListenableFuture<List<GetResult<V>>> multiget(List<String> keys, int ttl) { final int size = keys.size(); if (size == 0) { return Futures.immediateFuture(Collections.<GetResult<V>>emptyList()); }/*from w w w. j a va2 s . c o m*/ final List<List<String>> keyPartition = Lists.partition(keys, MemcacheEncoder.MAX_MULTIGET_SIZE); final List<ListenableFuture<List<GetResult<byte[]>>>> futureList = new ArrayList<>(keyPartition.size()); for (final List<String> part : keyPartition) { MultigetRequest request = MultigetRequest.create(part, charset, ttl); futureList.add(rawMemcacheClient.send(request)); } final ListenableFuture<List<GetResult<byte[]>>> future = Utils.transform(Futures.allAsList(futureList), Utils.<GetResult<byte[]>>flatten()); metrics.measureMultigetFuture(future); return transformerUtil.decodeList(future); }
From source file:com.facebook.buck.rules.UnskippedRulesTracker.java
private ListenableFuture<Void> releaseReference(BuildRule rule) { AtomicInteger referenceCount = ruleReferenceCounts.getUnchecked(rule.getBuildTarget()); int newValue = referenceCount.decrementAndGet(); if (newValue == 0) { // 1 -> 0 transition means that the rule can be marked as skipped. unskippedRules.decrementAndGet(); stateChanged.set(true);//from w ww . j a v a2 s . c om // Remove references from all dependencies of the rule. return Futures.transformAsync(ruleDepsCache.get(rule), releaseReferences, executor); } return Futures.immediateFuture(null); }
From source file:com.facebook.buck.event.listener.util.ProgressEstimator.java
/** * Indicates that buck has finished parsing, updating the progress estimation accordingly * * @return a future that completes when estimation calculation is complete */// www. java 2s. co m public Future<?> didFinishParsing() { if (command != null) { return runAsync(() -> { expectedNumberOfParsedRules.set(numberOfParsedRules.get()); expectedNumberOfParsedBUCKFiles.set(numberOfParsedBUCKFiles.get()); calculateParsingBuckFilesEstimatedProgress(); updateEstimatedBuckFilesParsingValues(command); }); } return Futures.immediateFuture(null); }
From source file:org.opendaylight.controller.clustering.it.provider.impl.WriteTransactionsHandler.java
public static ListenableFuture<RpcResult<WriteTransactionsOutput>> start(final DOMDataBroker domDataBroker, final WriteTransactionsInput input) { LOG.debug("Starting write-transactions."); final String id = input.getId(); final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id) .withChild(ImmutableNodes.mapNodeBuilder(ITEM).build()).build(); final YangInstanceIdentifier idListItem = ID_INT_YID.node(entry.getIdentifier()); final ContainerNode containerNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new NodeIdentifier(ID_INTS)) .withChild(ImmutableNodes.mapNodeBuilder(ID_INT).build()).build(); DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction(); // write only the top list tx.merge(LogicalDatastoreType.CONFIGURATION, ID_INTS_YID, containerNode); try {// w ww. ja va2 s.c o m tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (final OptimisticLockFailedException e) { // when multiple write-transactions are executed concurrently we need to ignore this. // If we get optimistic lock here it means id-ints already exists and we can continue. LOG.debug("Got an optimistic lock when writing initial top level list element.", e); } catch (final TransactionCommitFailedException | TimeoutException e) { LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e); return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed() .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build()); } tx = domDataBroker.newWriteOnlyTransaction(); tx.merge(LogicalDatastoreType.CONFIGURATION, idListItem, entry); try { tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e); return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed() .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build()); } LOG.debug("Filling the item list with initial values."); final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ITEM); final YangInstanceIdentifier itemListId = idListItem.node(ITEM); tx = domDataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, mapBuilder.build()); try { tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to fill the initial item list.", e); return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed() .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build()); } final WriteTransactionsHandler handler; if (input.isChainedTransactions()) { handler = new Chained(domDataBroker, idListItem, input); } else { handler = new Simple(domDataBroker, idListItem, input); } handler.doStart(); return handler.completionFuture; }