upstream.connect(downstream); };
@Override public Upstream<T> apply(Upstream<? extends T> upstream) throws Exception { return down -> { long start; if (circuitBreaker.isCallPermitted()) { start = System.nanoTime(); upstream.connect(new Downstream<T>() { @Override public void success(T value) { long durationInNanos = System.nanoTime() - start; circuitBreaker.onSuccess(durationInNanos); down.success(value); } @Override public void error(Throwable throwable) { long durationInNanos = System.nanoTime() - start; circuitBreaker.onError(durationInNanos, throwable); handleRecovery(down, throwable); } @Override public void complete() { down.complete(); } }); } else { Throwable t = new CircuitBreakerOpenException(String.format("CircuitBreaker '%s' is open", circuitBreaker.getName())); handleRecovery(down, t); } }; }
if (bulkhead.isCallPermitted()) { upstream.connect(new Downstream<T>() {
upstream.connect(new Downstream<T>() {
private void yield(final Downstream<? super T> downstream) throws Exception { upstream.connect(new Downstream<T>() { public void error(Throwable throwable) { receiveResult(downstream, ExecResult.of(Result.<T>error(throwable))); } @Override public void success(T value) { receiveResult(downstream, ExecResult.of(Result.success(value))); } @Override public void complete() { receiveResult(downstream, CompleteExecResult.get()); } }); }
private void doConnect(Downstream<? super T> downstream) { try { upstream.connect(downstream); } catch (ExecutionException e) { throw e; } catch (Exception e) { throwError(e); } }
upstream.connect(downstream); };
up.connect(new Downstream<T>() { @Override public void success(T value) {
up.connect(new Downstream<T>() { @Override public void success(T value) {
up.connect(new Downstream<T>() { @Override public void success(T value) {
return; up.connect(down); });
return new DefaultOperation( promise.transform(up -> down -> up.connect(new Downstream<Void>() { @Override public void success(Void value) {
@Override public Upstream<T> apply(Upstream<? extends T> upstream) throws Exception { return down -> { long start; if (circuitBreaker.isCallPermitted()) { start = System.nanoTime(); upstream.connect(new Downstream<T>() { @Override public void success(T value) { long durationInNanos = System.nanoTime() - start; circuitBreaker.onSuccess(durationInNanos); down.success(value); } @Override public void error(Throwable throwable) { long durationInNanos = System.nanoTime() - start; circuitBreaker.onError(durationInNanos, throwable); handleRecovery(down, throwable); } @Override public void complete() { down.complete(); } }); } else { Throwable t = new CircuitBreakerOpenException(String.format("CircuitBreaker '%s' is open", circuitBreaker.getName())); handleRecovery(down, t); } }; }
if (bulkhead.isCallPermitted()) { upstream.connect(new Downstream<T>() {
onRedirect(locationUrl, redirectCount + 1, redirectRequestConfig).connect(downstream);
/** * 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); } })) ); }
/** * 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); } })) ); }
up.connect(new Downstream<Void>() { @Override public void success(Void value) {
up.connect(new Downstream<T>() { private void onResult(ExecResult<T> originalResult) { ExecResult<A> newResult;