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.dcache.restful.util.cells.CellInfoCollector.java
@Override public Map<String, ListenableFutureWrapper<CellInfo>> collectData() throws InterruptedException { GetAllDomainsReply reply;/* w w w . j a v a 2 s. c o m*/ try { reply = stub.send(new CellPath("RoutingMgr"), new GetAllDomainsRequest(), GetAllDomainsReply.class) .get(); } catch (ExecutionException e) { LOGGER.error("Could not contact Routing Manager: {}, {}.", e.getMessage(), String.valueOf(e.getCause())); return Collections.EMPTY_MAP; } Map<String, ListenableFutureWrapper<CellInfo>> map = new TreeMap<>(); CellInfo frontendInfo = supplier.get(); /* * Remove Frontend, and substitute with the supplier. * Otherwise, the message fails. */ Collection<String> cells = reply.getDomains().get(frontendInfo.getDomainName()); cells.remove(frontendInfo.getCellName()); reply.getDomains().entrySet().stream().map(this::getCellPaths).flatMap(Collection::stream) .map(this::getCellInfo).forEach((future) -> map.put(future.getKey(), future)); ListenableFutureWrapper<CellInfo> wrapper = new ListenableFutureWrapper<>(); wrapper.setKey(frontendInfo.getCellName() + "@" + frontendInfo.getDomainName()); wrapper.setSent(System.currentTimeMillis()); wrapper.setFuture(Futures.immediateFuture(frontendInfo)); map.put(wrapper.getKey(), wrapper); return map; }
From source file:org.opendaylight.faas.fabric.general.FabricResourceAPIProvider.java
@Override public Future<RpcResult<AddFabricLinkOutput>> addFabricLink(AddFabricLinkInput input) { FabricId fabric1 = input.getSourceFabric(); FabricId fabric2 = input.getDestFabric(); TpId tp1 = input.getSourceFabricPort(); TpId tp2 = input.getDestFabricPort(); final LinkId lnkId = new LinkId(UUID.randomUUID().toString()); InstanceIdentifier<Link> path = MdSalUtils.createInterFabricLinkIId(lnkId); Link data = new LinkBuilder().setSource(new SourceBuilder().setSourceNode(fabric1).setSourceTp(tp1).build()) .setDestination(new DestinationBuilder().setDestNode(fabric2).setDestTp(tp2).build()) .setLinkId(lnkId).build();//from w ww . j a v a 2 s .c o m WriteTransaction wt = dataBroker.newWriteOnlyTransaction(); wt.put(LogicalDatastoreType.CONFIGURATION, path, data); wt.put(LogicalDatastoreType.OPERATIONAL, path, data); CheckedFuture<Void, TransactionCommitFailedException> future = wt.submit(); return Futures.transform(future, new AsyncFunction<Void, RpcResult<AddFabricLinkOutput>>() { @Override public ListenableFuture<RpcResult<AddFabricLinkOutput>> apply(Void submitResult) throws Exception { RpcResultBuilder<AddFabricLinkOutput> resultBuilder = RpcResultBuilder .<AddFabricLinkOutput>success(); AddFabricLinkOutput output = new AddFabricLinkOutputBuilder().setLinkId(lnkId).build(); return Futures.immediateFuture(resultBuilder.withResult(output).build()); } }); }
From source file:org.apache.qpid.server.security.AbstractKeyStore.java
protected final ListenableFuture<Void> deleteIfNotInUse() { // verify that it is not in use String storeName = getName(); Collection<Port> ports = new ArrayList<Port>(getBroker().getPorts()); for (Port port : ports) { if (port.getKeyStore() == this) { throw new IntegrityViolationException("Key store '" + storeName + "' can't be deleted as it is in use by a port:" + port.getName()); }/* ww w . j a va 2s .co m*/ } deleted(); setState(State.DELETED); getEventLogger().message(KeyStoreMessages.DELETE(getName())); return Futures.immediateFuture(null); }
From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java
@Override public Future<Boolean> put(Object key, Object value, Expiration expires, SetPolicy policy) { return Futures.immediateFuture(memcacheService.put(key, value, expires, policy)); }
From source file:org.codice.solr.factory.SolrServerFactory.java
public static Future<SolrServer> getHttpSolrServer(String url, String coreName, String configFile) { if (StringUtils.isBlank(url)) { url = SystemBaseUrl.constructUrl("/solr"); }/* ww w. j ava 2 s . c om*/ String coreUrl = url + "/" + coreName; SolrServer server; try { server = getSolrServer(url, coreName, configFile, coreUrl); } catch (Exception ex) { return pool.submit(new SolrServerFetcher(url, coreName, configFile, coreUrl)); } LOGGER.info("Created HTTP Solr server client ({})", coreUrl); return Futures.immediateFuture(server); }
From source file:com.facebook.buck.rules.UnskippedRulesTracker.java
private ListenableFuture<Void> acquireReference(BuildRule rule) { AtomicInteger referenceCount = ruleReferenceCounts.getUnchecked(rule.getBuildTarget()); int newValue = referenceCount.incrementAndGet(); if (newValue == 1) { // 0 -> 1 transition means that the rule might be used in the future (not skipped for now). unskippedRules.incrementAndGet(); stateChanged.set(true);/* w w w . ja va 2 s .co m*/ // Add references to all dependencies of the rule. return Futures.transformAsync(ruleDepsCache.get(rule), acquireReferences, executor); } return Futures.immediateFuture(null); }
From source file:com.facebook.buck.core.build.engine.cache.manager.InputBasedRuleKeyManager.java
public ListenableFuture<Optional<Pair<BuildRuleSuccessType, CacheResult>>> checkInputBasedCaches() { Optional<RuleKey> ruleKey; try (Scope ignored = buildRuleScopeManager.scope()) { // Calculate input-based rule key. ruleKey = inputBasedKey.get();// www .j a va 2 s . co m } if (ruleKey.isPresent()) { return performInputBasedCacheFetch(ruleKey.get()); } return Futures.immediateFuture(Optional.empty()); }
From source file:org.apache.shindig.social.websockbackend.spi.WsNativeFriendSPI.java
@Override public Future<RestfulCollection<Person>> getRequests(UserId userId, CollectionOptions collectionOptions, Set<String> fields, final SecurityToken token) { final List<Person> personList = new ArrayList<Person>(); final String sortField = collectionOptions.getSortBy(); if (sortField == null || sortField.equals(WsNativeFriendSPI.NAME_FIELD)) { collectionOptions.setSortBy(WsNativeFriendSPI.FORMATTED_FIELD); }//from w w w . j a v a 2s . co m // create query final WebsockQuery query = new WebsockQuery(EQueryType.PROCEDURE_CALL); query.setPayload(ShindigNativeQueries.GET_FRIEND_REQUESTS_QUERY); // set collection options CollOptsConverter.convert(collectionOptions, query); // set parameters for method query.setParameter(ShindigNativeQueries.USER_ID, userId.getUserId(token)); if (fields != null) { final List<String> fieldList = new ArrayList<String>(fields); query.setParameter(ShindigNativeQueries.FIELD_LIST, fieldList); } final IQueryCallback callback = this.fQueryHandler.sendQuery(query); ListResult result = null; try { result = (ListResult) callback.get(); } catch (final Exception e) { e.printStackTrace(); this.fLogger.log(Level.SEVERE, "server error", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "could not retrieve results", e); } @SuppressWarnings("unchecked") final List<Map<String, Object>> mapList = (List<Map<String, Object>>) result.getResults(); if (mapList != null) { String id = null; PersonDTO tmpPerson = null; for (final Map<String, Object> persMap : mapList) { tmpPerson = new PersonDTO(persMap); id = tmpPerson.getId(); // determine whether the person is viewer or owner if (token != null) { if (id.equals(token.getViewerId())) { tmpPerson.setIsViewer(true); } if (id.equals(token.getOwnerId())) { tmpPerson.setIsOwner(true); } } personList.add(tmpPerson); } } // return search query information final RestfulCollection<Person> people = new RestfulCollection<Person>(personList); people.setItemsPerPage(result.getMax()); people.setStartIndex(result.getFirst()); people.setTotalResults(result.getTotal()); return Futures.immediateFuture(people); }
From source file:org.thingsboard.server.dao.timeseries.BaseTimeseriesService.java
@Override public ListenableFuture<List<TsKvEntry>> findAllLatest(TenantId tenantId, EntityId entityId) { validate(entityId);/* www . ja v a2 s . c o m*/ if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { EntityView entityView = entityViewService.findEntityViewById(tenantId, (EntityViewId) entityId); if (entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null && !entityView.getKeys().getTimeseries().isEmpty()) { return findLatest(tenantId, entityId, entityView.getKeys().getTimeseries()); } else { return Futures.immediateFuture(new ArrayList<>()); } } else { return timeseriesDao.findAllLatest(tenantId, entityId); } }
From source file:org.opendaylight.netvirt.ipv6service.Ipv6NdUtilServiceImpl.java
@Override public Future<RpcResult<Void>> sendNeighborSolicitation(SendNeighborSolicitationInput ndInput) { RpcResultBuilder<Void> failureBuilder = RpcResultBuilder.failed(); RpcResultBuilder<Void> successBuilder = RpcResultBuilder.success(); Ipv6Address targetIpv6Address = null; Ipv6Address srcIpv6Address;//from www . j a v a 2s . co m String interfaceName = null; String macAddr = null; BigInteger dpnId; int localErrorCount = 0; targetIpv6Address = ndInput.getTargetIpAddress(); for (InterfaceAddress interfaceAddress : ndInput.getInterfaceAddress()) { try { interfaceName = interfaceAddress.getInterface(); srcIpv6Address = interfaceAddress.getSrcIpAddress(); GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName); checkNotNull(portResult); dpnId = portResult.getDpid(); Long portid = portResult.getPortno(); checkArgument(null != dpnId && BigInteger.ZERO != dpnId, DPN_NOT_FOUND_ERROR, interfaceName); NodeConnectorRef nodeRef = MDSALUtil.getNodeConnRef(dpnId, portid.toString()); checkNotNull(nodeRef, NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName); if (interfaceAddress.getSrcMacAddress() != null) { macAddr = interfaceAddress.getSrcMacAddress().getValue(); } checkNotNull(macAddr, FAILED_TO_GET_SRC_MAC_FOR_INTERFACE, interfaceName, nodeRef.getValue()); ipv6NeighborSolicitation.transmitNeighborSolicitation(dpnId, nodeRef, new MacAddress(macAddr), srcIpv6Address, targetIpv6Address); } catch (NullPointerException | IllegalArgumentException e) { LOG.trace("Failed to send Neighbor Solicitation for {} on interface {}", ndInput.getTargetIpAddress(), interfaceName); failureBuilder.withError(RpcError.ErrorType.APPLICATION, FAILED_TO_SEND_NS_FOR_INTERFACE + interfaceName, e); successBuilder.withError(RpcError.ErrorType.APPLICATION, FAILED_TO_SEND_NS_FOR_INTERFACE + interfaceName, e); localErrorCount++; } } if (localErrorCount == ndInput.getInterfaceAddress().size()) { // Failed to send IPv6 Neighbor Solicitation on all the interfaces, return failure. return Futures.immediateFuture(failureBuilder.build()); } return Futures.immediateFuture(successBuilder.build()); }