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:com.torodb.torod.db.metaInf.DefaultDbMetaInformationCache.java
@Override public void shutdown() { Futures.immediateFuture(null); }
From source file:com.google.wave.splash.auth.oauth.OAuthRequestFactory.java
@Override public ListenableFuture<String> makeSignedRequest(String body) { SessionContext session = sessionProvider.get(); InputStream bodyStream;/*from ww w .java2s . c om*/ try { bodyStream = new ByteArrayInputStream(body.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } String result = null; try { InputStream output; if (session.isAuthenticated()) { output = getSignedResult(session, bodyStream); } else { output = getUnsignedResult(body, bodyStream); } result = CharStreams.toString(new InputStreamReader(output, HttpMessage.DEFAULT_CHARSET)); } catch (URISyntaxException e) { LOG.warning(e.toString()); } catch (OAuthException e) { LOG.warning(e.toString()); } catch (IOException e) { LOG.severe(e.toString()); } return Futures.immediateFuture(result); }
From source file:com.facebook.buck.core.build.engine.cache.manager.BuildCacheArtifactFetcher.java
public ListenableFuture<CacheResult> tryToFetchArtifactFromBuildCacheAndOverlayOnTopOfProjectFilesystem( RuleKey ruleKey, ArtifactCache artifactCache, ProjectFilesystem filesystem) { if (!rule.isCacheable()) { return Futures.immediateFuture(CacheResult.ignored()); }//from w ww . j a v a 2 s .c o m // Create a temp file whose extension must be ".zip" for Filesystems.newFileSystem() to infer // that we are creating a zip-based FileSystem. LazyPath lazyZipPath = new LazyPath() { @Override protected Path create() throws IOException { return Files.createTempFile( "buck_artifact_" + MostFiles.sanitize(rule.getBuildTarget().getShortName()), ".zip"); } }; // TODO(mbolin): Change ArtifactCache.fetch() so that it returns a File instead of takes one. // Then we could download directly from the remote cache into the on-disk cache and unzip it // from there. return Futures.transformAsync(fetch(artifactCache, ruleKey, lazyZipPath), cacheResult -> { try (Scope ignored = buildRuleScope()) { // Verify that the rule key we used to fetch the artifact is one of the rule keys // reported in it's metadata. if (cacheResult.getType().isSuccess()) { ImmutableSet<RuleKey> ruleKeys = RichStream.from(cacheResult.getMetadata().entrySet()) .filter(e -> BuildInfo.RULE_KEY_NAMES.contains(e.getKey())).map(Map.Entry::getValue) .map(RuleKey::new).toImmutableSet(); if (!ruleKeys.contains(ruleKey)) { LOG.warn("%s: rule keys in artifact don't match rule key used to fetch it: %s not in %s", rule.getBuildTarget(), ruleKey, ruleKeys); } } return Futures.immediateFuture( extractArtifactFromCacheResult(ruleKey, lazyZipPath, filesystem, cacheResult)); } }); }
From source file:org.opendaylight.lispflowmapping.southbound.LispSouthboundRPC.java
@Override public Future<RpcResult<Void>> sendMapReply(SendMapReplyInput mapReplyInput) { LOG.trace("sendMapReply called!!"); if (mapReplyInput != null) { ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReplyInput.getMapReply()); lispSbPlugin.handleSerializedLispBuffer(mapReplyInput.getTransportAddress(), outBuffer, MessageType.MapReply);/*from w w w . java 2 s. c om*/ } else { LOG.warn("MapReply was null"); return Futures.immediateFuture(RpcResultBuilder.<Void>failed().build()); } return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal.FlowServiceAdapter.java
@Override public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) { Flow flow = ToSalConversionsUtils.toFlow(input, null); @SuppressWarnings("unchecked") org.opendaylight.controller.sal.core.Node node = InventoryMapping .toAdNode((InstanceIdentifier<Node>) input.getNode().getValue()); Status status = delegate.addFlowAsync(node, flow); AddFlowOutputBuilder builder = new AddFlowOutputBuilder(); builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId()))); AddFlowOutput rpcResultType = builder.build(); return Futures.immediateFuture( RpcResultBuilder.<AddFlowOutput>status(status.isSuccess()).withResult(rpcResultType).build()); }
From source file:org.opendaylight.topomanager.impl.BierTopologyProcess.java
@Override public ListenableFuture<T> call() throws Exception { T object = mtT;// w w w . ja v a2 s . c o m //try { BierTopologyOperation op = mqueTopoOperation.take(); final ReadWriteTransaction tx = this.mcDataBroker.newReadWriteTransaction(); int ops = 0; do { if (0 == miProcessFlag) { ListenableFuture<Optional<T>> readResult = op.readOperation(tx); //try { object = readResult.get().get(); } /*catch (Exception e) { LOG.error("Read Data failed", e); }*/ } else { op.writeOperation(tx); //try { tx.submit().checkedGet(); } /*catch (final TransactionCommitFailedException e) { tObject = null; LOG.warn("Stat DataStoreOperation unexpected State!", e); //m_cTxChain.close(); //m_cTxChain = m_cDataBroker.createTransactionChain(this); }*/ } ops++; if (ops < MAX_TRANSACTION_OPERATIONS) { op = mqueTopoOperation.poll(); } else { op = null; } } while (op != null); } /*catch (final Exception e) { LOG.warn("Stat DataStore Operation executor fail!", e); }*/ cleanDataStoreOperQueue(); return Futures.immediateFuture(object); }
From source file:eu.point.bootstrapping.impl.BootstrappingServiceImpl.java
/** * The method which configures the client of the TM-SDN interface. * It receives as input the TM IP address and port. * @param input The TM configuration input, including parameters such as server ip, port, node id, lid and ilid. * @return It returns a void future result. * @see ConfigureTmInput//w w w .ja va2s . co m */ @Override public Future<RpcResult<Void>> configureTm(ConfigureTmInput input) { LOG.info("Received input {}.", input); Client.serverIP = input.getTmIp(); Client.tcpPort = input.getTmPort(); IcnIdConfigurator.tmOpenflowId = input.getTmOpenflowId(); IcnIdConfigurator.tmAttachedOpenflowSwitchId = input.getTmAttachedSwitchId(); IcnIdConfigurator.tmNodeId = input.getTmNodeId(); IcnIdConfigurator.tmLidPosition = input.getTmLid(); IcnIdConfigurator.tmInternalLidPosition = input.getTmInternalLid(); //Adding input to the registries BootstrappingServiceImpl.assignedNodeIds.put(IcnIdConfigurator.tmOpenflowId, IcnIdConfigurator.tmNodeId); NodeRegistryUtils.getInstance().writeToNodeRegistry(new NodeRegistryEntryBuilder() .setNoneName(IcnIdConfigurator.tmOpenflowId).setNoneId(IcnIdConfigurator.tmNodeId).build()); BootstrappingServiceImpl.assignedLinkIds.put( IcnIdConfigurator.tmOpenflowId + "," + IcnIdConfigurator.tmAttachedOpenflowSwitchId, IcnIdConfigurator.generateLid(IcnIdConfigurator.tmLidPosition)); LinkRegistryUtils.getInstance().writeToLinkRegistry(new LinkRegistryEntryBuilder() .setLinkName(IcnIdConfigurator.tmOpenflowId + "," + IcnIdConfigurator.tmAttachedOpenflowSwitchId) .setLinkId(IcnIdConfigurator.generateLid(IcnIdConfigurator.tmLidPosition)).build()); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java
@Override public Future<Stats> getStatistics() { return Futures.immediateFuture(memcacheService.getStatistics()); }
From source file:com.facebook.buck.rules.ProjectConfigRule.java
public ProjectConfigRule(BuildRuleParams buildRuleParams, @Nullable BuildRule srcRule, @Nullable List<String> srcRoots, @Nullable BuildRule testRule, @Nullable List<String> testRoots, boolean isIntelliJPlugin) { super(buildRuleParams); Preconditions.checkArgument(srcRule != null || testRule != null, "At least one of src_target or test_target must be specified in %s.", buildRuleParams.getBuildTarget().getFullyQualifiedName()); Preconditions.checkArgument(testRule == null || testRule.getType().isTestRule(), "The test_target for a project_config() must correspond to a test rule, if specified, " + "but was %s.", testRule);/*from w w w.j ava 2 s. c o m*/ this.srcRule = srcRule; if (srcRoots != null) { this.srcSourceRoots = ImmutableList .copyOf(Iterables.transform(srcRoots, new Function<String, SourceRoot>() { @Override public SourceRoot apply(String srcRoot) { return new SourceRoot(srcRoot); } })); } else { this.srcSourceRoots = null; } this.testRule = testRule; if (testRoots != null) { this.testsSourceRoots = ImmutableList .copyOf(Iterables.transform(testRoots, new Function<String, SourceRoot>() { @Override public SourceRoot apply(String testRoot) { return new SourceRoot(testRoot); } })); } else { this.testsSourceRoots = null; } this.isIntelliJPlugin = isIntelliJPlugin; BuildRuleSuccess buildRuleSuccess = new BuildRuleSuccess(this, SUCCESS_TYPE); this.buildOutput = Futures.immediateFuture(buildRuleSuccess); }
From source file:org.apache.qpid.server.txn.AsyncAutoCommitTransaction.java
public void dequeue(MessageEnqueueRecord record, Action postTransactionAction) { Transaction txn = null;/*w w w . j a va2 s .c om*/ try { ListenableFuture<Void> future; if (record != null) { _logger.debug("Dequeue of message number {} from transaction log. Queue : {}", record.getMessageNumber(), record.getQueueId()); txn = _messageStore.newTransaction(); txn.dequeueMessage(record); future = txn.commitTranAsync((Void) null); txn = null; } else { future = Futures.immediateFuture(null); } addFuture(future, postTransactionAction); postTransactionAction = null; } finally { rollbackIfNecessary(postTransactionAction, txn); } }