List of usage examples for com.google.common.util.concurrent Futures transform
public static <I, O> ListenableFuture<O> transform(ListenableFuture<I> input, Function<? super I, ? extends O> function)
From source file:org.thingsboard.server.dao.nosql.RateLimitedResultSetFuture.java
public RateLimitedResultSetFuture(Session session, AsyncRateLimiter rateLimiter, Statement statement) { this.rateLimitFuture = Futures.catchingAsync(rateLimiter.acquireAsync(), Throwable.class, t -> { if (!(t instanceof BufferLimitException)) { rateLimiter.release();// w w w .jav a 2 s .co m } return Futures.immediateFailedFuture(t); }); this.originalFuture = Futures.transform(rateLimitFuture, i -> executeAsyncWithRelease(rateLimiter, session, statement)); }
From source file:io.v.v23.syncbase.SyncgroupImpl.java
@Override public ListenableFuture<Map<String, SyncgroupSpec>> getSpec(VContext ctx) { return VFutures.withUserLandChecks(ctx, Futures.transform(dbClient.getSyncgroupSpec(ctx, id), new Function<SyncgroupManagerClient.GetSyncgroupSpecOut, Map<String, SyncgroupSpec>>() { @Override/*from ww w. java2s . c o m*/ public Map<String, SyncgroupSpec> apply(SyncgroupManagerClient.GetSyncgroupSpecOut spec) { return ImmutableMap.of(spec.version, spec.spec); } })); }
From source file:net.oneandone.troilus.MutationQuery.java
public ListenableFuture<Result> executeAsync() { ListenableFuture<ResultSet> future = performAsync(getDefaultDbSession(), getStatementAsync(getDefaultDbSession())); Function<ResultSet, Result> mapEntity = new Function<ResultSet, Result>() { @Override/*from w w w. j a v a 2 s .c o m*/ public Result apply(ResultSet resultSet) { return newResult(resultSet); } }; return Futures.transform(future, mapEntity); }
From source file:org.opendaylight.openflowplugin.impl.services.SalEchoServiceImpl.java
private Future<RpcResult<SendEchoOutput>> transform( final ListenableFuture<RpcResult<EchoOutput>> rpcResultListenableFuture) { return Futures.transform(rpcResultListenableFuture, new Function<RpcResult<EchoOutput>, RpcResult<SendEchoOutput>>() { @Nullable//from w w w.j a v a 2s .c o m @Override public RpcResult<SendEchoOutput> apply(@Nullable final RpcResult<EchoOutput> input) { Preconditions.checkNotNull(input, "echoOutput value is never expected to be NULL"); final RpcResult<SendEchoOutput> rpcOutput; if (input.isSuccessful()) { final SendEchoOutput sendEchoOutput = new SendEchoOutputBuilder() .setData(input.getResult().getData()).build(); rpcOutput = RpcResultBuilder.success(sendEchoOutput).build(); } else { rpcOutput = RpcResultBuilder.<SendEchoOutput>failed().withRpcErrors(input.getErrors()) .build(); } return rpcOutput; } }); }
From source file:com.google.gapid.util.FutureCache.java
public ListenableFuture<V> get(K key) { // Look up the value in the cache using the executor. ListenableFuture<V> cacheLookUp = EXECUTOR.submit(() -> cache.getIfPresent(key)); return Futures.transformAsync(cacheLookUp, fromCache -> { if (fromCache != null) { return Futures.immediateFuture(fromCache); }/* w w w.java 2 s . c o m*/ return Futures.transform(fetcher.apply(key), value -> { if (shouldCache.test(value)) { cache.put(key, value); } return value; }); }); }
From source file:de.ii.xtraplatform.ogc.api.gml.parser.GMLParser.java
public void parse(ListenableFuture<HttpEntity> entity, String ns, String ft) throws ExecutionException { QName featureType = new QName(ns, ft); LOGGER.debug("Parsing GetFeature response for '{}'", ft); try {/*from w w w . j a v a2 s . co m*/ ListenableFuture<SMInputCursor> rootFuture = Futures.transform(entity, new Function<HttpEntity, SMInputCursor>() { @Override public SMInputCursor apply(HttpEntity e) { try { return staxFactory.rootElementCursor(e.getContent()).advance(); } catch (IOException | IllegalStateException | XMLStreamException ex) { LOGGER.debug("Error parsing WFS GetFeature (IOException) {}", ex.getMessage()); return null; } } }); parseRoot(rootFuture, ns, ft); } finally { try { EntityUtils.consumeQuietly(entity.get()); } catch (InterruptedException ex) { } } }
From source file:com.google.gapid.models.ApiContext.java
@Override protected ListenableFuture<FilteringContext[]> doLoad(Path.Any path) { return Futures.transform(Futures.transformAsync(client.get(path), val -> { List<ListenableFuture<ApiContext.IdAndContext>> contexts = Lists.newArrayList(); for (Path.Context ctx : val.getContexts().getListList()) { contexts.add(Futures.transform(client.get(Path.Any.newBuilder().setContext(ctx).build()), value -> new IdAndContext(ctx, value.getContext()))); }/* w ww . j av a 2 s .c o m*/ return Futures.allAsList(contexts); }), this::unbox); }
From source file:org.opendaylight.protocol.bgp.rib.impl.BgpPeerRpc.java
@Override public Future<RpcResult<Void>> routeRefreshRequest(final RouteRefreshRequestInput input) { final ChannelFuture f = sendRRMessage(input); if (f != null) { return Futures.transform(JdkFutureAdapters.listenInPoolThread(f), new Function<Void, RpcResult<Void>>() { @Override/* w w w . j a v a 2 s. co m*/ public RpcResult<Void> apply(final Void input) { if (f.isSuccess()) { return RpcResultBuilder.<Void>success().build(); } else { return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG) .build(); } } }); } return RpcResultBuilder.<Void>failed() .withError(ErrorType.RPC, FAILURE_MSG + " due to unsupported address families.").buildFuture(); }
From source file:net.oneandone.troilus.CounterMutationQuery.java
@Override public ListenableFuture<Result> executeAsync() { ListenableFuture<ResultSet> future = performAsync(getDefaultDbSession(), getStatementAsync(getDefaultDbSession())); Function<ResultSet, Result> mapEntity = new Function<ResultSet, Result>() { @Override// w ww .j a v a 2 s. co m public Result apply(ResultSet resultSet) { return newResult(resultSet); } }; return Futures.transform(future, mapEntity); }
From source file:org.dcache.poolmanager.RemotePoolManagerHandler.java
@Override @SuppressWarnings("unchecked") public <T extends PoolManagerMessage> ListenableFuture<T> sendAsync(CellEndpoint endpoint, T msg, long timeout) { if (msg instanceof PoolManagerGetRestoreHandlerInfo) { return (ListenableFuture<T>) Futures.transform( submit(endpoint, new CellPath(destination), "xrc ls", RestoreHandlerInfo[].class, timeout), a -> new PoolManagerGetRestoreHandlerInfo(asList(a))); }/*from w w w . ja va 2 s .c o m*/ return submit(endpoint, new CellPath(destination), msg, timeout); }