@Override public <V> ListenableFuture<V> withFallback( ListenableFuture<? extends V> input, final AsyncFunction<Throwable, V> fallback) { return Futures.withFallback( input, new FutureFallback<V>() { @Override public ListenableFuture<V> create(Throwable t) throws Exception { return fallback.apply(t); } }); }
@Override public <V> ListenableFuture<V> withFallback( ListenableFuture<? extends V> input, final AsyncFunction<Throwable, V> fallback, Executor executor) { return Futures.withFallback( input, new FutureFallback<V>() { @Override public ListenableFuture<V> create(Throwable t) throws Exception { return fallback.apply(t); } }, executor); }
@Override public <V> ListenableFuture<V> withFallback(ListenableFuture<? extends V> input, final AsyncFunction<Throwable, V> fallback, Executor executor) { return Futures.withFallback(input, new FutureFallback<V>() { @Override public ListenableFuture<V> create(Throwable t) throws Exception { return fallback.apply(t); } }, executor); }
@Override public <V> ListenableFuture<V> withFallback(ListenableFuture<? extends V> input, final AsyncFunction<Throwable, V> fallback) { return Futures.withFallback(input, new FutureFallback<V>() { @Override public ListenableFuture<V> create(Throwable t) throws Exception { return fallback.apply(t); } }); }
private ListenableFuture<StorageNodeLoadComposite> wrapFuture(ListenableFuture<StorageNodeLoadComposite> future, final StorageNodeLoadComposite value, final String msg) { return Futures.withFallback(future, new FutureFallback<StorageNodeLoadComposite>() { @Override public ListenableFuture<StorageNodeLoadComposite> create(Throwable t) throws Exception { if (log.isDebugEnabled()) { log.debug(msg, t); } else { log.info(msg + ": " + t.getMessage()); } return Futures.immediateFuture(value); } }); }
@Override public FluentFuture<V> withFallback(FutureFallback<V> fallback) { return from(Futures.withFallback(this, fallback, executor)); }
ListenableFuture<? extends V> input, FutureFallback<? extends V> fallback) { return withFallback(input, fallback, directExecutor());
@Override public Will<A> replaceFailed(FutureFallback<? extends A> fallback) { return new Of<A>(Futures.withFallback(delegate(), fallback)); }
private static ListenableFuture<ResultSet> executeAdaptiveQueryAsync(Session session, Statement statement, int fetchSize, int remainingAdaptations) { statement.setFetchSize(fetchSize); ResultSetFuture rawFuture = session.executeAsync(statement); // Lazily wrap the result set from the async result with an AdaptiveResultSet ListenableFuture<ResultSet> adaptiveFuture = Futures.transform(rawFuture, new Function<ResultSet, ResultSet>() { @Override public ResultSet apply(ResultSet resultSet) { return new AdaptiveResultSet(session, resultSet, remainingAdaptations); } }); return Futures.withFallback(adaptiveFuture, t -> { if (isAdaptiveException(t) && remainingAdaptations > 0 && fetchSize > MIN_FETCH_SIZE) { // Try again with half the fetch size int reducedFetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE); _log.debug("Repeating previous query with fetch size {} due to {}", reducedFetchSize, t.getMessage()); return executeAdaptiveQueryAsync(session, statement, reducedFetchSize, remainingAdaptations - 1); } throw Throwables.propagate(t); }); }
private static ListenableFuture<ResultSet> executeAdaptiveQueryAsync(Session session, Statement statement, int fetchSize, int remainingAdaptations) { statement.setFetchSize(fetchSize); ResultSetFuture rawFuture = session.executeAsync(statement); // Lazily wrap the result set from the async result with an AdaptiveResultSet ListenableFuture<ResultSet> adaptiveFuture = Futures.transform(rawFuture, new Function<ResultSet, ResultSet>() { @Override public ResultSet apply(ResultSet resultSet) { return new AdaptiveResultSet(session, resultSet, remainingAdaptations); } }); return Futures.withFallback(adaptiveFuture, t -> { if (isAdaptiveException(t) && remainingAdaptations > 0 && fetchSize > MIN_FETCH_SIZE) { // Try again with half the fetch size int reducedFetchSize = Math.max(fetchSize / 2, MIN_FETCH_SIZE); _log.debug("Repeating previous query with fetch size {} due to {}", reducedFetchSize, t.getMessage()); return executeAdaptiveQueryAsync(session, statement, reducedFetchSize, remainingAdaptations - 1); } throw Throwables.propagate(t); }); }
ListenableFuture<? extends V> input, FutureFallback<? extends V> fallback) { return withFallback(input, fallback, sameThreadExecutor());
ListenableFuture<? extends V> input, FutureFallback<? extends V> fallback) { return withFallback(input, fallback, sameThreadExecutor());
ListenableFuture<? extends V> input, FutureFallback<? extends V> fallback) { return withFallback(input, fallback, sameThreadExecutor());
ListenableFuture<? extends V> input, FutureFallback<? extends V> fallback) { return withFallback(input, fallback, sameThreadExecutor());
pendingTrials.add(current); previous = Futures.withFallback(current, FALLBACK_TO_NULL);
private ListenableFuture<R> future(final TraverseState state) { final ImmutableList.Builder<ListenableFuture<?>> futuresListBuilder = builder(); // get node and value dependencies for (Dep<?> input : graph.getInputs()) { final ListenableFuture<?> inputFuture = input.getFuture(state); futuresListBuilder.add(inputFuture); } final ImmutableList<ListenableFuture<?>> futures = futuresListBuilder.build(); final TraverseState.FutureCallInformation currentCall = state.record(this, futures); // future for signaling propagation - needs to include predecessors, too List<ListenableFuture<?>> mustHappenBefore = Lists.newArrayList(futures); for (Graph<?> predecessor : graph.getPredecessors()) { mustHappenBefore.add(state.futureForGraph(predecessor)); } final ListenableFuture<List<Object>> allFuture = allAsList(mustHappenBefore); checkArgument(graph.getInputs().size() == futures.size(), "sanity check result: insane"); return Futures.withFallback( nodeFuture(futures, allFuture, state.getExecutor()), new NodeExecutionFallback<R>(graph, currentCall, state)); }
@Override public ListenableFuture<Void> advertise( VContext ctx, Advertisement ad, List<BlessingPattern> visibility) throws VException { ListenableFutureCallback<Void> cb = new ListenableFutureCallback<>(); nativeAdvertise(nativeRef, ctx, ad, visibility, cb); return Futures.withFallback( cb.getFuture(ctx), new FutureFallback<Void>() { public ListenableFuture<Void> create(Throwable t) { if (t instanceof CancellationException) { return Futures.immediateFuture(null); } return Futures.immediateFailedFuture(t); } }); }
/** * submits the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * applies a {@link #getFallback(String, Invocation, HttpCommand) fallback} * if a {@code Throwable} is encountered. Parsing and Fallback occur on the * {@code userExecutor} thread. */ public ListenableFuture<?> submit(Invocation invocation) { String commandName = config.getCommandName(invocation); HttpCommand command = toCommand(commandName, invocation); Function<HttpResponse, ?> transformer = getTransformer(commandName, command); org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command); logger.debug(">> submitting %s", commandName); return withFallback(transform(http.submit(command), transformer, userExecutor), fallback); }
/** * submits the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * applies a {@link #getFallback(String, Invocation, HttpCommand) fallback} * if a {@code Throwable} is encountered. Parsing and Fallback occur on the * {@code userExecutor} thread. */ public ListenableFuture<?> submit(Invocation invocation) { String commandName = config.getCommandName(invocation); HttpCommand command = toCommand(commandName, invocation); Function<HttpResponse, ?> transformer = getTransformer(commandName, command); org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command); logger.debug(">> submitting %s", commandName); return withFallback(transform(http.submit(command), transformer, userExecutor), fallback); }
/** * submits the {@linkplain HttpCommand} associated with {@code invocation}, * {@link #getTransformer(String, HttpCommand) parses its response}, and * applies a {@link #getFallback(String, Invocation, HttpCommand) fallback} * if a {@code Throwable} is encountered. Parsing and Fallback occur on the * {@code userExecutor} thread. */ public ListenableFuture<?> submit(Invocation invocation) { String commandName = config.getCommandName(invocation); HttpCommand command = toCommand(commandName, invocation); Function<HttpResponse, ?> transformer = getTransformer(commandName, command); org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command); logger.debug(">> submitting %s", commandName); return withFallback(transform(http.submit(command), transformer, userExecutor), fallback); }