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.bgpcep.pcep.tunnel.provider.TunnelProgramming.java
@Override public ListenableFuture<RpcResult<PcepDestroyTunnelOutput>> pcepDestroyTunnel( final PcepDestroyTunnelInput destroyTunnelInput) { final PcepDestroyTunnelOutputBuilder b = new PcepDestroyTunnelOutputBuilder(); b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new DestroyTunnelInstructionExecutor( destroyTunnelInput, TunnelProgramming.this.dataProvider, this.topologyService))); final RpcResult<PcepDestroyTunnelOutput> res = SuccessfulRpcResult.create(b.build()); return Futures.immediateFuture(res); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<Path.Any> follow(Path.Any path) { LOG.log(FINE, "RPC->follow({0})", path); return Futures.transformAsync(client.follow(FollowRequest.newBuilder().setPath(path).setPath(path).build()), in -> Futures.immediateFuture(throwIfError(in.getPath(), in.getError()))); }
From source file:com.facebook.buck.rules.modern.builders.LocalContentAddressedStorage.java
public LocalContentAddressedStorage(Path cacheDir, Protocol protocol) { this.cacheDir = cacheDir; this.protocol = protocol; ExecutorService uploadService = MostExecutors.newMultiThreadExecutor("local-cas-write", 4); this.uploader = new MultiThreadedBlobUploader(MISSING_CHECK_LIMIT, UPLOAD_SIZE_LIMIT, uploadService, new CasBlobUploader() { @Override//from ww w.j a va 2 s . c o m public ImmutableList<UploadResult> batchUpdateBlobs(ImmutableList<UploadData> blobData) { return LocalContentAddressedStorage.this.batchUpdateBlobs(blobData); } @Override public ImmutableSet<String> getMissingHashes(List<Protocol.Digest> requiredDigests) { return findMissing(requiredDigests).map(Protocol.Digest::getHash) .collect(ImmutableSet.toImmutableSet()); } }); AsyncBlobFetcher fetcher = new AsyncBlobFetcher() { @Override public ListenableFuture<ByteBuffer> fetch(Protocol.Digest digest) { try (InputStream stream = getData(digest)) { return Futures.immediateFuture(ByteBuffer.wrap(ByteStreams.toByteArray(stream))); } catch (IOException e) { return Futures.immediateFailedFuture(e); } } @Override public void fetchToStream(Protocol.Digest digest, OutputStream outputStream) { throw new UnsupportedOperationException(); } }; this.outputsMaterializer = new OutputsMaterializer(fetcher, protocol); this.inputsMaterializer = new InputsMaterializer(protocol, new InputsMaterializer.Delegate() { @Override public void materializeFile(Path root, FileNode file) throws IOException { Path path = getPath(file.getDigest().getHash()); Preconditions.checkState(Files.exists(path)); // As this file could potentially be materialized as both executable and // non-executable, and // links share that, we need two concrete versions of the file. if (file.getIsExecutable()) { Path exePath = path.getParent().resolve(path.getFileName() + ".x"); if (!Files.exists(exePath)) { try (AutoUnlocker ignored = fileLock.writeLock(exePath.toString())) { if (!Files.exists(exePath)) { Path tempPath = path.getParent().resolve(path.getFileName() + ".x.tmp"); Files.copy(path, tempPath); Preconditions.checkState(tempPath.toFile().setExecutable(true)); Files.move(tempPath, exePath); } } } path = exePath; } Path target = root.resolve(file.getName()); Preconditions.checkState(target.normalize().startsWith(root)); Files.createLink(target, path); } @Override public InputStream getData(Protocol.Digest digest) throws IOException { return LocalContentAddressedStorage.this.getData(digest); } }); }
From source file:io.v.baku.toolkit.blessings.ActivityBlessingsSeeker.java
@Override @Synchronized("mSeekLock") public ListenableFuture<Blessings> refreshBlessings() { if (isAwaitingBlessings()) { return mCurrentSeek; }// www .j a va 2s . com Blessings mgrBlessings; try { mgrBlessings = BlessingsManager.getBlessings(mActivity.getApplicationContext()); } catch (final VException e) { log.warn("Could not get blessings from shared preferences", e); mgrBlessings = null; } final ListenableFuture<Blessings> nextBlessings; if (mgrBlessings == null) { nextBlessings = mCurrentSeek = SettableFuture.create(); seekBlessings(); } else { nextBlessings = Futures.immediateFuture(mgrBlessings); } mPub.onNext(nextBlessings); return nextBlessings; }
From source file:org.opendaylight.bgpcep.pcep.topology.provider.TopologyProgramming.java
@Override public ListenableFuture<RpcResult<SubmitAddLspOutput>> submitAddLsp(final SubmitAddLspInput input) { Preconditions.checkArgument(input.getNode() != null); Preconditions.checkArgument(input.getName() != null); final SubmitAddLspOutputBuilder b = new SubmitAddLspOutputBuilder(); b.setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) { @Override/*from w ww . ja v a 2 s . c o m*/ protected ListenableFuture<OperationResult> invokeOperation() { return TopologyProgramming.this.manager.addLsp(input); } })); final RpcResult<SubmitAddLspOutput> res = SuccessfulRpcResult.create(b.build()); return Futures.immediateFuture(res); }
From source file:com.facebook.buck.parser.RawNodeParsePipeline.java
@Override public ListenableFuture<Map<String, Object>> getNodeJob(final Cell cell, final BuildTarget buildTarget) throws BuildTargetException { return Futures.transformAsync(getAllNodesJob(cell, cell.getAbsolutePathToBuildFile(buildTarget)), input -> { for (Map<String, Object> rawNode : input) { Object shortName = rawNode.get("name"); if (buildTarget.getShortName().equals(shortName)) { return Futures.immediateFuture(rawNode); }/*from ww w . j a v a 2 s. c o m*/ } throw NoSuchBuildTargetException.createForMissingBuildRule(buildTarget, BuildTargetPatternParser.forBaseName(buildTarget.getBaseName()), cell.getBuildFileName(), "Defined in file: " + cell.getAbsolutePathToBuildFile(buildTarget)); }, executorService); }
From source file:org.codice.solr.factory.SolrClientFactory.java
public static Future<SolrClient> getHttpSolrClient(String url, String coreName, String configFile) { if (StringUtils.isBlank(url)) { url = SystemBaseUrl.constructUrl("/solr"); }// ww w . j av a 2s . c o m String coreUrl = url + "/" + coreName; SolrClient client; try { client = getSolrClient(url, coreName, configFile, coreUrl); } catch (Exception ex) { LOGGER.info("Returning future for HTTP Solr client ({})", coreName); LOGGER.debug("Failed to create Solr client (" + coreName + ")", ex); return pool.submit(new SolrClientFetcher(url, coreName, configFile, coreUrl)); } LOGGER.info("Created HTTP Solr client ({})", coreName); return Futures.immediateFuture(client); }
From source file:com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.java
@Override public <R> QueryTaskFuture<R> immediateSuccessfulFuture(R value) { return new QueryTaskFutureImpl<>(Futures.immediateFuture(value)); }
From source file:org.jclouds.http.ning.NingHttpCommandExecutorService.java
@Override public ListenableFuture<HttpResponse> submit(HttpCommand command) { try {/* w ww . ja v a2 s . co m*/ for (;;) { Future<Response> responseF = client .executeRequest(convertToNingRequest.apply(command.getCurrentRequest())); final HttpResponse httpResponse = convertToJCloudsResponse.apply(responseF.get()); int statusCode = httpResponse.getStatusCode(); if (statusCode >= 300) { if (retryHandler.shouldRetryRequest(command, httpResponse)) { continue; } else { errorHandler.handleError(command, httpResponse); return Futures.immediateFuture(httpResponse); } } else { return Futures.immediateFuture(httpResponse); } } } catch (IOException e) { throw Throwables.propagate(e); } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (ExecutionException e) { throw Throwables.propagate(e); } }
From source file:com.orangerhymelabs.helenus.cassandra.AbstractCassandraRepository.java
public ListenableFuture<T> update(T entity) { ListenableFuture<ResultSet> future = submitUpdate(entity); return Futures.transformAsync(future, new AsyncFunction<ResultSet, T>() { @Override//from w ww. j a v a 2 s . c o m public ListenableFuture<T> apply(ResultSet result) { if (result.wasApplied()) { return Futures.immediateFuture(entity); } return Futures.immediateFailedFuture(new ItemNotFoundException(entity.toString())); } }, MoreExecutors.directExecutor()); }