Java Code Examples for reactor.core.Exceptions#throwIfFatal()
The following examples show how to use
reactor.core.Exceptions#throwIfFatal() .
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: 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 2
Source File: DefaultStepVerifierBuilder.java From reactor-core with Apache License 2.0 | 6 votes |
void waitTaskEvent() { Event<T> event; while ((event = taskEvents.poll()) != null) { try { if (event instanceof SubscriptionTaskEvent) { updateRequested(event); ((TaskEvent<T>) event).run(this); serializeDrainAndSubscriptionEvent(); } else { ((TaskEvent<T>) event).run(this); } } catch (Throwable t) { Exceptions.throwIfFatal(t); cancel(); if (t instanceof AssertionError) { throw (AssertionError) t; } throw Exceptions.propagate(t); } } }
Example 3
Source File: LambdaMonoSubscriber.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public final void onSubscribe(Subscription s) { if (Operators.validate(subscription, s)) { this.subscription = s; if (subscriptionConsumer != null) { try { subscriptionConsumer.accept(s); } catch (Throwable t) { Exceptions.throwIfFatal(t); s.cancel(); onError(t); } } else { s.request(Long.MAX_VALUE); } } }
Example 4
Source File: LambdaSubscriber.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public final void onComplete() { Subscription s = S.getAndSet(this, Operators.cancelledSubscription()); if (s == Operators.cancelledSubscription()) { return; } if (completeConsumer != null) { try { completeConsumer.run(); } catch (Throwable t) { Exceptions.throwIfFatal(t); onError(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: OnNextFailureStrategy.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public Throwable process(Throwable error, @Nullable Object value, Context context) { Exceptions.throwIfFatal(error); Throwable iee = new IllegalStateException("STOP strategy cannot process errors"); iee.addSuppressed(error); return iee; }
Example 7
Source File: VirtualTimeScheduler.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public void run() { if (!disposed) { try { run.run(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); throw Exceptions.propagate(ex); } } }
Example 8
Source File: FluxOnAssembly.java From reactor-core with Apache License 2.0 | 5 votes |
@Override @Nullable final public T poll() { try { return qs.poll(); } catch (final Throwable ex) { Exceptions.throwIfFatal(ex); throw Exceptions.propagate(fail(ex)); } }
Example 9
Source File: FluxOnAssembly.java From reactor-core with Apache License 2.0 | 5 votes |
@Override final public boolean isEmpty() { try { return qs.isEmpty(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); throw Exceptions.propagate(fail(ex)); } }
Example 10
Source File: FluxOnBackpressureBuffer.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public void onNext(T t) { if (done) { Operators.onNextDropped(t, ctx); return; } if (cancelled) { Operators.onDiscard(t, ctx); } if ((capacityOrSkip != Integer.MAX_VALUE && queue.size() >= capacityOrSkip) || !queue.offer(t)) { Throwable ex = Operators.onOperatorError(s, Exceptions.failWithOverflow(), t, ctx); if (onOverflow != null) { try { onOverflow.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); ex.initCause(e); } } Operators.onDiscard(t, ctx); onError(ex); return; } drain(t); }
Example 11
Source File: TestScheduler.java From rsocket-java with Apache License 2.0 | 5 votes |
@Override public Disposable schedule(Runnable task) { tasks.offer(task); if (WIP.getAndIncrement(this) != 0) { return Disposables.never(); } int missed = 1; for (; ; ) { for (; ; ) { Runnable runnable = tasks.poll(); if (runnable == null) { break; } try { runnable.run(); } catch (Throwable t) { Exceptions.throwIfFatal(t); } } missed = WIP.addAndGet(this, -missed); if (missed == 0) { return Disposables.never(); } } }
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: FluxDoFinally.java From reactor-core with Apache License 2.0 | 5 votes |
void runFinally(SignalType signalType) { if (ONCE.compareAndSet(this, 0, 1)) { try { onFinally.accept(signalType); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); Operators.onErrorDropped(ex, actual.currentContext()); } } }
Example 14
Source File: FluxCreate.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { BaseSink<T> sink = createSink(actual, backpressure); actual.onSubscribe(sink); try { source.accept( createMode == CreateMode.PUSH_PULL ? new SerializedSink<>(sink) : sink); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); sink.error(Operators.onOperatorError(ex, actual.currentContext())); } }
Example 15
Source File: FluxPublishOn.java From reactor-core with Apache License 2.0 | 4 votes |
void runAsync() { int missed = 1; final ConditionalSubscriber<? super T> a = actual; final Queue<T> q = queue; long emitted = produced; long polled = consumed; for (; ; ) { long r = requested; while (emitted != r) { boolean d = done; T v; try { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); s.cancel(); // delegates discarding to the queue holder to ensure there is no racing on draining from the SpScQueue q.clear(); doError(a, Operators.onOperatorError(ex, actual.currentContext())); return; } boolean empty = v == null; if (checkTerminated(d, empty, a, v)) { return; } if (empty) { break; } if (a.tryOnNext(v)) { emitted++; } polled++; if (polled == limit) { s.request(polled); polled = 0L; } } if (emitted == r && checkTerminated(done, q.isEmpty(), a, null)) { return; } int w = wip; if (missed == w) { produced = emitted; consumed = polled; missed = WIP.addAndGet(this, -missed); if (missed == 0) { break; } } else { missed = w; } } }
Example 16
Source File: FluxPublishOn.java From reactor-core with Apache License 2.0 | 4 votes |
void runAsync() { int missed = 1; final Subscriber<? super T> a = actual; final Queue<T> q = queue; long e = produced; for (; ; ) { long r = requested; while (e != r) { boolean d = done; T v; try { v = q.poll(); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); s.cancel(); if (sourceMode == ASYNC) { // delegates discarding to the queue holder to ensure there is no racing on draining from the SpScQueue queue.clear(); } else { // discard MUST be happening only and only if there is no racing on elements consumption // which is guaranteed by the WIP guard here Operators.onDiscardQueueWithClear(queue, actual.currentContext(), null); } doError(a, Operators.onOperatorError(ex, actual.currentContext())); return; } boolean empty = v == null; if (checkTerminated(d, empty, a, v)) { return; } if (empty) { break; } a.onNext(v); e++; if (e == limit) { if (r != Long.MAX_VALUE) { r = REQUESTED.addAndGet(this, -e); } s.request(e); e = 0L; } } if (e == r && checkTerminated(done, q.isEmpty(), a, null)) { return; } int w = wip; if (missed == w) { produced = e; missed = WIP.addAndGet(this, -missed); if (missed == 0) { break; } } else { missed = w; } } }
Example 17
Source File: DefaultStepVerifierBuilder.java From reactor-core with Apache License 2.0 | 4 votes |
final void startFusion(Subscription s) { if (s instanceof Fuseable.QueueSubscription) { @SuppressWarnings("unchecked") Fuseable.QueueSubscription<T> qs = (Fuseable.QueueSubscription<T>) s; this.qs = qs; int m = qs.requestFusion(requestedFusionMode); if (expectedFusionMode == Fuseable.NONE && m != Fuseable.NONE) { setFailure(null, "expected no fusion; actual: %s", formatFusionMode(m)); return; } if (expectedFusionMode != Fuseable.NONE && m == Fuseable.NONE) { setFailure(null, "expected fusion: %s; actual does not support " + "fusion", formatFusionMode(expectedFusionMode)); return; } if ((m & expectedFusionMode) != m) { setFailure(null, "expected fusion mode: %s; actual: %s", formatFusionMode(expectedFusionMode), formatFusionMode(m)); return; } this.establishedFusionMode = m; if (m == Fuseable.SYNC) { T v; for (; ; ) { if(get() == Operators.cancelledSubscription()){ return; } try { v = qs.poll(); } catch (Throwable e) { Exceptions.throwIfFatal(e); cancel(); onError(Exceptions.unwrap(e)); return; } if (v == null) { onComplete(); break; } onNext(v); } } else if (initialRequest != 0) { s.request(initialRequest); } } else if (expectedFusionMode != Fuseable.NONE) { setFailure(null, "expected fuseable source but actual Subscription " + "is " + "not: %s", expectedFusionMode, s); } else if (initialRequest != 0L) { s.request(initialRequest); } }
Example 18
Source File: DefaultStepVerifierBuilder.java From reactor-core with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") final void onExpectation(Signal<T> actualSignal) { if (monitorSignal) { setFailure(null, actualSignal, "expected no event: %s", actualSignal); return; } try { Event<T> event = this.script.peek(); if (event == null) { waitTaskEvent(); if (isCancelled()) { return; } setFailure(null, actualSignal, "did not expect: %s", actualSignal); return; } if (onTaskEvent()) { event = this.script.peek(); } if (event instanceof DefaultStepVerifierBuilder.SignalConsumeWhileEvent) { if (consumeWhile(actualSignal, (SignalConsumeWhileEvent<T>) event)) { return; } //possibly re-evaluate the current onNext event = this.script.peek(); } if (event instanceof SignalCountEvent) { if (onSignalCount(actualSignal, (SignalCountEvent<T>) event)) { return; } } else if (event instanceof CollectEvent) { if (onCollect(actualSignal)) { return; } } else if (event instanceof SignalSequenceEvent) { if (onSignalSequence(actualSignal, (SignalSequenceEvent<T>) event)) { return; } } else if (event instanceof SignalEvent) { if (onSignal(actualSignal)) { return; } } event = this.script.peek(); for (; ; ) { if (event == null || !(event instanceof EagerEvent)) { break; } if (event instanceof SubscriptionEvent) { if (serializeDrainAndSubscriptionEvent()) { return; } } else if (event instanceof CollectEvent) { if (onCollect(actualSignal)) { return; } } else { onTaskEvent(); } event = this.script.peek(); } } catch (Throwable e) { Exceptions.throwIfFatal(e); if(e instanceof AssertionError){ Exceptions.addThrowable(ERRORS, this, e); } else { String msg = e.getMessage() != null ? e.getMessage() : ""; AssertionError wrapFailure = messageFormatter.failOptional(null, "failed running expectation on signal [%s] " + "with " + "[%s]:\n%s", actualSignal, Exceptions.unwrap(e) .getClass() .getName(), msg).get(); wrapFailure.addSuppressed(e); Exceptions.addThrowable(ERRORS, this, wrapFailure); } maybeCancel(actualSignal); completeLatch.countDown(); } }
Example 19
Source File: FluxPeek.java From reactor-core with Apache License 2.0 | 3 votes |
/** * Common method for FluxPeek and FluxPeekFuseable to deal with a doAfterTerminate * callback that fails during onComplete. It drops the error to the global hook. * <ul> * <li>The callback failure is thrown immediately if fatal.</li> * <li>{@link Operators#onOperatorError(Throwable, Context)} is called</li> * <li>{@link Operators#onErrorDropped(Throwable, Context)} is called</li> * </ul> * <p> * * @param parent the {@link SignalPeek} from which to get the callbacks * @param callbackFailure the afterTerminate callback failure * @param context subscriber context */ //see https://github.com/reactor/reactor-core/issues/270 static <T> void afterCompleteWithFailure(SignalPeek<T> parent, Throwable callbackFailure, Context context) { Exceptions.throwIfFatal(callbackFailure); Throwable _e = Operators.onOperatorError(callbackFailure, context); Operators.onErrorDropped(_e, context); }
Example 20
Source File: FluxPeek.java From reactor-core with Apache License 2.0 | 3 votes |
/** * Common method for FluxPeek and FluxPeekFuseable to deal with a doAfterTerminate * callback that fails during onError. It drops the error to the global hook. * <ul> * <li>The callback failure is thrown immediately if fatal.</li> * <li>{@link Operators#onOperatorError(Subscription, Throwable, Object, Context)} is * called, adding the original error as suppressed</li> * <li>{@link Operators#onErrorDropped(Throwable, Context)} is called</li> * </ul> * <p> * * @param parent the {@link SignalPeek} from which to get the callbacks * @param callbackFailure the afterTerminate callback failure * @param originalError the onError throwable * @param context subscriber context */ //see https://github.com/reactor/reactor-core/issues/270 static <T> void afterErrorWithFailure(SignalPeek<T> parent, Throwable callbackFailure, Throwable originalError, Context context) { Exceptions.throwIfFatal(callbackFailure); Throwable _e = Operators.onOperatorError(null, callbackFailure, originalError, context); Operators.onErrorDropped(_e, context); }