.sorted(Comparator.comparing(RetryEvent::getCreationTime)) .map(RetryEventDTO::createRetryEventDTO).toJavaList(); d.success(new RetryEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r))) ); .sorted(Comparator.comparing(RetryEvent::getCreationTime)) .map(RetryEventDTO::createRetryEventDTO).toJavaList(); d.success(new RetryEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r))); .filter(event -> event.getEventType() == RetryEvent.Type.valueOf(eventType.toUpperCase())) .map(RetryEventDTO::createRetryEventDTO).toJavaList(); d.success(new RetryEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r)));
@Override public void onFailure(Throwable t) { error(t); } }, Execution.current().getEventLoop());
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Function)}, except that it will only apply if the error is of the given type. * If the error is not of the given type, it will not be transformed and will propagate as normal. * * @param function the transformation to apply to the promise failure * @return a promise * @since 1.3 */ default <E extends Throwable> Promise<T> mapError(Class<E> type, Function<? super E, ? extends T> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (type.isInstance(throwable)) { T transformed; try { transformed = function.apply(type.cast(throwable)); } catch (Throwable t) { down.error(t); return; } down.success(transformed); } else { down.error(throwable); } })) ); }
public static <T> void retryAttempt(int attemptNum, int maxAttempts, Upstream<? extends T> up, Downstream<? super T> down, BiFunction<? super Integer, ? super Throwable, Promise<Duration>> onError) throws Exception { up.connect(down.onError(e -> { if (attemptNum > maxAttempts) { down.error(e); } else { Promise<Duration> delay; errorHandlerError.addSuppressed(e); down.error(errorHandlerError); return;
private void tooLarge(Block onTooLarge, long length, Downstream<? super ByteBuf> downstream) { discard(); if (onTooLarge == RequestBodyReader.DEFAULT_TOO_LARGE_SENTINEL) { downstream.error(tooLargeException(length)); } else { try { onTooLarge.execute(); } catch (Throwable t) { downstream.error(t); return; } downstream.complete(); } }
private void drain() { ExecResult<? extends T> result = ref.get(); if (result == null) { return; } Downstream<? super T> next = listeners.poll(); while (next != null) { next.accept(result); next = listeners.poll(); } }
@Override public void complete() { Downstream.this.complete(); } };
.sorted(Comparator.comparing(RateLimiterEvent::getCreationTime)) .map(RateLimiterEventDTO::createRateLimiterEventDTO).toJavaList(); d.success(new RateLimiterEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r))) ); .sorted(Comparator.comparing(RateLimiterEvent::getCreationTime)) .map(RateLimiterEventDTO::createRateLimiterEventDTO).toJavaList(); d.success(new RateLimiterEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r))); .filter(event -> event.getEventType() == RateLimiterEvent.Type.valueOf(eventType.toUpperCase())) .map(RateLimiterEventDTO::createRateLimiterEventDTO).toJavaList(); d.success(new RateLimiterEventsEndpointResponse(eventsList)); }).then(r -> ctx.render(Jackson.json(r)));
@Override public void onError(Throwable t) { if (!cancelled) { downstream.error(t); } }
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Function)}, except that it will only apply depending if it satisfies the predicate. * If the error is not of the given type, it will not be transformed and will propagate as normal. * * @param predicate the predicate to test against the error * @param function the transformation to apply to the promise failure * @return a promise * @since 1.6.0 */ default Promise<T> mapError(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (predicate.apply(throwable)) { T transformed; try { transformed = function.apply(throwable); } catch (Throwable t) { down.error(t); return; } down.success(transformed); } else { down.error(throwable); } })) ); }
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Class, Function)}, except that it allows async transformation. * * @param function the transformation to apply to the promise failure * @return a promise * @since 1.3 */ default <E extends Throwable> Promise<T> flatMapError(Class<E> type, Function<? super E, ? extends Promise<T>> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (type.isInstance(throwable)) { Promise<T> transformed; try { transformed = function.apply(type.cast(throwable)); } catch (Throwable t) { down.error(t); return; } transformed.connect(down); } else { down.error(throwable); } })) ); }
/** * Convert a {@link CompletableFuture} into a promise. * <p> * @param future the {@link CompletableFuture} to convert into a {@link Promise} * @param <T> The type of the promised value * @return a {@link Promise} that will be consumed on the current execution thread. * @since 1.6 */ static <T> Promise<T> toPromise(CompletableFuture<T> future) { return async(downstream -> downstream.accept(future)); }