Java Code Examples for reactor.core.Exceptions#addSuppressed()
The following examples show how to use
reactor.core.Exceptions#addSuppressed() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FluxRetryPredicate.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { boolean b; try { b = predicate.test(t); } catch (Throwable e) { Throwable _t = Operators.onOperatorError(e, actual.currentContext()); _t = Exceptions.addSuppressed(_t, t); actual.onError(_t); return; } if (b) { resubscribe(); } else { actual.onError(t); } }
Example 2
Source File: MonoUsing.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (valued && mode != ASYNC) { Operators.onErrorDropped(t, actual.currentContext()); return; } if (eager && WIP.compareAndSet(this, 0, 1)) { try { resourceCleanup.accept(resource); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); t = Exceptions.addSuppressed(_e, t); } } actual.onError(t); if (!eager && WIP.compareAndSet(this, 0, 1)) { cleanup(); } }
Example 3
Source File: FluxOnErrorResume.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (!second) { second = true; Publisher<? extends T> p; try { p = Objects.requireNonNull(nextFactory.apply(t), "The nextFactory returned a null Publisher"); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); _e = Exceptions.addSuppressed(_e, t); actual.onError(_e); return; } p.subscribe(this); } else { actual.onError(t); } }
Example 4
Source File: FluxUsingWhen.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (CALLBACK_APPLIED.compareAndSet(this, 0, 1)) { Publisher<?> p; try { p = Objects.requireNonNull(asyncError.apply(resource, t), "The asyncError returned a null Publisher"); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); _e = Exceptions.addSuppressed(_e, t); actual.onError(_e); return; } p.subscribe(new RollbackInner(this, t)); } }
Example 5
Source File: OnNextFailureStrategy.java From reactor-core with Apache License 2.0 | 6 votes |
@Override @Nullable public Throwable process(Throwable error, @Nullable Object value, Context context) { if (errorPredicate == null) { Exceptions.throwIfFatal(error); } else if (!errorPredicate.test(error)) { Exceptions.throwIfFatal(error); return error; } try { if (value != null) { Operators.onNextDropped(value, context); } Operators.onErrorDropped(error, context); return null; } catch (Throwable e) { return Exceptions.addSuppressed(e, error); } }
Example 6
Source File: MonoProcessor.java From reactor-core with Apache License 2.0 | 6 votes |
/** * Returns the value that completed this {@link MonoProcessor}. Returns {@code null} if the {@link MonoProcessor} has not been completed. If the * {@link MonoProcessor} is completed with an error a RuntimeException that wraps the error is thrown. * * @return the value that completed the {@link MonoProcessor}, or {@code null} if it has not been completed * * @throws RuntimeException if the {@link MonoProcessor} was completed with an error */ @Nullable public O peek() { if (!isTerminated()) { return null; } if (value != null) { return value; } if (error != null) { RuntimeException re = Exceptions.propagate(error); re = Exceptions.addSuppressed(re, new Exception("Mono#peek terminated with an error")); throw re; } return null; }
Example 7
Source File: FluxUsing.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (eager && WIP.compareAndSet(this, 0, 1)) { try { resourceCleanup.accept(resource); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); t = Exceptions.addSuppressed(_e, t); } } actual.onError(t); if (!eager && WIP.compareAndSet(this, 0, 1)) { cleanup(); } }
Example 8
Source File: FluxUsing.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (eager && WIP.compareAndSet(this, 0, 1)) { try { resourceCleanup.accept(resource); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); t = Exceptions.addSuppressed(_e, t); } } actual.onError(t); if (!eager && WIP.compareAndSet(this, 0, 1)) { cleanup(); } }
Example 9
Source File: FluxUsing.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void onError(Throwable t) { if (eager && WIP.compareAndSet(this, 0, 1)) { try { resourceCleanup.accept(resource); } catch (Throwable e) { Throwable _e = Operators.onOperatorError(e, actual.currentContext()); t = Exceptions.addSuppressed(_e, t); } } actual.onError(t); if (!eager && WIP.compareAndSet(this, 0, 1)) { cleanup(); } }
Example 10
Source File: BaseSubscriber.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public final void onError(Throwable t) { Objects.requireNonNull(t, "onError"); if (S.getAndSet(this, Operators.cancelledSubscription()) == Operators .cancelledSubscription()) { //already cancelled concurrently Operators.onErrorDropped(t, currentContext()); return; } try { hookOnError(t); } catch (Throwable e) { e = Exceptions.addSuppressed(e, t); Operators.onErrorDropped(e, currentContext()); } finally { safeHookFinally(SignalType.ON_ERROR); } }
Example 11
Source File: OnNextFailureStrategy.java From reactor-core with Apache License 2.0 | 6 votes |
@Override @Nullable public Throwable process(Throwable error, @Nullable Object value, Context context) { if (errorPredicate == null) { Exceptions.throwIfFatal(error); } else if (!errorPredicate.test(error)) { Exceptions.throwIfFatal(error); return error; } try { errorConsumer.accept(error, value); return null; } catch (Throwable e) { return Exceptions.addSuppressed(e, error); } }
Example 12
Source File: Operators.java From reactor-core with Apache License 2.0 | 5 votes |
/** * Map an "operator" error given an operator parent {@link Subscription}. The * result error will be passed via onError to the operator downstream. * {@link Subscription} will be cancelled after checking for fatal error via * {@link Exceptions#throwIfFatal(Throwable)}. Takes an additional signal, which * can be added as a suppressed exception if it is a {@link Throwable} and the * default {@link Hooks#onOperatorError(BiFunction) hook} is in place. * * @param subscription the linked operator parent {@link Subscription} * @param error the callback or operator error * @param dataSignal the value (onNext or onError) signal processed during failure * @param context a context that might hold a local error consumer * @return mapped {@link Throwable} * */ public static Throwable onOperatorError(@Nullable Subscription subscription, Throwable error, @Nullable Object dataSignal, Context context) { Exceptions.throwIfFatal(error); if(subscription != null) { subscription.cancel(); } Throwable t = Exceptions.unwrap(error); BiFunction<? super Throwable, Object, ? extends Throwable> hook = context.getOrDefault(Hooks.KEY_ON_OPERATOR_ERROR, null); if (hook == null) { hook = Hooks.onOperatorErrorHook; } if (hook == null) { if (dataSignal != null) { if (dataSignal != t && dataSignal instanceof Throwable) { t = Exceptions.addSuppressed(t, (Throwable) dataSignal); } //do not wrap original value to avoid strong references /*else { }*/ } return t; } return hook.apply(error, dataSignal); }
Example 13
Source File: InheritableBaseSubscriber.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Override public void onError(Throwable t) { Objects.requireNonNull(t, "onError"); if (S.getAndSet(this, Operators.cancelledSubscription()) == Operators .cancelledSubscription()) { // Already cancelled concurrently // Workaround for Sentinel BlockException: // Here we add a predicate method to decide whether exception should be dropped implicitly // or call the {@code onErrorDropped} hook. if (shouldCallErrorDropHook()) { Operators.onErrorDropped(t, currentContext()); } return; } try { hookOnError(t); } catch (Throwable e) { e = Exceptions.addSuppressed(e, t); Operators.onErrorDropped(e, currentContext()); } finally { safeHookFinally(SignalType.ON_ERROR); } }
Example 14
Source File: InheritableBaseSubscriber.java From Sentinel with Apache License 2.0 | 5 votes |
@Override public void onError(Throwable t) { Objects.requireNonNull(t, "onError"); if (S.getAndSet(this, Operators.cancelledSubscription()) == Operators .cancelledSubscription()) { // Already cancelled concurrently // Workaround for Sentinel BlockException: // Here we add a predicate method to decide whether exception should be dropped implicitly // or call the {@code onErrorDropped} hook. if (shouldCallErrorDropHook()) { Operators.onErrorDropped(t, currentContext()); } return; } try { hookOnError(t); } catch (Throwable e) { e = Exceptions.addSuppressed(e, t); Operators.onErrorDropped(e, currentContext()); } finally { safeHookFinally(SignalType.ON_ERROR); } }
Example 15
Source File: FluxOnAssembly.java From reactor-core with Apache License 2.0 | 4 votes |
final Throwable fail(Throwable t) { boolean lightCheckpoint = snapshotStack.isLight(); OnAssemblyException onAssemblyException = null; for (Throwable e : t.getSuppressed()) { if (e instanceof OnAssemblyException) { onAssemblyException = (OnAssemblyException) e; break; } } if (onAssemblyException == null) { if (lightCheckpoint) { onAssemblyException = new OnAssemblyException(""); } else { StringBuilder sb = new StringBuilder(); fillStacktraceHeader(sb, parent.getClass(), snapshotStack.getDescription()); sb.append(snapshotStack.toAssemblyInformation().replaceFirst("\\n$", "")); String description = sb.toString(); onAssemblyException = new OnAssemblyException(description); } t = Exceptions.addSuppressed(t, onAssemblyException); final StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace.length > 0) { StackTraceElement[] newStackTrace = new StackTraceElement[stackTrace.length]; int i = 0; for (StackTraceElement stackTraceElement : stackTrace) { String className = stackTraceElement.getClassName(); if (className.startsWith("reactor.core.publisher.") && className.contains("OnAssembly")) { continue; } newStackTrace[i] = stackTraceElement; i++; } newStackTrace = Arrays.copyOf(newStackTrace, i); onAssemblyException.setStackTrace(newStackTrace); t.setStackTrace(new StackTraceElement[] { stackTrace[0] }); } } onAssemblyException.add(parent, snapshotStack); return t; }
Example 16
Source File: MonoProcessor.java From reactor-core with Apache License 2.0 | 4 votes |
/** * Block the calling thread for the specified time, waiting for the completion of this {@code MonoProcessor}. If the * {@link MonoProcessor} is completed with an error a RuntimeException that wraps the error is thrown. * * @param timeout the timeout value as a {@link Duration} * * @return the value of this {@code MonoProcessor} or {@code null} if the timeout is reached and the {@code MonoProcessor} has * not completed */ @Override @Nullable public O block(@Nullable Duration timeout) { try { if (!isPending()) { return peek(); } connect(); long delay; if (null == timeout) { delay = 0L; } else { delay = System.nanoTime() + timeout.toNanos(); } for (; ; ) { NextInner<O>[] inners = subscribers; if (inners == TERMINATED) { if (error != null) { RuntimeException re = Exceptions.propagate(error); re = Exceptions.addSuppressed(re, new Exception("Mono#block terminated with an error")); throw re; } if (value == null) { return null; } return value; } if (timeout != null && delay < System.nanoTime()) { cancel(); throw new IllegalStateException("Timeout on Mono blocking read"); } Thread.sleep(1); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); throw new IllegalStateException("Thread Interruption on Mono blocking read"); } }
Example 17
Source File: MonoCacheTime.java From reactor-core with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void signalCached(Signal<T> signal) { Signal<T> signalToPropagate = signal; if (STATE.compareAndSet(main, this, signal)) { Duration ttl = null; try { ttl = main.ttlGenerator.apply(signal); } catch (Throwable generatorError) { signalToPropagate = Signal.error(generatorError); STATE.set(main, signalToPropagate); if (signal.isOnError()) { //noinspection ThrowableNotThrown Exceptions.addSuppressed(generatorError, signal.getThrowable()); } } if (ttl != null) { if (ttl.isZero()) { //immediate cache clear main.run(); } else if (!ttl.equals(DURATION_INFINITE)) { main.clock.schedule(main, ttl.toNanos(), TimeUnit.NANOSECONDS); } //else TTL is Long.MAX_VALUE, schedule nothing but still cache } else { //error during TTL generation, signal != updatedSignal, aka dropped if (signal.isOnNext()) { Operators.onNextDropped(signal.get(), currentContext()); } //if signal.isOnError(), avoid dropping the error. it is not really dropped but already suppressed //in all cases, unless nextDropped hook throws, immediate cache clear main.run(); } } for (Operators.MonoSubscriber<T, T> inner : SUBSCRIBERS.getAndSet(this, TERMINATED)) { if (signalToPropagate.isOnNext()) { inner.complete(signalToPropagate.get()); } else if (signalToPropagate.isOnError()) { inner.onError(signalToPropagate.getThrowable()); } else { inner.onComplete(); } } }