diff --git a/reactor-core/src/main/java/reactor/core/publisher/BaseSubscriber.java b/reactor-core/src/main/java/reactor/core/publisher/BaseSubscriber.java index 286208f58b..fbe99e189b 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/BaseSubscriber.java +++ b/reactor-core/src/main/java/reactor/core/publisher/BaseSubscriber.java @@ -129,7 +129,7 @@ protected void hookOnCancel() { * cancel). The hook is executed in addition to and after {@link #hookOnError(Throwable)}, * {@link #hookOnComplete()} and {@link #hookOnCancel()} hooks, even if these callbacks * fail. Defaults to doing nothing. A failure of the callback will be caught by - * {@link Operators#onErrorDropped(Throwable)}. + * {@link Operators#onErrorDropped(Throwable, reactor.util.context.Context)}. * * @param type the type of termination event that triggered the hook * ({@link SignalType#ON_ERROR}, {@link SignalType#ON_COMPLETE} or @@ -146,7 +146,7 @@ public final void onSubscribe(Subscription s) { hookOnSubscribe(s); } catch (Throwable throwable) { - onError(Operators.onOperatorError(s, throwable)); + onError(Operators.onOperatorError(s, throwable, currentContext())); } } } @@ -158,7 +158,7 @@ public final void onNext(T value) { hookOnNext(value); } catch (Throwable throwable) { - onError(Operators.onOperatorError(subscription, throwable, value)); + onError(Operators.onOperatorError(subscription, throwable, value, currentContext())); } } @@ -169,7 +169,7 @@ public final void onError(Throwable t) { if (S.getAndSet(this, Operators.cancelledSubscription()) == Operators .cancelledSubscription()) { //already cancelled concurrently - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } @@ -181,7 +181,7 @@ public final void onError(Throwable t) { if (e != t) { e.addSuppressed(t); } - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, currentContext()); } finally { safeHookFinally(SignalType.ON_ERROR); @@ -198,7 +198,7 @@ public final void onComplete() { } catch (Throwable throwable) { //onError itself will short-circuit due to the CancelledSubscription being push above - hookOnError(Operators.onOperatorError(throwable)); + hookOnError(Operators.onOperatorError(throwable, currentContext())); } finally { safeHookFinally(SignalType.ON_COMPLETE); @@ -230,7 +230,7 @@ public final void cancel() { hookOnCancel(); } catch (Throwable throwable) { - hookOnError(Operators.onOperatorError(subscription, throwable)); + hookOnError(Operators.onOperatorError(subscription, throwable, currentContext())); } finally { safeHookFinally(SignalType.CANCEL); @@ -243,7 +243,7 @@ void safeHookFinally(SignalType type) { hookFinally(type); } catch (Throwable finallyFailure) { - Operators.onErrorDropped(finallyFailure); + Operators.onErrorDropped(finallyFailure, currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/BlockingIterable.java b/reactor-core/src/main/java/reactor/core/publisher/BlockingIterable.java index c13a6c9662..8d27831024 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/BlockingIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/BlockingIterable.java @@ -35,6 +35,7 @@ import org.reactivestreams.Subscription; import reactor.core.Exceptions; import reactor.core.Scannable; +import reactor.util.context.Context; /** * An iterable that consumes a Publisher in a blocking fashion. @@ -221,7 +222,7 @@ public void onNext(T t) { onError(Operators.onOperatorError(null, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), - t)); + t, currentContext())); } else { signalConsumer(); diff --git a/reactor-core/src/main/java/reactor/core/publisher/DirectProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/DirectProcessor.java index e3a4a79311..1fc8491287 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/DirectProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/DirectProcessor.java @@ -98,7 +98,7 @@ public void onNext(T t) { DirectInner[] inners = subscribers; if (inners == TERMINATED) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); return; } @@ -114,7 +114,7 @@ public void onError(Throwable t) { DirectInner[] inners = subscribers; if (inners == TERMINATED) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/EmitterProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/EmitterProcessor.java index 3f0b4dcac1..7131d7159c 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/EmitterProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/EmitterProcessor.java @@ -228,6 +228,7 @@ else if (m == Fuseable.ASYNC) { @SuppressWarnings("unchecked") public void onNext(T t) { if (done) { + Operators.onNextDropped(t, currentContext()); return; } @@ -268,7 +269,7 @@ public void onNext(T t) { public void onError(Throwable t) { Objects.requireNonNull(t, "onError"); if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } if (Exceptions.addThrowable(ERROR, this, t)) { @@ -276,7 +277,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDroppedMulticast(t); } } @@ -373,8 +374,7 @@ final void drain() { } catch (Throwable ex) { Exceptions.addThrowable(ERROR, - this, - Operators.onOperatorError(s, ex)); + this, Operators.onOperatorError(s, ex, currentContext())); d = true; v = null; } @@ -398,8 +398,7 @@ final void drain() { } catch (Throwable ex) { Exceptions.addThrowable(ERROR, - this, - Operators.onOperatorError(s, ex)); + this, Operators.onOperatorError(s, ex, currentContext())); d = true; v = null; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/EventLoopProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/EventLoopProcessor.java index eec6eedb02..eb9a71a8e9 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/EventLoopProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/EventLoopProcessor.java @@ -31,7 +31,6 @@ import java.util.stream.Stream; import org.reactivestreams.Subscription; -import reactor.core.Exceptions; import reactor.core.Scannable; import reactor.util.concurrent.Queues; import reactor.util.concurrent.WaitStrategy; @@ -427,7 +426,7 @@ final public void onSubscribe(final Subscription s) { } } catch (Throwable t) { - onError(Operators.onOperatorError(s, t)); + onError(Operators.onOperatorError(s, t, currentContext())); } } } @@ -448,7 +447,7 @@ public final void shutdown() { requestTaskExecutor.shutdown(); } catch (Throwable t) { - onError(Operators.onOperatorError(t)); + onError(Operators.onOperatorError(t, currentContext())); } } @@ -527,7 +526,7 @@ public void run() { } return; } - parent.onError(Operators.onOperatorError(t)); + parent.onError(Operators.onOperatorError(t, parent.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/Flux.java b/reactor-core/src/main/java/reactor/core/publisher/Flux.java index 5cf95da989..69c24356d4 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/Flux.java +++ b/reactor-core/src/main/java/reactor/core/publisher/Flux.java @@ -3535,7 +3535,7 @@ public final Flux doOnNext(Consumer onNext) { * receives any request. *

* Note that non fatal error raised in the callback will not be propagated and - * will simply trigger {@link Operators#onOperatorError(Throwable)}. + * will simply trigger {@link Operators#onOperatorError(Throwable, Context)}. * *

* diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxBuffer.java b/reactor-core/src/main/java/reactor/core/publisher/FluxBuffer.java index 1c7e8142d9..c0193745b5 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxBuffer.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxBuffer.java @@ -129,7 +129,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -140,7 +140,7 @@ public void onNext(T t) { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } buffer = b; @@ -157,7 +157,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -271,7 +271,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -285,7 +285,7 @@ public void onNext(T t) { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -306,7 +306,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -450,7 +450,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -464,7 +464,7 @@ public void onNext(T t) { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -495,7 +495,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferBoundary.java b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferBoundary.java index c91b7c2955..2b9114bd2f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferBoundary.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferBoundary.java @@ -68,7 +68,7 @@ public void subscribe(CoreSubscriber actual) { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -167,7 +167,7 @@ public void onNext(T t) { } } - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); } @Override @@ -181,7 +181,7 @@ public void onError(Throwable t) { actual.onError(t); return; } - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } @Override @@ -242,7 +242,7 @@ void otherError(Throwable t){ actual.onError(t); return; } - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } void otherNext() { @@ -253,7 +253,7 @@ void otherNext() { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - otherError(Operators.onOperatorError(other, e)); + otherError(Operators.onOperatorError(other, e, actual.currentContext())); return; } @@ -281,7 +281,7 @@ boolean emit(C b) { } else { actual.onError(Operators.onOperatorError(this, Exceptions - .failWithOverflow(), b)); + .failWithOverflow(), b, actual.currentContext())); return false; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferPredicate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferPredicate.java index 2517823282..9e7d27b3d6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferPredicate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferPredicate.java @@ -84,7 +84,7 @@ public void subscribe(CoreSubscriber actual) { "The bufferSupplier returned a null initial buffer"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -185,7 +185,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -195,7 +195,7 @@ public boolean tryOnNext(T t) { match = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -237,7 +237,7 @@ private C triggerNewBuffer() { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return null; } @@ -261,7 +261,7 @@ public CoreSubscriber actual() { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferTimeOrSize.java b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferTimeOrSize.java index 42a07d5828..0d3d4efc1f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferTimeOrSize.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferTimeOrSize.java @@ -199,7 +199,8 @@ public void onNext(final T value) { timespanRegistration = timer.schedule(flushTask, timespan, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ree) { - onError(Operators.onRejectedExecution(ree, this, null, value)); + onError(Operators.onRejectedExecution(ree, this, null, value, + actual.currentContext())); return; } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferWhen.java b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferWhen.java index 12cb44ff7f..ad84c26e3c 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxBufferWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxBufferWhen.java @@ -185,7 +185,7 @@ public void onNext(T t) { } } - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); } @Override @@ -206,7 +206,7 @@ public void onError(Throwable t) { anyError(t); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -312,7 +312,7 @@ void anyError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -328,7 +328,7 @@ void startNext(U u) { "The bufferSupplier returned a null buffer"); } catch (Throwable e) { - anyError(Operators.onOperatorError(starter, e, u)); + anyError(Operators.onOperatorError(starter, e, u, actual.currentContext())); return; } @@ -348,7 +348,7 @@ void startNext(U u) { "The end returned a null publisher"); } catch (Throwable e) { - anyError(Operators.onOperatorError(starter, e, u)); + anyError(Operators.onOperatorError(starter, e, u, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxCallable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxCallable.java index d7df06c745..1082725b3a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxCallable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxCallable.java @@ -45,7 +45,7 @@ public void subscribe(CoreSubscriber actual) { v = Objects.requireNonNull(callable.call(), "callable returned null"); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(ex)); + actual.onError(Operators.onOperatorError(ex, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxCancelOn.java b/reactor-core/src/main/java/reactor/core/publisher/FluxCancelOn.java index ccbb2cf93f..b5a9fbd7e3 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxCancelOn.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxCancelOn.java @@ -110,7 +110,7 @@ public void cancel() { scheduler.schedule(this); } catch (RejectedExecutionException ree) { - throw Operators.onRejectedExecution(ree); + throw Operators.onRejectedExecution(ree, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxCombineLatest.java b/reactor-core/src/main/java/reactor/core/publisher/FluxCombineLatest.java index d367150304..984aeaeab6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxCombineLatest.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxCombineLatest.java @@ -106,7 +106,8 @@ public void subscribe(CoreSubscriber actual) { it = Objects.requireNonNull(iterable.iterator(), "The iterator returned is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -118,7 +119,8 @@ public void subscribe(CoreSubscriber actual) { b = it.hasNext(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -133,7 +135,8 @@ public void subscribe(CoreSubscriber actual) { "The Publisher returned by the iterator is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -307,7 +310,8 @@ void innerValue(int index, T value) { new SourceAndArray(subscribers[index], os.clone()); if (!queue.offer(sa)) { - innerError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL))); + innerError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), + actual.currentContext())); return; } @@ -355,7 +359,7 @@ void innerError(Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -432,7 +436,8 @@ void drainAsync() { w = Objects.requireNonNull(combiner.apply(v.array), "Combiner returned null"); } catch (Throwable ex) { - ex = Operators.onOperatorError(this, ex, v.array); + ex = Operators.onOperatorError(this, ex, v.array, + actual.currentContext()); Exceptions.addThrowable(ERROR, this, ex); //noinspection ConstantConditions ex = Exceptions.terminate(ERROR, this); diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatArray.java b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatArray.java index 4425fbf976..1cc95616ca 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatArray.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatArray.java @@ -247,7 +247,7 @@ public void onError(Throwable t) { if (Exceptions.addThrowable(ERROR, this, t)) { onComplete(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatIterable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatIterable.java index 889117fdce..6e6cb9c81e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatIterable.java @@ -48,7 +48,7 @@ public void subscribe(CoreSubscriber actual) { "The Iterator returned is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -102,7 +102,8 @@ public void onComplete() { b = a.hasNext(); } catch (Throwable e) { - onError(Operators.onOperatorError(this, e)); + onError(Operators.onOperatorError(this, e, + actual.currentContext())); return; } @@ -122,7 +123,8 @@ public void onComplete() { "The Publisher returned by the iterator is null"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(this, e)); + actual.onError(Operators.onOperatorError(this, e, + actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatMap.java b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatMap.java index cbf3b8c70c..4a7261711e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxConcatMap.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxConcatMap.java @@ -234,7 +234,8 @@ public void onNext(T t) { drain(); } else if (!queue.offer(t)) { - onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + actual.currentContext())); } else { drain(); @@ -254,7 +255,7 @@ public void onError(Throwable t) { } } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -297,7 +298,7 @@ public void innerError(Throwable e) { } } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -337,7 +338,8 @@ void drain() { v = queue.poll(); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e)); + actual.onError(Operators.onOperatorError(s, e, + actual.currentContext())); return; } @@ -356,7 +358,8 @@ void drain() { "The mapper returned a null Publisher"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e, v)); + actual.onError(Operators.onOperatorError(s, e, v, + actual.currentContext())); return; } @@ -381,7 +384,8 @@ void drain() { vr = callable.call(); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e, v)); + actual.onError(Operators.onOperatorError(s, e, v, + actual.currentContext())); return; } @@ -570,7 +574,8 @@ public void onNext(T t) { drain(); } else if (!queue.offer(t)) { - onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + actual.currentContext())); } else { drain(); @@ -584,7 +589,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -616,7 +621,7 @@ public void innerError(Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -664,7 +669,8 @@ void drain() { v = queue.poll(); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e)); + actual.onError(Operators.onOperatorError(s, e, + actual.currentContext())); return; } @@ -689,7 +695,8 @@ void drain() { "The mapper returned a null Publisher"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e, v)); + actual.onError(Operators.onOperatorError(s, e, v, + actual.currentContext())); return; } @@ -714,7 +721,8 @@ void drain() { vr = supplier.call(); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(s, e, v)); + actual.onError(Operators.onOperatorError(s, e, v, + actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxContextStart.java b/reactor-core/src/main/java/reactor/core/publisher/FluxContextStart.java index 1e2e2c39f8..d552278a14 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxContextStart.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxContextStart.java @@ -42,7 +42,7 @@ public void subscribe(CoreSubscriber actual) { c = doOnContext.apply(actual.currentContext()); } catch (Throwable t) { - Operators.error(actual, Operators.onOperatorError(t)); + Operators.error(actual, Operators.onOperatorError(t, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxCreate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxCreate.java index 95ed5b0f69..e14e4dd0d7 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxCreate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxCreate.java @@ -95,7 +95,7 @@ public void subscribe(CoreSubscriber actual) { } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - sink.error(Operators.onOperatorError(ex)); + sink.error(Operators.onOperatorError(ex, actual.currentContext())); } } @@ -137,6 +137,7 @@ public Context currentContext() { @Override public FluxSink next(T t) { if (sink.isCancelled() || done) { + Operators.onNextDropped(t, sink.currentContext()); return this; } //noinspection ConstantConditions @@ -165,7 +166,7 @@ public FluxSink next(T t) { @Override public void error(Throwable t) { if (sink.isCancelled() || done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, sink.currentContext()); return; } //noinspection ConstantConditions @@ -177,7 +178,7 @@ public void error(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, sink.currentContext()); } } @@ -418,6 +419,7 @@ public void complete() { @Override public void error(Throwable e) { if (isCancelled()) { + Operators.onErrorDropped(e, actual.currentContext()); return; } try { @@ -567,6 +569,7 @@ static final class IgnoreSink extends BaseSink { @Override public FluxSink next(T t) { if (isCancelled()) { + Operators.onNextDropped(t, actual.currentContext()); return this; } @@ -591,6 +594,7 @@ static abstract class NoOverflowBaseAsyncSink extends BaseSink { @Override public final FluxSink next(T t) { if (isCancelled()) { + Operators.onNextDropped(t, actual.currentContext()); return this; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDefer.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDefer.java index 2199a88082..fb292cc637 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDefer.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDefer.java @@ -47,7 +47,7 @@ public void subscribe(CoreSubscriber actual) { "The Publisher returned by the supplier is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDelaySubscription.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDelaySubscription.java index bd293d1780..01def6184b 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDelaySubscription.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDelaySubscription.java @@ -125,7 +125,7 @@ public void onNext(U t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDematerialize.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDematerialize.java index 83316771e2..e51b7cefe4 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDematerialize.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDematerialize.java @@ -94,7 +94,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(Signal t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (t.isOnComplete()) { @@ -119,7 +119,7 @@ else if (t.isOnNext()) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinct.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinct.java index debb437b75..6062b62702 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinct.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinct.java @@ -64,7 +64,7 @@ public void subscribe(CoreSubscriber actual) { "The collectionSupplier returned a null collection"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -118,7 +118,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -129,7 +129,7 @@ public boolean tryOnNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -139,7 +139,7 @@ public boolean tryOnNext(T t) { b = collection.add(k); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -153,7 +153,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -230,7 +230,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -241,7 +241,7 @@ public void onNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -251,7 +251,7 @@ public void onNext(T t) { b = collection.add(k); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -266,7 +266,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -277,7 +277,7 @@ public boolean tryOnNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -287,7 +287,7 @@ public boolean tryOnNext(T t) { b = collection.add(k); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -297,7 +297,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -391,7 +391,7 @@ public boolean tryOnNext(T t) { return true; } if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -402,7 +402,7 @@ public boolean tryOnNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(qs, e, t)); + onError(Operators.onOperatorError(qs, e, t, actual.currentContext())); return true; } @@ -412,7 +412,7 @@ public boolean tryOnNext(T t) { b = collection.add(k); } catch (Throwable e) { - onError(Operators.onOperatorError(qs, e, t)); + onError(Operators.onOperatorError(qs, e, t, actual.currentContext())); return true; } @@ -426,7 +426,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctFuseable.java index 56adcef57c..9ed8982b52 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctFuseable.java @@ -60,7 +60,7 @@ public void subscribe(CoreSubscriber actual) { "The collectionSupplier returned a null collection"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctUntilChanged.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctUntilChanged.java index f26b7b978b..9be316b2de 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctUntilChanged.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDistinctUntilChanged.java @@ -96,7 +96,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -107,7 +107,7 @@ public boolean tryOnNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -123,7 +123,7 @@ public boolean tryOnNext(T t) { equiv = keyComparator.test(lastKey, k); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -139,7 +139,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -222,7 +222,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -233,7 +233,7 @@ public boolean tryOnNext(T t) { "The distinct extractor returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -248,7 +248,7 @@ public boolean tryOnNext(T t) { equiv = keyComparator.test(lastKey, k); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -263,7 +263,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinally.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinally.java index 4de33f1a5d..d2d62684aa 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinally.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinally.java @@ -35,7 +35,7 @@ * {@link SignalType#CANCEL}). *

* Note that any exception thrown by the hook are caught and bubbled up - * using {@link Operators#onErrorDropped(Throwable)}. + * using {@link Operators#onErrorDropped(Throwable, reactor.util.context.Context)}. * * @param the value type * @author Simon Baslé @@ -152,7 +152,7 @@ void runFinally(SignalType signalType) { onFinally.accept(signalType); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinallyFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinallyFuseable.java index be8b34a6ba..feb53aa75d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinallyFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDoFinallyFuseable.java @@ -29,7 +29,7 @@ * {@link SignalType#CANCEL}). *

* Note that any exception thrown by the hook are caught and bubbled up - * using {@link Operators#onErrorDropped(Throwable)}. + * using {@link Operators#onErrorDropped(Throwable, reactor.util.context.Context)}. * * @param the value type * @author Simon Baslé diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxDoOnEach.java b/reactor-core/src/main/java/reactor/core/publisher/FluxDoOnEach.java index a2de39fd7c..a7d82c28c1 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxDoOnEach.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxDoOnEach.java @@ -17,7 +17,6 @@ package reactor.core.publisher; import java.util.Objects; -import java.util.function.BiConsumer; import java.util.function.Consumer; import javax.annotation.Nullable; @@ -98,7 +97,7 @@ public Object scanUnsafe(Attr key) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } try { @@ -107,7 +106,7 @@ public void onNext(T t) { onSignal.accept(this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -117,7 +116,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -127,7 +126,7 @@ public void onError(Throwable t) { } catch (Throwable e) { //this performs a throwIfFatal or suppresses t in e - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } try { @@ -153,7 +152,7 @@ public void onComplete() { } catch (Throwable e) { done = false; - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxError.java b/reactor-core/src/main/java/reactor/core/publisher/FluxError.java index 72277b657a..81cd756f38 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxError.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxError.java @@ -18,12 +18,8 @@ import java.util.Objects; -import org.reactivestreams.Subscriber; import reactor.core.Exceptions; import reactor.core.Fuseable; -import reactor.util.context.Context; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import javax.annotation.Nullable; import reactor.core.CoreSubscriber; @@ -44,7 +40,7 @@ final class FluxError extends Flux implements Fuseable.ScalarCallable { @Override public void subscribe(CoreSubscriber actual) { - Operators.error(actual, Operators.onOperatorError(error)); + Operators.error(actual, Operators.onOperatorError(error, actual.currentContext())); } @Override diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFilter.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFilter.java index 0728159157..a1eb150dd2 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFilter.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFilter.java @@ -80,7 +80,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -90,7 +90,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (b) { @@ -104,7 +104,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -114,7 +114,7 @@ public boolean tryOnNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } if (b) { @@ -126,7 +126,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -196,7 +196,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -206,7 +206,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (b) { @@ -220,7 +220,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -230,7 +230,7 @@ public boolean tryOnNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } return b && actual.tryOnNext(t); @@ -239,7 +239,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFilterFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFilterFuseable.java index 23b7b464b9..e4123c536f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFilterFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFilterFuseable.java @@ -88,7 +88,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } boolean b; @@ -97,7 +97,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (b) { @@ -112,7 +112,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -122,7 +122,7 @@ public boolean tryOnNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } if (b) { @@ -135,7 +135,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -269,7 +269,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } boolean b; @@ -278,7 +278,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (b) { @@ -293,7 +293,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -303,7 +303,7 @@ public boolean tryOnNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } return b && actual.tryOnNext(t); @@ -312,7 +312,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFilterWhen.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFilterWhen.java index bcb5440051..54ae614ec7 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFilterWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFilterWhen.java @@ -439,7 +439,7 @@ public void onError(Throwable t) { done = true; parent.innerError(t); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, parent.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFirstEmitting.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFirstEmitting.java index c5f98d6499..275ebe97d4 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFirstEmitting.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFirstEmitting.java @@ -68,7 +68,8 @@ public void subscribe(CoreSubscriber actual) { "The iterator returned is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -80,7 +81,8 @@ public void subscribe(CoreSubscriber actual) { b = it.hasNext(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -95,7 +97,8 @@ public void subscribe(CoreSubscriber actual) { "The Publisher returned by the iterator is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFlatMap.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFlatMap.java index 50c432639f..25e999beb6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFlatMap.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFlatMap.java @@ -126,7 +126,7 @@ static boolean trySubscribeScalarMap(Publisher source, t = ((Callable) source).call(); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(e)); + Operators.error(s, Operators.onOperatorError(e, s.currentContext())); return true; } @@ -142,7 +142,7 @@ static boolean trySubscribeScalarMap(Publisher source, "The mapper returned a null Publisher"); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(null, e, t)); + Operators.error(s, Operators.onOperatorError(null, e, t, s.currentContext())); return true; } @@ -153,7 +153,7 @@ static boolean trySubscribeScalarMap(Publisher source, v = ((Callable) p).call(); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(null, e, t)); + Operators.error(s, Operators.onOperatorError(null, e, t, s.currentContext())); return true; } @@ -343,7 +343,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -354,7 +354,7 @@ public void onNext(T t) { "The mapper returned a null Publisher"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -364,7 +364,7 @@ public void onNext(T t) { v = ((Callable) p).call(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } tryEmitScalar(v); @@ -391,7 +391,7 @@ Queue getOrCreateScalarQueue() { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } if (Exceptions.addThrowable(ERROR, this, t)) { @@ -399,7 +399,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -620,9 +620,11 @@ else if (q != null) { v = q.poll(); } catch (Throwable ex) { - ex = Operators.onOperatorError(inner, ex); + ex = Operators.onOperatorError(inner, ex, + actual.currentContext()); if (!Exceptions.addThrowable(ERROR, this, ex)) { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, + actual.currentContext()); } v = null; d = true; @@ -790,17 +792,17 @@ void innerError(FlatMapInner inner, Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } boolean failOverflow(R v, Subscription toCancel){ Throwable e = Operators.onOperatorError(toCancel, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), - v); + v, actual.currentContext()); if (!Exceptions.addThrowable(ERROR, this, e)) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); return false; } return true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxFlattenIterable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxFlattenIterable.java index cf2e623b31..3027ed62d1 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxFlattenIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxFlattenIterable.java @@ -77,7 +77,8 @@ public void subscribe(CoreSubscriber actual) { v = ((Callable) source).call(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -94,7 +95,8 @@ public void subscribe(CoreSubscriber actual) { it = iter.iterator(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -228,7 +230,8 @@ else if (m == Fuseable.ASYNC) { public void onNext(T t) { if (fusionMode != Fuseable.ASYNC) { if (!queue.offer(t)) { - onError(Operators.onOperatorError(s,Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL))); + onError(Operators.onOperatorError(s,Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), + actual.currentContext())); return; } } @@ -242,7 +245,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -326,7 +329,8 @@ void drainAsync() { } catch (Throwable exc) { it = null; - onError(Operators.onOperatorError(s, exc, t)); + onError(Operators.onOperatorError(s, exc, t, + actual.currentContext())); continue; } @@ -372,7 +376,8 @@ void drainAsync() { "iterator returned null"); } catch (Throwable exc) { - onError(Operators.onOperatorError(s, exc)); + onError(Operators.onOperatorError(s, exc, + actual.currentContext())); continue; } @@ -392,7 +397,8 @@ void drainAsync() { b = it.hasNext(); } catch (Throwable exc) { - onError(Operators.onOperatorError(s, exc)); + onError(Operators.onOperatorError(s, exc, + actual.currentContext())); continue; } @@ -500,7 +506,8 @@ void drainSync() { } catch (Throwable exc) { current = null; - a.onError(Operators.onOperatorError(s, exc, t)); + a.onError(Operators.onOperatorError(s, exc, t, + actual.currentContext())); return; } @@ -530,7 +537,8 @@ void drainSync() { } catch (Throwable exc) { current = null; - a.onError(Operators.onOperatorError(s, exc)); + a.onError(Operators.onOperatorError(s, exc, + actual.currentContext())); return; } @@ -551,7 +559,8 @@ void drainSync() { } catch (Throwable exc) { current = null; - a.onError(Operators.onOperatorError(s, exc)); + a.onError(Operators.onOperatorError(s, exc, + actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxGenerate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxGenerate.java index c27208e56e..a716ca3d91 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxGenerate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxGenerate.java @@ -77,7 +77,7 @@ public void subscribe(CoreSubscriber actual) { try { state = stateSupplier.call(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } actual.onSubscribe(new GenerateSubscription<>(actual, state, generator, stateConsumer)); @@ -145,7 +145,7 @@ public CoreSubscriber actual() { @Override public void next(T t) { if (terminate) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (hasValue) { @@ -219,7 +219,7 @@ void fastPath() { } catch (Throwable e) { cleanup(s); - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } if (terminate || cancelled) { @@ -306,7 +306,7 @@ void cleanup(S s) { stateConsumer.accept(s); } catch (Throwable e) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxGroupBy.java b/reactor-core/src/main/java/reactor/core/publisher/FluxGroupBy.java index e6bf0fb0af..e5a40af589 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxGroupBy.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxGroupBy.java @@ -174,7 +174,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if(done){ - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -186,7 +186,7 @@ public void onNext(T t) { value = Objects.requireNonNull(valueSelector.apply(t), "The valueSelector returned a null value"); } catch (Throwable ex) { - onError(Operators.onOperatorError(s, ex, t)); + onError(Operators.onOperatorError(s, ex, t, actual.currentContext())); return; } @@ -218,7 +218,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -663,7 +663,8 @@ public void onNext(V t) { Subscriber a = actual; if (!queue.offer(t)) { - onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + actual.currentContext())); return; } if (outputFused) { diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxGroupJoin.java b/reactor-core/src/main/java/reactor/core/publisher/FluxGroupJoin.java index 5975b144a4..2d1da397c2 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxGroupJoin.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxGroupJoin.java @@ -328,7 +328,8 @@ void drain() { catch (Throwable exc) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(this, exc, left)); + Operators.onOperatorError(this, exc, left, + actual.currentContext())); errorAll(a); return; } @@ -355,7 +356,8 @@ void drain() { } catch (Throwable exc) { Exceptions.addThrowable(ERROR, - this, Operators.onOperatorError(this, exc, up)); + this, Operators.onOperatorError(this, exc, up, + actual.currentContext())); errorAll(a); return; } @@ -374,7 +376,8 @@ void drain() { Exceptions.addThrowable(ERROR, this, Operators.onOperatorError(this, - Exceptions.failWithOverflow())); + Exceptions.failWithOverflow(), + actual.currentContext())); errorAll(a); return; } @@ -412,7 +415,8 @@ else if (mode == RIGHT_VALUE) { catch (Throwable exc) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(this, exc, right)); + Operators.onOperatorError(this, exc, right, + actual.currentContext())); errorAll(a); return; } @@ -466,7 +470,7 @@ public void innerError(Throwable ex) { drain(); } else { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } @@ -499,7 +503,7 @@ public void innerCloseError(Throwable ex) { drain(); } else { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxHandle.java b/reactor-core/src/main/java/reactor/core/publisher/FluxHandle.java index 9676ac295c..b71cb1abd8 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxHandle.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxHandle.java @@ -89,7 +89,7 @@ public Context currentContext() { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -97,7 +97,7 @@ public void onNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } R v = data; @@ -108,7 +108,8 @@ public void onNext(T t) { if(stop){ s.cancel(); if(error != null){ - onError(Operators.onOperatorError(null, error, t)); + onError(Operators.onOperatorError(null, error, t, + actual.currentContext())); return; } onComplete(); @@ -121,7 +122,7 @@ else if(v == null){ @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -129,7 +130,7 @@ public boolean tryOnNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } R v = data; @@ -140,7 +141,8 @@ public boolean tryOnNext(T t) { if(stop){ s.cancel(); if(error != null){ - onError(Operators.onOperatorError(null, error, t)); + onError(Operators.onOperatorError(null, error, t, + actual.currentContext())); } else { onComplete(); @@ -153,7 +155,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -251,7 +253,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -259,7 +261,7 @@ public void onNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } R v = data; @@ -270,7 +272,8 @@ public void onNext(T t) { if(done){ s.cancel(); if(error != null){ - actual.onError(Operators.onOperatorError(null, error, t)); + actual.onError(Operators.onOperatorError(null, error, t, + actual.currentContext())); return; } actual.onComplete(); @@ -283,7 +286,7 @@ else if(v == null){ @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -291,7 +294,7 @@ public boolean tryOnNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } R v = data; @@ -303,7 +306,8 @@ public boolean tryOnNext(T t) { if(done){ s.cancel(); if(error != null){ - actual.onError(Operators.onOperatorError(null, error, t)); + actual.onError(Operators.onOperatorError(null, error, t, + actual.currentContext())); } else { actual.onComplete(); @@ -316,7 +320,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxHandleFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxHandleFuseable.java index 20e2ed0d29..f835433b33 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxHandleFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxHandleFuseable.java @@ -96,7 +96,7 @@ public Context currentContext() { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -104,7 +104,7 @@ public boolean tryOnNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } R v = data; @@ -114,7 +114,8 @@ public boolean tryOnNext(T t) { } if (done) { if (error != null) { - actual.onError(Operators.onOperatorError(s, error, t)); + actual.onError(Operators.onOperatorError(s, error, t, + actual.currentContext())); } else { s.cancel(); @@ -141,14 +142,14 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } try { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } R v = data; @@ -159,7 +160,8 @@ public void onNext(T t) { if (done) { s.cancel(); if (error != null) { - actual.onError(Operators.onOperatorError(null, error, t)); + actual.onError(Operators.onOperatorError(null, error, t, + actual.currentContext())); return; } actual.onComplete(); @@ -173,7 +175,7 @@ else if (v == null) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -236,7 +238,7 @@ public R poll() { s.cancel(); if (error != null) { throw Exceptions.propagate(Operators.onOperatorError - (null, error, v)); + (null, error, v, actual.currentContext())); } else { actual.onComplete(); @@ -267,7 +269,7 @@ else if (dropped != 0L) { if (done) { if (error != null) { throw Exceptions.propagate(Operators.onOperatorError - (null, error, v)); + (null, error, v, actual.currentContext())); } return u; } @@ -373,14 +375,14 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } try { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } R v = data; @@ -391,7 +393,8 @@ public void onNext(T t) { if (done) { s.cancel(); if (error != null) { - actual.onError(Operators.onOperatorError(null, error, v)); + actual.onError(Operators.onOperatorError(null, error, v, + actual.currentContext())); return; } actual.onComplete(); @@ -405,7 +408,7 @@ else if (v == null) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -413,7 +416,7 @@ public boolean tryOnNext(T t) { handler.accept(t, this); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } R v = data; @@ -425,7 +428,8 @@ public boolean tryOnNext(T t) { if (done) { s.cancel(); if (error != null) { - actual.onError(Operators.onOperatorError(null, error, v)); + actual.onError(Operators.onOperatorError(null, error, v, + actual.currentContext())); } else { actual.onComplete(); @@ -438,7 +442,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -520,7 +524,7 @@ public R poll() { s.cancel(); if (error != null) { throw Exceptions.propagate(Operators.onOperatorError - (null, error, v)); + (null, error, v, actual.currentContext())); } else { actual.onComplete(); @@ -551,7 +555,7 @@ else if (dropped != 0L) { if (done) { if (error != null) { throw Exceptions.propagate(Operators.onOperatorError - (null, error, v)); + (null, error, v, actual.currentContext())); } return u; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxInterval.java b/reactor-core/src/main/java/reactor/core/publisher/FluxInterval.java index d1f26a59c3..52b189545e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxInterval.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxInterval.java @@ -69,7 +69,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if (!r.cancelled) { - actual.onError(Operators.onRejectedExecution(ree, r, null, null)); + actual.onError(Operators.onRejectedExecution(ree, r, null, null, + actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxIterable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxIterable.java index 0ec1a1a018..c44544ad74 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxIterable.java @@ -48,7 +48,7 @@ public void subscribe(CoreSubscriber actual) { it = iterable.iterator(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -75,7 +75,7 @@ static void subscribe(CoreSubscriber s, Iterator it) b = it.hasNext(); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(e)); + Operators.error(s, Operators.onOperatorError(e, s.currentContext())); return; } if (!b) { diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxJoin.java b/reactor-core/src/main/java/reactor/core/publisher/FluxJoin.java index a7dbd05f86..d27fbf7c90 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxJoin.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxJoin.java @@ -279,7 +279,8 @@ void drain() { catch (Throwable exc) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(this, exc, left)); + Operators.onOperatorError(this, exc, left, + actual.currentContext())); errorAll(a); return; } @@ -314,7 +315,7 @@ void drain() { Exceptions.addThrowable(ERROR, this, Operators.onOperatorError(this, - exc, right)); + exc, right, actual.currentContext())); errorAll(a); return; } @@ -346,7 +347,8 @@ void drain() { Exceptions.addThrowable(ERROR, this, Operators.onOperatorError(this, - Exceptions.failWithOverflow())); + Exceptions.failWithOverflow(), + actual.currentContext())); errorAll(a); return; } @@ -373,7 +375,8 @@ else if (mode == RIGHT_VALUE) { catch (Throwable exc) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(this, exc, right)); + Operators.onOperatorError(this, exc, right, + actual.currentContext())); errorAll(a); return; } @@ -407,7 +410,8 @@ else if (mode == RIGHT_VALUE) { catch (Throwable exc) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(this, exc, left)); + Operators.onOperatorError(this, exc, left, + actual.currentContext())); errorAll(a); return; } @@ -439,7 +443,8 @@ else if (mode == RIGHT_VALUE) { Exceptions.addThrowable(ERROR, this, Operators.onOperatorError(this, - Exceptions.failWithOverflow())); + Exceptions.failWithOverflow(), + actual.currentContext())); errorAll(a); return; } @@ -478,7 +483,7 @@ public void innerError(Throwable ex) { drain(); } else { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } @@ -511,7 +516,7 @@ public void innerCloseError(Throwable ex) { drain(); } else { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxMap.java b/reactor-core/src/main/java/reactor/core/publisher/FluxMap.java index a5e4fe436d..abe66feacd 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxMap.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxMap.java @@ -90,7 +90,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -101,7 +101,7 @@ public void onNext(T t) { "The mapper returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -111,7 +111,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -183,7 +183,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -194,7 +194,7 @@ public void onNext(T t) { "The mapper returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -204,7 +204,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -216,7 +216,7 @@ public boolean tryOnNext(T t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -226,7 +226,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxMapFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxMapFuseable.java index 7ccd90e6cf..283c7073a6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxMapFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxMapFuseable.java @@ -98,7 +98,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } R v; @@ -108,7 +108,7 @@ public void onNext(T t) { "The mapper returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -119,7 +119,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -248,7 +248,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -259,7 +259,7 @@ public void onNext(T t) { "The mapper returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -270,7 +270,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -281,7 +281,7 @@ public boolean tryOnNext(T t) { "The mapper returned a null value."); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -291,7 +291,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxMapSignal.java b/reactor-core/src/main/java/reactor/core/publisher/FluxMapSignal.java index 4ab7403186..a30f627efc 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxMapSignal.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxMapSignal.java @@ -123,7 +123,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -139,7 +139,7 @@ public void onNext(T t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -150,7 +150,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -169,7 +169,7 @@ public void onError(Throwable t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -201,7 +201,7 @@ public void onComplete() { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e)); + actual.onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxMaterialize.java b/reactor-core/src/main/java/reactor/core/publisher/FluxMaterialize.java index 69a4b995f6..484951942f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxMaterialize.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxMaterialize.java @@ -92,7 +92,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T ev) { if(terminalSignal != null){ - Operators.onNextDropped(ev); + Operators.onNextDropped(ev, actual.currentContext()); return; } produced++; @@ -102,7 +102,7 @@ public void onNext(T ev) { @Override public void onError(Throwable ev) { if(terminalSignal != null){ - Operators.onErrorDropped(ev); + Operators.onErrorDropped(ev, actual.currentContext()); return; } terminalSignal = Signal.error(ev); diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxMergeSequential.java b/reactor-core/src/main/java/reactor/core/publisher/FluxMergeSequential.java index 2d95d6ff10..f83808995d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxMergeSequential.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxMergeSequential.java @@ -201,7 +201,7 @@ public void onNext(T t) { publisher = Objects.requireNonNull(mapper.apply(t), "publisher"); } catch (Throwable ex) { - onError(Operators.onOperatorError(s, ex, t)); + onError(Operators.onOperatorError(s, ex, t, actual.currentContext())); return; } @@ -219,7 +219,7 @@ public void onNext(T t) { new IllegalStateException("Too many subscribers for " + "fluxMergeSequential on item: " + t + "; subscribers: " + badSize), - t)); + t, actual.currentContext())); return; } @@ -242,7 +242,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -294,7 +294,8 @@ void innerNext(MergeSequentialInner inner, R value) { } else { inner.cancel(); - onError(Operators.onOperatorError(null, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value)); + onError(Operators.onOperatorError(null, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value, + actual.currentContext())); } } @@ -307,7 +308,7 @@ void innerError(MergeSequentialInner inner, Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -396,7 +397,8 @@ void drain() { catch (Throwable ex) { current = null; inner.cancel(); - ex = Operators.onOperatorError(ex); + ex = Operators.onOperatorError(ex, + actual.currentContext()); cancelAll(); a.onError(ex); return; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBuffer.java b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBuffer.java index 149c64770b..637cc324bb 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBuffer.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBuffer.java @@ -142,12 +142,13 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (!queue.offer(t)) { Throwable ex = - Operators.onOperatorError(s, Exceptions.failWithOverflow(), t); + Operators.onOperatorError(s, Exceptions.failWithOverflow(), t, + actual.currentContext()); if (onOverflow != null) { try { onOverflow.accept(t); @@ -166,7 +167,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } error = t; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferStrategy.java b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferStrategy.java index 207f95dd35..7bc5a7bacd 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferStrategy.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferStrategy.java @@ -132,7 +132,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -166,14 +166,16 @@ public void onNext(T t) { onOverflow.accept(overflowElement); } catch (Throwable e) { - Throwable ex = Operators.onOperatorError(s, e, overflowElement); + Throwable ex = Operators.onOperatorError(s, e, overflowElement, + actual.currentContext()); onError(ex); return; } } if (callOnError) { - Throwable ex = Operators.onOperatorError(s, Exceptions.failWithOverflow(), overflowElement); + Throwable ex = Operators.onOperatorError(s, Exceptions.failWithOverflow(), overflowElement, + actual.currentContext()); onError(ex); } @@ -185,7 +187,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } error = t; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferTimeout.java b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferTimeout.java index 7dc2c2146f..8d451a4f1c 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferTimeout.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureBufferTimeout.java @@ -222,7 +222,8 @@ public void onNext(T t) { } catch (RejectedExecutionException re) { done = true; - error = Operators.onRejectedExecution(re, this, null, t); + error = Operators.onRejectedExecution(re, this, null, t, + actual.currentContext()); } drain(); } @@ -289,7 +290,7 @@ void evict(@Nullable T evicted) { evicted, ex); } - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureDrop.java b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureDrop.java index e3db649aca..b8342757dd 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureDrop.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxOnBackpressureDrop.java @@ -110,7 +110,7 @@ public void onNext(T t) { onDrop.accept(t); } catch (Throwable e) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } return; } @@ -128,7 +128,7 @@ public void onNext(T t) { onDrop.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); } } } @@ -136,7 +136,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxOnErrorResume.java b/reactor-core/src/main/java/reactor/core/publisher/FluxOnErrorResume.java index 22c7f6182a..12d730c839 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxOnErrorResume.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxOnErrorResume.java @@ -88,7 +88,7 @@ public void onError(Throwable t) { "The nextFactory returned a null Publisher"); } catch (Throwable e) { - Throwable _e = Operators.onOperatorError(e); + Throwable _e = Operators.onOperatorError(e, actual.currentContext()); if (t != _e) { _e.addSuppressed(t); } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxPeek.java b/reactor-core/src/main/java/reactor/core/publisher/FluxPeek.java index 0e810fb858..e5c486b16e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxPeek.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxPeek.java @@ -124,7 +124,7 @@ public void request(long n) { requestHook.accept(n); } catch (Throwable e) { - Operators.onOperatorError(e); + Operators.onOperatorError(e, actual.currentContext()); } } s.request(n); @@ -138,7 +138,7 @@ public void cancel() { cancelHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -154,7 +154,8 @@ public void onSubscribe(Subscription s) { subscribeHook.accept(s); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(s, e)); + Operators.error(actual, Operators.onOperatorError(s, e, + actual.currentContext())); return; } } @@ -166,7 +167,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -176,7 +177,7 @@ public void onNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } } @@ -187,7 +188,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -198,7 +199,7 @@ public void onError(Throwable t) { } catch (Throwable e) { //this performs a throwIfFatal or suppresses t in e - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } } @@ -219,7 +220,7 @@ public void onError(Throwable t) { afterTerminateHook.run(); } catch (Throwable e) { - afterErrorWithFailure(parent, e, t); + afterErrorWithFailure(parent, e, t, actual.currentContext()); } } } @@ -235,7 +236,7 @@ public void onComplete() { completeHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -249,7 +250,7 @@ public void onComplete() { afterTerminateHook.run(); } catch (Throwable e) { - afterCompleteWithFailure(parent, e); + afterCompleteWithFailure(parent, e, actual.currentContext()); } } } @@ -308,21 +309,22 @@ public Runnable onCancelCall() { * callback that fails during onComplete. It drops the error to the global hook. *

    *
  • The callback failure is thrown immediately if fatal.
  • - *
  • {@link Operators#onOperatorError(Throwable)} is called
  • - *
  • {@link Operators#onErrorDropped(Throwable)} is called
  • + *
  • {@link Operators#onOperatorError(Throwable, Context)} is called
  • + *
  • {@link Operators#onErrorDropped(Throwable, Context)} is called
  • *
*

* * @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 void afterCompleteWithFailure(SignalPeek parent, - Throwable callbackFailure) { + Throwable callbackFailure, Context context) { Exceptions.throwIfFatal(callbackFailure); - Throwable _e = Operators.onOperatorError(callbackFailure); - Operators.onErrorDropped(_e); + Throwable _e = Operators.onOperatorError(callbackFailure, context); + Operators.onErrorDropped(_e, context); } /** @@ -330,22 +332,23 @@ static void afterCompleteWithFailure(SignalPeek parent, * callback that fails during onError. It drops the error to the global hook. *

    *
  • The callback failure is thrown immediately if fatal.
  • - *
  • {@link Operators#onOperatorError(Subscription, Throwable, Object)} is + *
  • {@link Operators#onOperatorError(Subscription, Throwable, Object, Context)} is * called, adding the original error as suppressed
  • - *
  • {@link Operators#onErrorDropped(Throwable)} is called
  • + *
  • {@link Operators#onErrorDropped(Throwable, Context)} is called
  • *
*

* * @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 void afterErrorWithFailure(SignalPeek parent, - Throwable callbackFailure, Throwable originalError) { + Throwable callbackFailure, Throwable originalError, Context context) { Exceptions.throwIfFatal(callbackFailure); - Throwable _e = Operators.onOperatorError(null, callbackFailure, originalError); - Operators.onErrorDropped(_e); + Throwable _e = Operators.onOperatorError(null, callbackFailure, originalError, context); + Operators.onErrorDropped(_e, context); } } \ No newline at end of file diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxPeekFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxPeekFuseable.java index 9c2899a120..735140db3e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxPeekFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxPeekFuseable.java @@ -132,7 +132,7 @@ public void request(long n) { requestHook.accept(n); } catch (Throwable e) { - Operators.onOperatorError(e); + Operators.onOperatorError(e, actual.currentContext()); } } s.request(n); @@ -146,7 +146,7 @@ public void cancel() { cancelHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -163,7 +163,8 @@ public void onSubscribe(Subscription s) { subscribeHook.accept(s); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(s, e)); + Operators.error(actual, Operators.onOperatorError(s, e, + actual.currentContext())); return; } } @@ -179,7 +180,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -189,7 +190,8 @@ public void onNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, + actual.currentContext())); return; } } @@ -200,7 +202,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -212,7 +214,7 @@ public void onError(Throwable t) { } catch (Throwable e) { //this performs a throwIfFatal or suppresses t in e - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } } @@ -232,7 +234,7 @@ public void onError(Throwable t) { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterErrorWithFailure(parent, e, t); + FluxPeek.afterErrorWithFailure(parent, e, t, actual.currentContext()); } } } @@ -254,7 +256,7 @@ public void onComplete() { completeHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -268,7 +270,7 @@ public void onComplete() { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterCompleteWithFailure(parent, e); + FluxPeek.afterCompleteWithFailure(parent, e, actual.currentContext()); } } } @@ -294,10 +296,12 @@ public T poll() { errorHook.accept(e); } catch (Throwable errorCallbackError) { - throw Exceptions.propagate(Operators.onOperatorError(s, errorCallbackError, e)); + throw Exceptions.propagate(Operators.onOperatorError(s, errorCallbackError, e, + actual.currentContext())); } } - throw Exceptions.propagate(Operators.onOperatorError(s, e)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, + actual.currentContext())); } final Consumer nextHook = parent.onNextCall(); @@ -306,7 +310,8 @@ public T poll() { nextHook.accept(v); } catch (Throwable e) { - throw Exceptions.propagate(Operators.onOperatorError(s, e, v)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, v, + actual.currentContext())); } } if (v == null && (d || sourceMode == SYNC)) { @@ -398,7 +403,7 @@ public void request(long n) { requestHook.accept(n); } catch (Throwable e) { - Operators.onOperatorError(e); + Operators.onOperatorError(e, actual.currentContext()); } } s.request(n); @@ -412,7 +417,7 @@ public void cancel() { cancelHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -429,7 +434,8 @@ public void onSubscribe(Subscription s) { subscribeHook.accept(s); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(s, e)); + Operators.error(actual, Operators.onOperatorError(s, e, + actual.currentContext())); return; } } @@ -445,7 +451,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -455,7 +461,8 @@ public void onNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, + actual.currentContext())); return; } } @@ -466,7 +473,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -476,7 +483,7 @@ public boolean tryOnNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } } @@ -486,7 +493,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -498,7 +505,7 @@ public void onError(Throwable t) { } catch (Throwable e) { //this performs a throwIfFatal or suppresses t in e - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } } @@ -518,7 +525,7 @@ public void onError(Throwable t) { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterErrorWithFailure(parent, e, t); + FluxPeek.afterErrorWithFailure(parent, e, t, actual.currentContext()); } } } @@ -540,7 +547,7 @@ public void onComplete() { completeHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -553,7 +560,7 @@ public void onComplete() { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterCompleteWithFailure(parent, e); + FluxPeek.afterCompleteWithFailure(parent, e, actual.currentContext()); } } } @@ -579,10 +586,12 @@ public T poll() { errorHook.accept(e); } catch (Throwable errorCallbackError) { - throw Exceptions.propagate(Operators.onOperatorError(s, errorCallbackError, e)); + throw Exceptions.propagate(Operators.onOperatorError(s, errorCallbackError, e, + actual.currentContext())); } } - throw Exceptions.propagate(Operators.onOperatorError(s, e)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, + actual.currentContext())); } final Consumer nextHook = parent.onNextCall(); @@ -591,7 +600,8 @@ public T poll() { nextHook.accept(v); } catch (Throwable e) { - throw Exceptions.propagate(Operators.onOperatorError(s, e, v)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, v, + actual.currentContext())); } } if (v == null && (d || sourceMode == SYNC)) { @@ -712,7 +722,7 @@ public void request(long n) { requestHook.accept(n); } catch (Throwable e) { - Operators.onOperatorError(e); + Operators.onOperatorError(e, actual.currentContext()); } } s.request(n); @@ -726,7 +736,7 @@ public void cancel() { cancelHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -742,7 +752,8 @@ public void onSubscribe(Subscription s) { subscribeHook.accept(s); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(s, e)); + Operators.error(actual, Operators.onOperatorError(s, e, + actual.currentContext())); return; } } @@ -763,7 +774,7 @@ public Object scanUnsafe(Attr key) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -773,7 +784,7 @@ public void onNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } } @@ -783,7 +794,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } @@ -793,7 +804,7 @@ public boolean tryOnNext(T t) { nextHook.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } } @@ -803,7 +814,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -815,7 +826,7 @@ public void onError(Throwable t) { } catch (Throwable e) { //this performs a throwIfFatal or suppresses t in e - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } } @@ -835,7 +846,7 @@ public void onError(Throwable t) { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterErrorWithFailure(parent, e, t); + FluxPeek.afterErrorWithFailure(parent, e, t, actual.currentContext()); } } } @@ -851,7 +862,7 @@ public void onComplete() { completeHook.run(); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -865,7 +876,7 @@ public void onComplete() { afterTerminateHook.run(); } catch (Throwable e) { - FluxPeek.afterCompleteWithFailure(parent, e); + FluxPeek.afterCompleteWithFailure(parent, e, actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxPublish.java b/reactor-core/src/main/java/reactor/core/publisher/FluxPublish.java index 3542bd26b3..3c107d2578 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxPublish.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxPublish.java @@ -242,7 +242,7 @@ else if (m == Fuseable.ASYNC) { public void onNext(T t) { if (done) { if (t != null) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); } return; } @@ -253,10 +253,9 @@ public void onNext(T t) { if (!queue.offer(t)) { Throwable ex = Operators.onOperatorError(s, - Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), - t); + Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, currentContext()); if (!Exceptions.addThrowable(ERROR, this, ex)) { - Operators.onErrorDropped(ex); + Operators.onErrorDroppedMulticast(ex); return; } done = true; @@ -267,7 +266,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDroppedMulticast(t); return; } if (Exceptions.addThrowable(ERROR, this, t)) { @@ -275,7 +274,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDroppedMulticast(t); } } @@ -414,7 +413,7 @@ final void drain() { catch (Throwable ex) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(s, ex)); + Operators.onOperatorError(s, ex, currentContext())); d = true; v = null; } @@ -439,7 +438,7 @@ final void drain() { catch (Throwable ex) { Exceptions.addThrowable(ERROR, this, - Operators.onOperatorError(s, ex)); + Operators.onOperatorError(s, ex, currentContext())); d = true; v = null; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxPublishMulticast.java b/reactor-core/src/main/java/reactor/core/publisher/FluxPublishMulticast.java index 692dfde1e1..b233190189 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxPublishMulticast.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxPublishMulticast.java @@ -83,7 +83,7 @@ public void subscribe(CoreSubscriber actual) { "The transform returned a null Publisher"); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, actual.currentContext())); return; } @@ -248,7 +248,7 @@ else if (m == Fuseable.ASYNC) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, context); return; } @@ -256,7 +256,7 @@ public void onNext(T t) { if (!queue.offer(t)) { onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), - t)); + t, context)); return; } } @@ -266,7 +266,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, context); return; } error = t; @@ -334,7 +334,7 @@ void drainSync() { v = queue.poll(); } catch (Throwable ex) { - error = Operators.onOperatorError(s, ex); + error = Operators.onOperatorError(s, ex, context); queue.clear(); a = SUBSCRIBERS.getAndSet(this, TERMINATED); n = a.length; @@ -432,7 +432,7 @@ void drainAsync() { } catch (Throwable ex) { queue.clear(); - error = Operators.onOperatorError(s, ex); + error = Operators.onOperatorError(s, ex, context); a = SUBSCRIBERS.getAndSet(this, TERMINATED); n = a.length; for (int i = 0; i < n; i++) { @@ -726,7 +726,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if(!parent.terminate()){ - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } actual.onError(t); @@ -825,7 +825,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if(!parent.terminate()){ - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } actual.onError(t); diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxPublishOn.java b/reactor-core/src/main/java/reactor/core/publisher/FluxPublishOn.java index cc4048cba7..3459287ebe 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxPublishOn.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxPublishOn.java @@ -79,7 +79,7 @@ public void subscribe(CoreSubscriber actual) { "The scheduler returned a null worker"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -220,13 +220,13 @@ public void onNext(T t) { } if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (!queue.offer(t)) { error = Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), - t); + t, actual.currentContext()); done = true; } trySchedule(this, null, t); @@ -235,7 +235,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } error = t; @@ -290,7 +290,8 @@ void trySchedule( } catch (RejectedExecutionException ree) { queue.clear(); - actual.onError(Operators.onRejectedExecution(ree, subscription, suppressed, dataSignal)); + actual.onError(Operators.onRejectedExecution(ree, subscription, suppressed, dataSignal, + actual.currentContext())); } } @@ -313,7 +314,8 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { - doError(a, Operators.onOperatorError(s, ex)); + doError(a, Operators.onOperatorError(s, ex, + actual.currentContext())); return; } @@ -377,7 +379,7 @@ void runAsync() { s.cancel(); q.clear(); - doError(a, Operators.onOperatorError(ex)); + doError(a, Operators.onOperatorError(ex, actual.currentContext())); return; } @@ -699,11 +701,12 @@ public void onNext(T t) { } if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (!queue.offer(t)) { - error = Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t); + error = Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + actual.currentContext()); done = true; } trySchedule(this, null, t); @@ -712,7 +715,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if(done){ - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } error = t; @@ -765,7 +768,8 @@ void trySchedule( } catch (RejectedExecutionException ree) { queue.clear(); - actual.onError(Operators.onRejectedExecution(ree, subscription, suppressed, dataSignal)); + actual.onError(Operators.onRejectedExecution(ree, subscription, suppressed, dataSignal, + actual.currentContext())); } } @@ -787,7 +791,8 @@ void runSync() { v = q.poll(); } catch (Throwable ex) { - doError(a, Operators.onOperatorError(s, ex)); + doError(a, Operators.onOperatorError(s, ex, + actual.currentContext())); return; } @@ -851,7 +856,7 @@ void runAsync() { s.cancel(); q.clear(); - doError(a, Operators.onOperatorError(ex)); + doError(a, Operators.onOperatorError(ex, actual.currentContext())); return; } boolean empty = v == null; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatPredicate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatPredicate.java index e6a713e817..77caea275a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatPredicate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatPredicate.java @@ -85,7 +85,7 @@ public void onComplete() { try { b = predicate.getAsBoolean(); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatWhen.java b/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatWhen.java index 6b61fb3c2f..579176e787 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxRepeatWhen.java @@ -74,7 +74,7 @@ public void subscribe(CoreSubscriber actual) { "The whenSourceFactory returned a null Publisher"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java index f6809126c7..edef02f606 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java @@ -1151,7 +1151,7 @@ else if (Operators.setOnce(S, this, s)) { public void onNext(T t) { ReplayBuffer b = buffer; if (b.isDone()) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); } else { b.add(t); @@ -1165,7 +1165,7 @@ public void onNext(T t) { public void onError(Throwable t) { ReplayBuffer b = buffer; if (b.isDone()) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); } else { b.onError(t); diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxRetryPredicate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxRetryPredicate.java index 3fe35bec25..856391a31a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxRetryPredicate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxRetryPredicate.java @@ -87,7 +87,7 @@ public void onError(Throwable t) { try { b = predicate.test(t); } catch (Throwable e) { - Throwable _t = Operators.onOperatorError(e); + Throwable _t = Operators.onOperatorError(e, actual.currentContext()); if (_t != t) { _t.addSuppressed(t); } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxRetryWhen.java b/reactor-core/src/main/java/reactor/core/publisher/FluxRetryWhen.java index aa8253ba47..7f8dd0d7d5 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxRetryWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxRetryWhen.java @@ -71,7 +71,7 @@ static void subscribe(CoreSubscriber s, Function m = main; if (m.gate) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, main.currentContext()); return; } m.onError(t); @@ -217,7 +217,7 @@ public void onError(Throwable t) { return; } else if (main == Operators.cancelledSubscription()){ - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } cancel(); diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSkipWhile.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSkipWhile.java index 3763f14f93..8b990a304e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxSkipWhile.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSkipWhile.java @@ -72,7 +72,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -86,7 +86,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -102,7 +102,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -116,7 +116,7 @@ public boolean tryOnNext(T t) { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return true; } @@ -133,7 +133,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxStream.java b/reactor-core/src/main/java/reactor/core/publisher/FluxStream.java index ee4b9e7c70..c83c243437 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxStream.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxStream.java @@ -47,7 +47,7 @@ public void subscribe(CoreSubscriber actual) { "The stream returned a null Iterator"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOn.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOn.java index 5167a75af6..43d415eef5 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOn.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOn.java @@ -57,7 +57,7 @@ public void subscribe(CoreSubscriber actual) { worker = Objects.requireNonNull(scheduler.createWorker(), "The scheduler returned a null Function"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -70,7 +70,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if (parent.s != Operators.cancelledSubscription()) { - actual.onError(Operators.onRejectedExecution(ree, parent, null, null)); + actual.onError(Operators.onRejectedExecution(ree, parent, null, null, + actual.currentContext())); } } } @@ -138,7 +139,8 @@ void requestUpstream(final long n, final Subscription s) { //FIXME should not throw but if we implement strict // serialization like in StrictSubscriber, onNext will carry an // extra cost - throw Operators.onRejectedExecution(ree, this, null, null); + throw Operators.onRejectedExecution(ree, this, null, null, + actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnCallable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnCallable.java index 9807ebec7b..ca5fe19871 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnCallable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnCallable.java @@ -57,7 +57,7 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if(parent.state != CallableSubscribeOnSubscription.HAS_CANCELLED) { - actual.onError(Operators.onRejectedExecution(ree)); + actual.onError(Operators.onRejectedExecution(ree, actual.currentContext())); } } } @@ -216,7 +216,8 @@ public void run() { v = callable.call(); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(this, ex)); + actual.onError(Operators.onOperatorError(this, ex, + actual.currentContext())); return; } @@ -262,7 +263,8 @@ public void request(long n) { setRequestFuture(f); } catch (RejectedExecutionException ree) { - actual.onError(Operators.onRejectedExecution(ree)); + actual.onError(Operators.onRejectedExecution(ree, + actual.currentContext())); } } return; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnValue.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnValue.java index 78fd43fb2e..b8e1cfcbf9 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnValue.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSubscribeOnValue.java @@ -59,7 +59,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if (parent.future != OperatorDisposables.DISPOSED) { - actual.onError(Operators.onRejectedExecution(ree)); + actual.onError(Operators.onRejectedExecution(ree, + actual.currentContext())); } } } @@ -141,7 +142,7 @@ public void request(long n) { actual.onError(Operators.onRejectedExecution(ree, this, null, - value)); + value, actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMap.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMap.java index 44e02658d5..58a6fd9f58 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMap.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMap.java @@ -196,7 +196,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -215,7 +215,7 @@ public void onNext(T t) { "The mapper returned a null publisher"); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -231,7 +231,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } @@ -246,7 +246,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -415,7 +415,7 @@ void innerError(SwitchMapInner inner, Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxTake.java b/reactor-core/src/main/java/reactor/core/publisher/FluxTake.java index 1af1a72281..a4e4038232 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxTake.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxTake.java @@ -100,7 +100,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -127,7 +127,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -217,7 +217,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -244,7 +244,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return true; } @@ -272,7 +272,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -372,7 +372,7 @@ public void onNext(T t) { return; } if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -399,7 +399,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxTakeUntil.java b/reactor-core/src/main/java/reactor/core/publisher/FluxTakeUntil.java index c2922926de..93eda06550 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxTakeUntil.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxTakeUntil.java @@ -70,7 +70,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -81,7 +81,7 @@ public void onNext(T t) { try { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -96,7 +96,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxTakeWhile.java b/reactor-core/src/main/java/reactor/core/publisher/FluxTakeWhile.java index 096861a21a..e099781e21 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxTakeWhile.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxTakeWhile.java @@ -69,7 +69,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -78,7 +78,7 @@ public void onNext(T t) { try { b = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -97,7 +97,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxTimeout.java b/reactor-core/src/main/java/reactor/core/publisher/FluxTimeout.java index 374fedd1ca..46cf982585 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxTimeout.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxTimeout.java @@ -133,12 +133,12 @@ public void onNext(T t) { long idx = index; if (idx == Long.MIN_VALUE) { s.cancel(); - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } if (!INDEX.compareAndSet(this, idx, idx + 1)) { s.cancel(); - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -153,7 +153,8 @@ public void onNext(T t) { "The itemTimeout returned a null Publisher"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(this, e, t)); + actual.onError(Operators.onOperatorError(this, e, t, + actual.currentContext())); return; } @@ -170,11 +171,11 @@ public void onNext(T t) { public void onError(Throwable t) { long idx = index; if (idx == Long.MIN_VALUE) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } if (!INDEX.compareAndSet(this, idx, Long.MIN_VALUE)) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxUsing.java b/reactor-core/src/main/java/reactor/core/publisher/FluxUsing.java index 7626593a70..86509f9bb3 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxUsing.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxUsing.java @@ -74,7 +74,7 @@ public void subscribe(CoreSubscriber actual) { resource = resourceSupplier.call(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -90,11 +90,11 @@ public void subscribe(CoreSubscriber actual) { resourceCleanup.accept(resource); } catch (Throwable ex) { - ex.addSuppressed(Operators.onOperatorError(e)); + ex.addSuppressed(Operators.onOperatorError(e, actual.currentContext())); e = ex; } - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -177,7 +177,7 @@ void cleanup() { resourceCleanup.accept(resource); } catch (Throwable e) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -202,7 +202,7 @@ public void onError(Throwable t) { resourceCleanup.accept(resource); } catch (Throwable e) { - Throwable _e = Operators.onOperatorError(e); + Throwable _e = Operators.onOperatorError(e, actual.currentContext()); if (_e != t) { _e.addSuppressed(t); } @@ -224,7 +224,7 @@ public void onComplete() { resourceCleanup.accept(resource); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } } @@ -329,7 +329,7 @@ void cleanup() { resourceCleanup.accept(resource); } catch (Throwable e) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -355,7 +355,7 @@ public void onError(Throwable t) { resourceCleanup.accept(resource); } catch (Throwable e) { - Throwable _e = Operators.onOperatorError(e); + Throwable _e = Operators.onOperatorError(e, actual.currentContext()); if (_e != t) { _e.addSuppressed(t); } @@ -377,7 +377,7 @@ public void onComplete() { resourceCleanup.accept(resource); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } } @@ -489,7 +489,7 @@ void cleanup() { resourceCleanup.accept(resource); } catch (Throwable e) { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -519,7 +519,7 @@ public void onError(Throwable t) { resourceCleanup.accept(resource); } catch (Throwable e) { - Throwable _e = Operators.onOperatorError(e); + Throwable _e = Operators.onOperatorError(e, actual.currentContext()); if (_e != t) { _e.addSuppressed(t); } @@ -541,7 +541,7 @@ public void onComplete() { resourceCleanup.accept(resource); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWindow.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWindow.java index dd3baf55af..3884cbefa8 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWindow.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWindow.java @@ -148,7 +148,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -181,7 +181,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -315,7 +315,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -355,7 +355,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -517,7 +517,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -566,7 +566,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowBoundary.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowBoundary.java index 996af5ae4a..ff2639a135 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowBoundary.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowBoundary.java @@ -172,7 +172,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } synchronized (this) { @@ -184,7 +184,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -255,7 +255,7 @@ void boundaryError(Throwable e) { if (Exceptions.addThrowable(ERROR, this, e)) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowPredicate.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowPredicate.java index c1fdb10c96..4397657c08 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowPredicate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowPredicate.java @@ -202,7 +202,8 @@ void offerNewWindow(@Nullable T emitInNewWindow) { window = g; if (!queue.offer(g)) { - onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), emitInNewWindow)); + onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), emitInNewWindow, + actual.currentContext())); return; } drain(); @@ -212,7 +213,7 @@ void offerNewWindow(@Nullable T emitInNewWindow) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } WindowFlux g = window; @@ -222,7 +223,7 @@ public void onNext(T t) { match = predicate.test(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -253,7 +254,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -705,7 +706,8 @@ public void onNext(T t) { Subscriber a = actual; if (!queue.offer(t)) { - onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + actual.currentContext())); return; } if (enableOperatorFusion) { diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowTimeOrSize.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowTimeOrSize.java index 508f319b1c..527cafb65e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowTimeOrSize.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowTimeOrSize.java @@ -194,7 +194,8 @@ void subscribeAndCreateWindow() { //or the first emission, which will follow the subscribe } catch (RejectedExecutionException ree) { - RuntimeException error = Operators.onRejectedExecution(ree, subscription, null, null); + RuntimeException error = Operators.onRejectedExecution(ree, subscription, null, null, + actual.currentContext()); Operators.error(actual, error); } } @@ -235,7 +236,7 @@ boolean timerStart() { return true; } catch (RejectedExecutionException ree) { - onError(Operators.onRejectedExecution(ree)); + onError(Operators.onRejectedExecution(ree, actual.currentContext())); return false; } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowWhen.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowWhen.java index 74ec1bdd46..acd262c66c 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWindowWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWindowWhen.java @@ -195,7 +195,7 @@ public void onError(Throwable t) { drain(); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); } } @@ -237,7 +237,7 @@ void starterError(Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -262,7 +262,7 @@ void endError(Throwable e) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -402,7 +402,7 @@ else if (windowCount == 0) { this, Operators.onOperatorError(s, ex, - newWindow.value)); + newWindow.value, actual.currentContext())); continue; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxWithLatestFrom.java b/reactor-core/src/main/java/reactor/core/publisher/FluxWithLatestFrom.java index cf13c19edd..a2447b696e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxWithLatestFrom.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxWithLatestFrom.java @@ -187,7 +187,7 @@ public void onNext(T t) { "The combiner returned a null value"); } catch (Throwable e) { - onError(Operators.onOperatorError(this, e, t)); + onError(Operators.onOperatorError(this, e, t, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxZip.java b/reactor-core/src/main/java/reactor/core/publisher/FluxZip.java index 1f1e367ca9..37b28752e3 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxZip.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxZip.java @@ -153,7 +153,8 @@ void handleIterableMode(CoreSubscriber s, if (p == null) { Operators.error(s, Operators.onOperatorError(new NullPointerException( - "The sourcesIterable returned a null Publisher"))); + "The sourcesIterable returned a null Publisher"), + s.currentContext())); return; } @@ -166,7 +167,8 @@ void handleIterableMode(CoreSubscriber s, v = callable.call(); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(e)); + Operators.error(s, Operators.onOperatorError(e, + s.currentContext())); return; } @@ -243,7 +245,8 @@ void handleArrayMode(CoreSubscriber s, Publisher[] srcs) v = ((Callable) p).call(); } catch (Throwable e) { - Operators.error(s, Operators.onOperatorError(e)); + Operators.error(s, Operators.onOperatorError(e, + s.currentContext())); return; } @@ -306,7 +309,7 @@ void handleBoth(CoreSubscriber s, "The zipper returned a null value"); } catch (Throwable e) { - s.onError(Operators.onOperatorError(e)); + s.onError(Operators.onOperatorError(e, s.currentContext())); return; } @@ -379,7 +382,8 @@ void next(T value, int index) { "The zipper returned a null value"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(this, e, value)); + actual.onError(Operators.onOperatorError(this, e, value, + actual.currentContext())); return; } @@ -393,7 +397,7 @@ void error(Throwable e, int index) { actual.onError(e); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -482,7 +486,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, parent.currentContext()); return; } done = true; @@ -493,7 +497,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, parent.currentContext()); return; } done = true; @@ -612,7 +616,7 @@ void error(Throwable e, int index) { drain(); } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } @@ -682,7 +686,8 @@ void drain() { } } catch (Throwable ex) { - ex = Operators.onOperatorError(ex); + ex = Operators.onOperatorError(ex, + actual.currentContext()); cancelAll(); @@ -708,7 +713,8 @@ void drain() { } catch (Throwable ex) { - ex = Operators.onOperatorError(null, ex, values.clone()); + ex = Operators.onOperatorError(null, ex, values.clone(), + actual.currentContext()); cancelAll(); Exceptions.addThrowable(ERROR, this, ex); @@ -762,7 +768,8 @@ void drain() { } } catch (Throwable ex) { - ex = Operators.onOperatorError(null, ex, values); + ex = Operators.onOperatorError(null, ex, values, + actual.currentContext()); cancelAll(); @@ -873,7 +880,8 @@ else if (m == ASYNC) { public void onNext(T t) { if (sourceMode != ASYNC) { if (!queue.offer(t)) { - onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(s, Exceptions.failWithOverflow + (Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), currentContext())); return; } } @@ -888,7 +896,7 @@ public Context currentContext() { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxZipIterable.java b/reactor-core/src/main/java/reactor/core/publisher/FluxZipIterable.java index 8952ba53f2..75db019afb 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/FluxZipIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/FluxZipIterable.java @@ -56,7 +56,7 @@ public void subscribe(CoreSubscriber actual) { "The other iterable produced a null iterator"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -66,7 +66,7 @@ public void subscribe(CoreSubscriber actual) { b = it.hasNext(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -119,7 +119,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -130,7 +130,7 @@ public void onNext(T t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -142,7 +142,7 @@ public void onNext(T t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -155,7 +155,7 @@ public void onNext(T t) { } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } @@ -169,7 +169,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/LambdaMonoSubscriber.java b/reactor-core/src/main/java/reactor/core/publisher/LambdaMonoSubscriber.java index 4ee8734fcf..25febc4a75 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/LambdaMonoSubscriber.java +++ b/reactor-core/src/main/java/reactor/core/publisher/LambdaMonoSubscriber.java @@ -24,6 +24,7 @@ import org.reactivestreams.Subscription; import reactor.core.Disposable; import reactor.core.Exceptions; +import reactor.util.context.Context; /** * An unbounded Java Lambda adapter to {@link Subscriber}, targetted at {@link Mono}. @@ -100,7 +101,7 @@ public final void onComplete() { completeConsumer.run(); } catch (Throwable t) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); } } } @@ -109,7 +110,7 @@ public final void onComplete() { public final void onError(Throwable t) { Subscription s = S.getAndSet(this, Operators.cancelledSubscription()); if (s == Operators.cancelledSubscription()) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); return; } doError(t); @@ -128,7 +129,7 @@ void doError(Throwable t) { public final void onNext(T x) { Subscription s = S.getAndSet(this, Operators.cancelledSubscription()); if (s == Operators.cancelledSubscription()) { - Operators.onNextDropped(x); + Operators.onNextDropped(x, Context.empty()); return; } if (consumer != null) { @@ -136,7 +137,7 @@ public final void onNext(T x) { consumer.accept(x); } catch (Throwable t) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); return; } } @@ -145,7 +146,7 @@ public final void onNext(T x) { completeConsumer.run(); } catch (Throwable t) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/LambdaSubscriber.java b/reactor-core/src/main/java/reactor/core/publisher/LambdaSubscriber.java index ff3eaa4e1d..d069d4664f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/LambdaSubscriber.java +++ b/reactor-core/src/main/java/reactor/core/publisher/LambdaSubscriber.java @@ -23,6 +23,8 @@ import org.reactivestreams.Subscription; import reactor.core.Disposable; import reactor.core.Exceptions; +import reactor.util.context.Context; + import javax.annotation.Nullable; /** @@ -110,7 +112,7 @@ public final void onComplete() { public final void onError(Throwable t) { Subscription s = S.getAndSet(this, Operators.cancelledSubscription()); if (s == Operators.cancelledSubscription()) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); return; } if (errorConsumer != null) { diff --git a/reactor-core/src/main/java/reactor/core/publisher/Mono.java b/reactor-core/src/main/java/reactor/core/publisher/Mono.java index 03d48c1971..143ed6c49d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/Mono.java +++ b/reactor-core/src/main/java/reactor/core/publisher/Mono.java @@ -2159,7 +2159,7 @@ public final Mono doOnError(Predicate predicate, * Add behavior triggering a {@link LongConsumer} when the {@link Mono} receives any request. *

* Note that non fatal error raised in the callback will not be propagated and - * will simply trigger {@link Operators#onOperatorError(Throwable)}. + * will simply trigger {@link Operators#onOperatorError(Throwable, Context)}. * *

* diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoAll.java b/reactor-core/src/main/java/reactor/core/publisher/MonoAll.java index 415d68c4dd..dec5d2fa89 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoAll.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoAll.java @@ -98,7 +98,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (!b) { @@ -112,7 +112,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoAny.java b/reactor-core/src/main/java/reactor/core/publisher/MonoAny.java index 5f437adae4..30757bf428 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoAny.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoAny.java @@ -99,7 +99,7 @@ public void onNext(T t) { b = predicate.test(t); } catch (Throwable e) { done = true; - actual.onError(Operators.onOperatorError(s, e, t)); + actual.onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return; } if (b) { @@ -113,7 +113,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoCacheTime.java b/reactor-core/src/main/java/reactor/core/publisher/MonoCacheTime.java index a4ef3ab7e3..5e657aea5d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoCacheTime.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoCacheTime.java @@ -114,7 +114,7 @@ static final class CoordinatorSubscriber implements InnerConsumer, Signal< static final AtomicReferenceFieldUpdater SUBSCRIBERS = AtomicReferenceFieldUpdater.newUpdater(CoordinatorSubscriber.class, Operators.MonoSubscriber[].class, "subscribers"); - public CoordinatorSubscriber(MonoCacheTime main) { + CoordinatorSubscriber(MonoCacheTime main) { this.main = main; //noinspection unchecked this.subscribers = EMPTY; @@ -248,7 +248,7 @@ else if (signal.isOnError()) { @Override public void onNext(T t) { if (main.state != this) { - Operators.onNextDropped(t); + Operators.onNextDroppedMulticast(t); return; } signalCached(Signal.next(t)); @@ -257,7 +257,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (main.state != this) { - Operators.onErrorDropped(t); + Operators.onErrorDroppedMulticast(t); return; } signalCached(Signal.error(t)); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoCallable.java b/reactor-core/src/main/java/reactor/core/publisher/MonoCallable.java index 4b702919df..888898c76e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoCallable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoCallable.java @@ -58,7 +58,7 @@ public void subscribe(CoreSubscriber actual) { t = Objects.requireNonNull(callable.call(), "callable returned null"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoCollect.java b/reactor-core/src/main/java/reactor/core/publisher/MonoCollect.java index e2b718a0da..7e612fffa7 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoCollect.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoCollect.java @@ -59,7 +59,7 @@ public void subscribe(CoreSubscriber actual) { "The supplier returned a null container"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -111,7 +111,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -119,14 +119,14 @@ public void onNext(T t) { action.accept(value, t); } catch (Throwable e) { - onError(Operators.onOperatorError(this, e, t)); + onError(Operators.onOperatorError(this, e, t, actual.currentContext())); } } @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoCollectList.java b/reactor-core/src/main/java/reactor/core/publisher/MonoCollectList.java index 57d63fff77..0dc8f08837 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoCollectList.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoCollectList.java @@ -52,7 +52,7 @@ public void subscribe(CoreSubscriber actual) { "The collectionSupplier returned a null collection"); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoCreate.java b/reactor-core/src/main/java/reactor/core/publisher/MonoCreate.java index bacf7831f3..ac7b0bca06 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoCreate.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoCreate.java @@ -53,7 +53,7 @@ public void subscribe(CoreSubscriber actual) { callback.accept(emitter); } catch (Throwable ex) { - emitter.error(Operators.onOperatorError(ex)); + emitter.error(Operators.onOperatorError(ex, actual.currentContext())); } } @@ -163,7 +163,7 @@ public void error(Throwable e) { } } else { - Operators.onErrorDropped(e); + Operators.onErrorDropped(e, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoDefer.java b/reactor-core/src/main/java/reactor/core/publisher/MonoDefer.java index ac626e9342..20e3804500 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoDefer.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoDefer.java @@ -45,7 +45,7 @@ public void subscribe(CoreSubscriber actual) { "The Mono returned by the supplier is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoDelay.java b/reactor-core/src/main/java/reactor/core/publisher/MonoDelay.java index 34575815e0..3b8d25a457 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoDelay.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoDelay.java @@ -58,7 +58,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if(r.cancel != OperatorDisposables.DISPOSED) { - actual.onError(Operators.onRejectedExecution(ree, r, null, null)); + actual.onError(Operators.onRejectedExecution(ree, r, null, null, + actual.currentContext())); } } } @@ -110,7 +111,7 @@ public void run() { } } catch (Throwable t){ - actual.onError(Operators.onOperatorError(t)); + actual.onError(Operators.onOperatorError(t, actual.currentContext())); } } else { actual.onError(Exceptions.failWithOverflow("Could not emit value due to lack of requests")); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoDelayElement.java b/reactor-core/src/main/java/reactor/core/publisher/MonoDelayElement.java index 1a606efe1d..761dcd17ee 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoDelayElement.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoDelayElement.java @@ -107,7 +107,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } this.done = true; @@ -115,7 +115,8 @@ public void onNext(T t) { this.task = scheduler.schedule(() -> complete(t), delay, unit); } catch (RejectedExecutionException ree) { - throw Operators.onRejectedExecution(ree, this, null, t); + throw Operators.onRejectedExecution(ree, this, null, t, + actual.currentContext()); } } @@ -131,7 +132,7 @@ public void onComplete() { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } this.done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinally.java b/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinally.java index 7a07263f14..2f65aae8f6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinally.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinally.java @@ -28,7 +28,7 @@ * {@link SignalType#CANCEL}). *

* Note that any exception thrown by the hook are caught and bubbled up - * using {@link Operators#onErrorDropped(Throwable)}. + * using {@link Operators#onErrorDropped(Throwable, reactor.util.context.Context)}. * * @param the value type * @author Simon Baslé diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinallyFuseable.java b/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinallyFuseable.java index eee57d3b92..afa54d9adb 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinallyFuseable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoDoFinallyFuseable.java @@ -29,7 +29,7 @@ * {@link SignalType#CANCEL}). *

* Note that any exception thrown by the hook are caught and bubbled up - * using {@link Operators#onErrorDropped(Throwable)}. + * using {@link Operators#onErrorDropped(Throwable, reactor.util.context.Context)}. * * @param the value type * @author Simon Baslé diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoElementAt.java b/reactor-core/src/main/java/reactor/core/publisher/MonoElementAt.java index 339611f5f1..ebc67c598b 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoElementAt.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoElementAt.java @@ -111,7 +111,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -130,7 +130,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -150,7 +150,7 @@ public void onComplete() { } else{ actual.onError(Operators.onOperatorError(new - IndexOutOfBoundsException())); + IndexOutOfBoundsException(), actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoError.java b/reactor-core/src/main/java/reactor/core/publisher/MonoError.java index a4c6bee22f..abafd9b357 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoError.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoError.java @@ -49,7 +49,7 @@ public T block() { @Override public void subscribe(CoreSubscriber actual) { - Operators.error(actual, Operators.onOperatorError(error)); + Operators.error(actual, Operators.onOperatorError(error, actual.currentContext())); } @Override diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoFilterWhen.java b/reactor-core/src/main/java/reactor/core/publisher/MonoFilterWhen.java index df5ce92dc1..db415cefa5 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoFilterWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoFilterWhen.java @@ -262,7 +262,7 @@ public void onError(Throwable t) { done = true; main.innerError(t); } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, main.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoFirst.java b/reactor-core/src/main/java/reactor/core/publisher/MonoFirst.java index 53ac8ee183..348c123702 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoFirst.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoFirst.java @@ -77,7 +77,8 @@ public void subscribe(CoreSubscriber actual) { it = Objects.requireNonNull(iterable.iterator(), "The iterator returned is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -89,7 +90,8 @@ public void subscribe(CoreSubscriber actual) { b = it.hasNext(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -104,7 +106,8 @@ public void subscribe(CoreSubscriber actual) { "The Publisher returned by the iterator is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, + actual.currentContext())); return; } @@ -130,7 +133,8 @@ public void subscribe(CoreSubscriber actual) { if (p == null) { Operators.error(actual, - Operators.onOperatorError(new NullPointerException("The single source Publisher is null"))); + Operators.onOperatorError(new NullPointerException("The single source Publisher is null"), + actual.currentContext())); } else { p.subscribe(actual); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMap.java b/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMap.java index b23db67fa6..a8e21f3bab 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMap.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMap.java @@ -107,7 +107,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } done = true; @@ -119,7 +119,8 @@ public void onNext(T t) { "The mapper returned a null Mono"); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(s, ex, t)); + actual.onError(Operators.onOperatorError(s, ex, t, + actual.currentContext())); return; } @@ -131,7 +132,8 @@ public void onNext(T t) { v = c.call(); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(s, ex, t)); + actual.onError(Operators.onOperatorError(s, ex, t, + actual.currentContext())); return; } @@ -148,14 +150,15 @@ public void onNext(T t) { m.subscribe(second); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(this, e, t)); + actual.onError(Operators.onOperatorError(this, e, t, + actual.currentContext())); } } @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -231,7 +234,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(R t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, parent.currentContext()); return; } done = true; @@ -241,7 +244,7 @@ public void onNext(R t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, parent.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMapMany.java b/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMapMany.java index 8e7198f0e7..be48079c1d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMapMany.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoFlatMapMany.java @@ -154,7 +154,8 @@ public void onNext(T t) { "The mapper returned a null Publisher."); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(this, ex, t)); + actual.onError(Operators.onOperatorError(this, ex, t, + actual.currentContext())); return; } @@ -165,7 +166,8 @@ public void onNext(T t) { v = ((Callable) p).call(); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(this, ex, t)); + actual.onError(Operators.onOperatorError(this, ex, t, + actual.currentContext())); return; } @@ -185,7 +187,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (hasValue) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } actual.onError(t); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoFlattenIterable.java b/reactor-core/src/main/java/reactor/core/publisher/MonoFlattenIterable.java index 9b03faded3..2ef46df788 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoFlattenIterable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoFlattenIterable.java @@ -71,7 +71,8 @@ public void subscribe(CoreSubscriber actual) { v = ((Callable) source).call(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -88,7 +89,8 @@ public void subscribe(CoreSubscriber actual) { it = iter.iterator(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, + actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoIgnoreThen.java b/reactor-core/src/main/java/reactor/core/publisher/MonoIgnoreThen.java index c2dcc65aac..3615db7a85 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoIgnoreThen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoIgnoreThen.java @@ -130,7 +130,8 @@ void drain() { v = ((Callable)m).call(); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(ex)); + actual.onError(Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -154,7 +155,8 @@ void drain() { ((Callable)m).call(); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(ex)); + actual.onError(Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -281,7 +283,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, parent.currentContext()); return; } done = true; @@ -291,7 +293,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, parent.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoNext.java b/reactor-core/src/main/java/reactor/core/publisher/MonoNext.java index acb23f9ecf..029cffc5d1 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoNext.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoNext.java @@ -68,7 +68,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -80,7 +80,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoPeekTerminal.java b/reactor-core/src/main/java/reactor/core/publisher/MonoPeekTerminal.java index ec258ed8cf..05687e0716 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoPeekTerminal.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoPeekTerminal.java @@ -154,7 +154,7 @@ public void onNext(T t) { } else { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } //implementation note: this operator doesn't expect the source to be anything but a Mono @@ -166,7 +166,8 @@ public void onNext(T t) { parent.onTerminateCall.accept(t, null); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, + actual.currentContext())); return; } } @@ -175,7 +176,8 @@ public void onNext(T t) { parent.onSuccessCall.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, + actual.currentContext())); return; } } @@ -188,7 +190,9 @@ public void onNext(T t) { } catch (Throwable e) { //don't invoke error callback, see https://github.com/reactor/reactor-core/issues/270 - Operators.onErrorDropped(Operators.onOperatorError(s, e, t)); + Operators.onErrorDropped(Operators.onOperatorError(s, e, t, + actual.currentContext()), + actual.currentContext()); } } } @@ -197,7 +201,7 @@ public void onNext(T t) { @Override public boolean tryOnNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return false; } if (actualConditional == null) { @@ -214,7 +218,7 @@ public boolean tryOnNext(T t) { parent.onTerminateCall.accept(t, null); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } } @@ -223,7 +227,7 @@ public boolean tryOnNext(T t) { parent.onSuccessCall.accept(t); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e, t)); + onError(Operators.onOperatorError(s, e, t, actual.currentContext())); return false; } } @@ -236,7 +240,9 @@ public boolean tryOnNext(T t) { } catch (Throwable e) { //don't invoke error callback, see https://github.com/reactor/reactor-core/issues/270 - Operators.onErrorDropped(Operators.onOperatorError(s, e, t)); + Operators.onErrorDropped(Operators.onOperatorError(s, e, t, + actual.currentContext()), + actual.currentContext()); } } @@ -246,7 +252,7 @@ public boolean tryOnNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -256,7 +262,7 @@ public void onError(Throwable t) { parent.onTerminateCall.accept(null, t); } catch (Throwable e) { - t = Operators.onOperatorError(null, e, t); + t = Operators.onOperatorError(null, e, t, actual.currentContext()); } } @@ -275,7 +281,9 @@ public void onError(Throwable t) { } catch (Throwable e) { //don't invoke error callback, see https://github.com/reactor/reactor-core/issues/270 - Operators.onErrorDropped(Operators.onOperatorError(e)); + Operators.onErrorDropped(Operators.onOperatorError(e, + actual.currentContext()), + actual.currentContext()); } } } @@ -291,7 +299,7 @@ public void onComplete() { parent.onTerminateCall.accept(null, null); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -300,7 +308,7 @@ public void onComplete() { parent.onSuccessCall.accept(null); } catch (Throwable e) { - onError(Operators.onOperatorError(s, e)); + onError(Operators.onOperatorError(s, e, actual.currentContext())); return; } } @@ -315,7 +323,9 @@ public void onComplete() { } catch (Throwable e) { //don't invoke error callback, see https://github.com/reactor/reactor-core/issues/270 - Operators.onErrorDropped(Operators.onOperatorError(e)); + Operators.onErrorDropped(Operators.onOperatorError(e, + actual.currentContext()), + actual.currentContext()); } } } @@ -337,7 +347,8 @@ public T poll() { parent.onTerminateCall.accept(v, null); } catch (Throwable e) { - throw Exceptions.propagate(Operators.onOperatorError(s, e, v)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, v, + actual.currentContext())); } } if (parent.onSuccessCall != null) { @@ -345,7 +356,8 @@ public T poll() { parent.onSuccessCall.accept(v); } catch (Throwable e) { - throw Exceptions.propagate(Operators.onOperatorError(s, e, v)); + throw Exceptions.propagate(Operators.onOperatorError(s, e, v, + actual.currentContext())); } } if (parent.onAfterTerminateCall != null) { @@ -353,7 +365,9 @@ public T poll() { parent.onAfterTerminateCall.accept(v, null); } catch (Throwable t) { - Operators.onErrorDropped(Operators.onOperatorError(t)); + Operators.onErrorDropped(Operators.onOperatorError(t, + actual.currentContext()), + actual.currentContext()); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/MonoProcessor.java index 6c7b5c3558..6304d91422 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoProcessor.java @@ -33,6 +33,7 @@ import reactor.core.Exceptions; import reactor.core.Scannable; import reactor.util.concurrent.WaitStrategy; +import reactor.util.context.Context; /** * A {@code MonoProcessor} is a {@link Mono} extension that implements stateful semantics. Multi-subscribe is allowed. @@ -275,7 +276,7 @@ public final void onError(Throwable cause) { Subscription s = subscription; if ((source != null && s == null) || this.error != null) { - Operators.onErrorDropped(cause); + Operators.onErrorDroppedMulticast(cause); return; } @@ -286,7 +287,7 @@ public final void onError(Throwable cause) { int state = this.state; for (; ; ) { if (state != STATE_READY && state != STATE_SUBSCRIBED && state != STATE_POST_SUBSCRIBED) { - Operators.onErrorDropped(cause); + Operators.onErrorDroppedMulticast(cause); return; } if (STATE.compareAndSet(this, state, STATE_ERROR)) { @@ -305,7 +306,7 @@ public final void onNext(O value) { Subscription s = subscription; if (value != null && ((source != null && s == null) || this.value != null)) { - Operators.onNextDropped(value); + Operators.onNextDroppedMulticast(value); return; } subscription = null; @@ -328,7 +329,7 @@ public final void onNext(O value) { for (; ; ) { if (state != STATE_READY && state != STATE_SUBSCRIBED && state != STATE_POST_SUBSCRIBED) { if(value != null) { - Operators.onNextDropped(value); + Operators.onNextDroppedMulticast(value); } return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoPublishMulticast.java b/reactor-core/src/main/java/reactor/core/publisher/MonoPublishMulticast.java index 74debff72c..685cb119b4 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoPublishMulticast.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoPublishMulticast.java @@ -57,7 +57,7 @@ public void subscribe(CoreSubscriber actual) { "The transform returned a null Mono"); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoPublishOn.java b/reactor-core/src/main/java/reactor/core/publisher/MonoPublishOn.java index cd75cb79be..aa9fffcfaf 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoPublishOn.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoPublishOn.java @@ -136,7 +136,7 @@ void trySchedule( } catch (RejectedExecutionException ree) { actual.onError(Operators.onRejectedExecution(ree, subscription, - suppressed, dataSignal)); + suppressed, dataSignal, actual.currentContext())); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoReduce.java b/reactor-core/src/main/java/reactor/core/publisher/MonoReduce.java index e15522e0b0..f1b0f36a91 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoReduce.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoReduce.java @@ -83,7 +83,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } T r = result; @@ -98,7 +98,8 @@ public void onNext(T t) { catch (Throwable ex) { result = null; done = true; - actual.onError(Operators.onOperatorError(s, ex, t)); + actual.onError(Operators.onOperatorError(s, ex, t, + actual.currentContext())); return; } @@ -109,7 +110,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoReduceSeed.java b/reactor-core/src/main/java/reactor/core/publisher/MonoReduceSeed.java index 3d0076dfb7..98395668ae 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoReduceSeed.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoReduceSeed.java @@ -58,7 +58,7 @@ public void subscribe(CoreSubscriber actual) { "The initial value supplied is null"); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -122,7 +122,7 @@ public void onNext(T t) { } catch (Throwable e) { - onError(Operators.onOperatorError(this, e, t)); + onError(Operators.onOperatorError(this, e, t, actual.currentContext())); return; } @@ -132,7 +132,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoRepeatWhen.java b/reactor-core/src/main/java/reactor/core/publisher/MonoRepeatWhen.java index 42332189c6..1f0d34ef70 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoRepeatWhen.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoRepeatWhen.java @@ -69,7 +69,7 @@ public void subscribe(CoreSubscriber actual) { "The whenSourceFactory returned a null Publisher"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoRunnable.java b/reactor-core/src/main/java/reactor/core/publisher/MonoRunnable.java index 15797f79ac..b874f2c054 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoRunnable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoRunnable.java @@ -39,7 +39,7 @@ public void subscribe(CoreSubscriber actual) { try { run.run(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, actual.currentContext())); return; } Operators.complete(actual); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSequenceEqual.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSequenceEqual.java index 5e5c9ffde8..bb35ad7875 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSequenceEqual.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSequenceEqual.java @@ -240,7 +240,8 @@ void drain() { Exceptions.throwIfFatal(ex); cancel(s1, q1, s2, q2); - actual.onError(Operators.onOperatorError(ex)); + actual.onError(Operators.onOperatorError(ex, + actual.currentContext())); return; } @@ -328,7 +329,8 @@ public void onSubscribe(Subscription s) { public void onNext(T t) { if (!queue.offer(t)) { onError(Operators.onOperatorError(cachedSubscription, Exceptions - .failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + .failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, + currentContext())); return; } parent.drain(); diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSingle.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSingle.java index cb93acbf14..b6aae1526d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSingle.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSingle.java @@ -117,7 +117,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } value = t; @@ -132,7 +132,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -162,7 +162,8 @@ public void onComplete() { } else { actual.onError(Operators.onOperatorError(this, - new NoSuchElementException("Source was empty"))); + new NoSuchElementException("Source was empty"), + actual.currentContext())); } } else if (c == 1) { diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoStreamCollector.java b/reactor-core/src/main/java/reactor/core/publisher/MonoStreamCollector.java index eddfa4b231..f8ecf67f8a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoStreamCollector.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoStreamCollector.java @@ -62,7 +62,7 @@ public void subscribe(CoreSubscriber actual) { finisher = collector.finisher(); } catch (Throwable ex) { - Operators.error(actual, Operators.onOperatorError(ex)); + Operators.error(actual, Operators.onOperatorError(ex, actual.currentContext())); return; } @@ -118,21 +118,21 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } try { accumulator.accept(container, t); } catch (Throwable ex) { - onError(Operators.onOperatorError(s, ex, t)); + onError(Operators.onOperatorError(s, ex, t, actual.currentContext())); } } @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; @@ -156,7 +156,7 @@ public void onComplete() { r = finisher.apply(a); } catch (Throwable ex) { - actual.onError(Operators.onOperatorError(ex)); + actual.onError(Operators.onOperatorError(ex, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOn.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOn.java index b756120a81..98d666a89a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOn.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOn.java @@ -56,7 +56,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if (parent.s != Operators.cancelledSubscription()) { - actual.onError(Operators.onRejectedExecution(ree, parent, null, null)); + actual.onError(Operators.onRejectedExecution(ree, parent, null, null, + actual.currentContext())); } } } @@ -168,7 +169,8 @@ void trySchedule(long n, Subscription s){ } catch (RejectedExecutionException ree) { if (!worker.isDisposed()) { - actual.onError(Operators.onRejectedExecution(ree, this, null, null)); + actual.onError(Operators.onRejectedExecution(ree, this, null, null, + actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnCallable.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnCallable.java index aa5dc9bc32..722a1f0b5e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnCallable.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnCallable.java @@ -21,7 +21,6 @@ import java.util.concurrent.RejectedExecutionException; import reactor.core.CoreSubscriber; -import reactor.core.Disposable; import reactor.core.Fuseable; import reactor.core.scheduler.Scheduler; @@ -53,7 +52,7 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if(parent.state != FluxSubscribeOnCallable.CallableSubscribeOnSubscription.HAS_CANCELLED) { - actual.onError(Operators.onRejectedExecution(ree)); + actual.onError(Operators.onRejectedExecution(ree, actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnValue.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnValue.java index 19c136dab4..68478b711a 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnValue.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscribeOnValue.java @@ -52,7 +52,8 @@ public void subscribe(CoreSubscriber actual) { } catch (RejectedExecutionException ree) { if (parent.future != OperatorDisposables.DISPOSED) { - actual.onError(Operators.onRejectedExecution(ree)); + actual.onError(Operators.onRejectedExecution(ree, + actual.currentContext())); } } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscriberContext.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscriberContext.java index 1c30d4a649..c3e0de1c42 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSubscriberContext.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSubscriberContext.java @@ -40,7 +40,7 @@ public void subscribe(CoreSubscriber actual) { c = doOnContext.apply(actual.currentContext()); } catch (Throwable t) { - Operators.error(actual, Operators.onOperatorError(t)); + Operators.error(actual, Operators.onOperatorError(t, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoSupplier.java b/reactor-core/src/main/java/reactor/core/publisher/MonoSupplier.java index e709261813..2416f4d161 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoSupplier.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoSupplier.java @@ -57,7 +57,7 @@ public void subscribe(CoreSubscriber actual) { "The supplier source returned null"); } catch (Throwable e) { - actual.onError(Operators.onOperatorError(e)); + actual.onError(Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoTakeLastOne.java b/reactor-core/src/main/java/reactor/core/publisher/MonoTakeLastOne.java index 5e3c6ee114..796a0017b6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoTakeLastOne.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoTakeLastOne.java @@ -98,7 +98,8 @@ public void onComplete() { } else { actual.onError(Operators.onOperatorError(new NoSuchElementException( - "Flux#last() didn't observe any " + "onNext signal"))); + "Flux#last() didn't observe any " + "onNext signal"), + actual.currentContext())); } } else { diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoToCompletableFuture.java b/reactor-core/src/main/java/reactor/core/publisher/MonoToCompletableFuture.java index fcb47e3ed7..33bec9276b 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoToCompletableFuture.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoToCompletableFuture.java @@ -18,7 +18,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.CoreSubscriber; @@ -59,7 +58,7 @@ public void onNext(T t) { s.cancel(); } else { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoUsing.java b/reactor-core/src/main/java/reactor/core/publisher/MonoUsing.java index 91ccc237b2..dc93b0b72f 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoUsing.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoUsing.java @@ -70,7 +70,7 @@ public void subscribe(CoreSubscriber actual) { resource = resourceSupplier.call(); } catch (Throwable e) { - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } @@ -86,11 +86,11 @@ public void subscribe(CoreSubscriber actual) { resourceCleanup.accept(resource); } catch (Throwable ex) { - ex.addSuppressed(Operators.onOperatorError(e)); + ex.addSuppressed(Operators.onOperatorError(e, actual.currentContext())); e = ex; } - Operators.error(actual, Operators.onOperatorError(e)); + Operators.error(actual, Operators.onOperatorError(e, actual.currentContext())); return; } diff --git a/reactor-core/src/main/java/reactor/core/publisher/MonoZip.java b/reactor-core/src/main/java/reactor/core/publisher/MonoZip.java index 865f6081eb..0fd0dd4529 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/MonoZip.java +++ b/reactor-core/src/main/java/reactor/core/publisher/MonoZip.java @@ -240,7 +240,8 @@ void signal() { "zipper produced a null value"); } catch (Throwable t) { - actual.onError(Operators.onOperatorError(null, t, o)); + actual.onError(Operators.onOperatorError(null, t, o, + actual.currentContext())); return; } complete(r); diff --git a/reactor-core/src/main/java/reactor/core/publisher/Operators.java b/reactor-core/src/main/java/reactor/core/publisher/Operators.java index 1e9f95f862..358cc822de 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/Operators.java +++ b/reactor-core/src/main/java/reactor/core/publisher/Operators.java @@ -30,12 +30,12 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.CoreSubscriber; -import reactor.core.Disposables; import reactor.core.Exceptions; import reactor.core.Fuseable; import reactor.core.Scannable; import reactor.util.Logger; import reactor.util.Loggers; +import reactor.util.context.Context; /** * An helper to support "Operator" writing, handle noop subscriptions, validate request @@ -47,6 +47,31 @@ */ public abstract class Operators { + /** + * A key that can be used to store a sequence-specific {@link Hooks#onErrorDropped(Consumer)} + * hook in a {@link Context}, as a {@link Consumer Consumer<Throwable>}. + */ + public static final String KEY_ON_ERROR_DROPPED = "reactor.onErrorDropped.local"; + + /** + * A key that can be used to store a sequence-specific {@link Hooks#onNextDropped(Consumer)} + * hook in a {@link Context}, as a {@link Consumer Consumer<Object>}. + */ + public static final String KEY_ON_NEXT_DROPPED = "reactor.onNextDropped.local"; + + /** + * A key that can be used to store a sequence-specific {@link Hooks#onOperatorError(BiFunction)} + * hook in a {@link Context}, as a {@link BiFunction BiFunction<Throwable, Object, Throwable>}. + */ + public static final String KEY_ON_OPERATOR_ERROR = "reactor.onOperatorError.local"; + + /** + * A key that can be used to store a sequence-specific {@link Hooks#onOperatorError(BiFunction)} + * hook THAT IS ONLY APPLIED TO Operators{@link #onRejectedExecution(Throwable, Context) onRejectedExecution} + * in a {@link Context}, as a {@link BiFunction BiFunction<Throwable, Object, Throwable>}. + */ + public static final String KEY_ON_REJECTED_EXECUTION = "reactor.onRejectedExecution.local"; + /** * Concurrent addition bound to Long.MAX_VALUE. Any concurrent write will "happen * before" this operation. @@ -268,33 +293,52 @@ public static long multiplyCap(long a, long b) { } /** - * An unexpected exception is about to be dropped, and it additionally - * masks another one due to callback failure. The later will be suppressed by - * the dropped exception. + * An unexpected exception is about to be dropped from an operator that has multiple + * subscribers (and thus potentially multiple Context with local onErrorDropped handlers). * - * @param e the exception to handle - * @param root the optional root cause to suppress + * @param e the dropped exception + * @see #onErrorDropped(Throwable, Context) */ - public static void onErrorDropped(Throwable e, @Nullable Throwable root) { - if(root != null && root != e) { - e.addSuppressed(root); - } - onErrorDropped(e); + public static void onErrorDroppedMulticast(Throwable e) { + //TODO let this method go through multiple contexts and use their local handlers + //if at least one has no local handler, also call onErrorDropped(e, Context.empty()) + onErrorDropped(e, Context.empty()); } /** * An unexpected exception is about to be dropped. * * @param e the dropped exception + * @param context a context that might hold a local error consumer (see {@link #KEY_ON_ERROR_DROPPED}) */ - public static void onErrorDropped(Throwable e) { - Consumer hook = Hooks.onErrorDroppedHook; + public static void onErrorDropped(Throwable e, Context context) { + Consumer hook = context.getOrDefault(KEY_ON_ERROR_DROPPED,null); + if (hook == null) { + hook = Hooks.onErrorDroppedHook; + } if (hook == null) { throw Exceptions.bubble(e); } hook.accept(e); } + /** + * An unexpected event is about to be dropped from an operator that has multiple + * subscribers (and thus potentially multiple Context with local onNextDropped handlers). + *

+ * If no hook is registered for {@link Hooks#onNextDropped(Consumer)}, the dropped + * element is just logged at DEBUG level. + * + * @param the dropped value type + * @param t the dropped data + * @see #onNextDropped(Object, Context) + */ + public static void onNextDroppedMulticast(T t) { + //TODO let this method go through multiple contexts and use their local handlers + //if at least one has no local handler, also call onNextDropped(t, Context.empty()) + onNextDropped(t, Context.empty()); + } + /** * An unexpected event is about to be dropped. *

@@ -303,18 +347,20 @@ public static void onErrorDropped(Throwable e) { * * @param the dropped value type * @param t the dropped data - * @see #onNextDropped(Object) + * @param context a context that might hold a local next consumer (see {@link #KEY_ON_NEXT_DROPPED}) */ - public static void onNextDropped(T t) { - //noinspection ConstantConditions - if(t != null) { - Consumer hook = Hooks.onNextDroppedHook; - if (hook != null) { - hook.accept(t); - } - else if (log.isDebugEnabled()) { - log.debug("onNextDropped: " + t); - } + public static void onNextDropped(T t, Context context) { + Objects.requireNonNull(t, "onNext"); + Objects.requireNonNull(context, "context"); + Consumer hook = context.getOrDefault(KEY_ON_NEXT_DROPPED, null); + if (hook == null) { + hook = Hooks.onNextDroppedHook; + } + if (hook != null) { + hook.accept(t); + } + else if (log.isDebugEnabled()) { + log.debug("onNextDropped: " + t); } } @@ -325,11 +371,12 @@ else if (log.isDebugEnabled()) { * {@link Exceptions#throwIfFatal(Throwable)}. * * @param error the callback or operator error + * @param context a context that might hold a local error consumer * @return mapped {@link Throwable} * */ - public static Throwable onOperatorError(Throwable error) { - return onOperatorError(null, error, null); + public static Throwable onOperatorError(Throwable error, Context context) { + return onOperatorError(null, error, context); } /** @@ -340,11 +387,14 @@ public static Throwable onOperatorError(Throwable error) { * * @param subscription the linked operator parent {@link Subscription} * @param error the callback or operator error + * @param context a context that might hold a local error consumer * @return mapped {@link Throwable} * */ - public static Throwable onOperatorError(@Nullable Subscription subscription, Throwable error) { - return onOperatorError(subscription, error, null); + public static Throwable onOperatorError(@Nullable Subscription subscription, + Throwable error, + Context context) { + return onOperatorError(subscription, error, null, context); } /** @@ -358,12 +408,13 @@ public static Throwable onOperatorError(@Nullable Subscription subscription, Thr * @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) { + @Nullable Object dataSignal, Context context) { Exceptions.throwIfFatal(error); if(subscription != null) { @@ -372,7 +423,10 @@ public static Throwable onOperatorError(@Nullable Subscription subscription, Throwable t = Exceptions.unwrap(error); BiFunction hook = - Hooks.onOperatorErrorHook; + context.getOrDefault(KEY_ON_OPERATOR_ERROR, null); + if (hook == null) { + hook = Hooks.onOperatorErrorHook; + } if (hook == null) { if (dataSignal != null) { if (dataSignal != t && dataSignal instanceof Throwable) { @@ -393,11 +447,14 @@ public static Throwable onOperatorError(@Nullable Subscription subscription, * {@link reactor.core.scheduler.Scheduler}, notably when it was already disposed. *

* Wrapping is done by calling both {@link Exceptions#bubble(Throwable)} and - * {@link #onOperatorError(Subscription, Throwable, Object)}. + * {@link #onOperatorError(Subscription, Throwable, Object, Context)}. + * + * @param original the original execution error + * @param context a context that might hold a local error consumer * */ - public static RuntimeException onRejectedExecution(Throwable original) { - return onRejectedExecution(original, null, null, null); + public static RuntimeException onRejectedExecution(Throwable original, Context context) { + return onRejectedExecution(original, null, null, null, context); } /** @@ -406,26 +463,35 @@ public static RuntimeException onRejectedExecution(Throwable original) { * {@link reactor.core.scheduler.Scheduler}, notably when it was already disposed. *

* Wrapping is done by calling both {@link Exceptions#bubble(Throwable)} and - * {@link #onOperatorError(Subscription, Throwable, Object)} (with the passed + * {@link #onOperatorError(Subscription, Throwable, Object, Context)} (with the passed * {@link Subscription}). * + * @param original the original execution error * @param subscription the subscription to pass to onOperatorError. * @param suppressed a Throwable to be suppressed by the {@link RejectedExecutionException} (or null if not relevant) - * @param dataSignal a value to be passed to {@link #onOperatorError(Subscription, Throwable, Object)} (or null if not relevant) + * @param dataSignal a value to be passed to {@link #onOperatorError(Subscription, Throwable, Object, Context)} (or null if not relevant) + * @param context a context that might hold a local error consumer */ public static RuntimeException onRejectedExecution(Throwable original, @Nullable Subscription subscription, @Nullable Throwable suppressed, - @Nullable Object dataSignal) { + @Nullable Object dataSignal, + Context context) { + //we "cheat" to apply the special key for onRejectedExecution in onOperatorError + if (context.hasKey(KEY_ON_REJECTED_EXECUTION)) { + context = context.put(KEY_ON_OPERATOR_ERROR, context.get(KEY_ON_REJECTED_EXECUTION)); + } + //FIXME only create REE if original is REE singleton OR there's suppressed OR there's Throwable dataSignal RejectedExecutionException ree = Exceptions.failWithRejected(original); if (suppressed != null) { ree.addSuppressed(suppressed); } if (dataSignal != null) { - return Exceptions.propagate(Operators.onOperatorError(subscription, ree, dataSignal)); + return Exceptions.propagate(Operators.onOperatorError(subscription, ree, + dataSignal, context)); } - return Exceptions.propagate(Operators.onOperatorError(subscription, ree)); + return Exceptions.propagate(Operators.onOperatorError(subscription, ree, context)); } /** @@ -1622,7 +1688,7 @@ public void onNext(Object o) { @Override public void onError(Throwable t) { - Operators.onErrorDropped(Exceptions.errorCallbackNotImplemented(t)); + Operators.onErrorDropped(Exceptions.errorCallbackNotImplemented(t), Context.empty()); } @Override diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelCollect.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelCollect.java index bf9f5d62f0..a91922f436 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelCollect.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelCollect.java @@ -81,7 +81,8 @@ public void subscribe(CoreSubscriber[] subscribers) { "The initialSupplier returned a null value"); } catch (Throwable ex) { - reportError(subscribers, Operators.onOperatorError(ex)); + reportError(subscribers, Operators.onOperatorError(ex, + subscribers[i].currentContext())); return; } @@ -137,7 +138,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -145,14 +146,14 @@ public void onNext(T t) { collector.accept(collection, t); } catch (Throwable ex) { - onError(Operators.onOperatorError(this, ex, t)); + onError(Operators.onOperatorError(this, ex, t, actual.currentContext())); } } @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeReduce.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeReduce.java index 2eb7f5f035..38d0dd25f6 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeReduce.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeReduce.java @@ -160,7 +160,7 @@ void innerError(Throwable ex) { actual.onError(ex); } else if(error != ex) { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } @@ -176,7 +176,8 @@ void innerComplete(@Nullable T value) { sp.second), "The reducer returned a null value"); } catch (Throwable ex) { - innerError(Operators.onOperatorError(this, ex)); + innerError(Operators.onOperatorError(this, ex, + actual.currentContext())); return; } } @@ -252,7 +253,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); return; } T v = value; @@ -266,7 +267,7 @@ public void onNext(T t) { v = Objects.requireNonNull(reducer.apply(v, t), "The reducer returned a null value"); } catch (Throwable ex) { - onError(Operators.onOperatorError(s, ex, t)); + onError(Operators.onOperatorError(s, ex, t, currentContext())); return; } @@ -277,7 +278,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, parent.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSequential.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSequential.java index 3467b1fe90..b75986b00d 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSequential.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSequential.java @@ -179,7 +179,8 @@ void onNext(MergeSequentialInner inner, T value) { Queue q = inner.getQueue(queueSupplier); if(!q.offer(value)){ - onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value)); + onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value, + actual.currentContext())); return; } } @@ -190,7 +191,8 @@ void onNext(MergeSequentialInner inner, T value) { Queue q = inner.getQueue(queueSupplier); if(!q.offer(value)){ - onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value)); + onError(Operators.onOperatorError(this, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), value, + actual.currentContext())); return; } @@ -208,7 +210,7 @@ void onError(Throwable ex) { drain(); } else if(error != ex) { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSort.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSort.java index 1203617d91..77f9202c2e 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSort.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelMergeSort.java @@ -191,7 +191,7 @@ void innerError(Throwable ex) { drain(); } else if(error != ex) { - Operators.onErrorDropped(ex); + Operators.onErrorDropped(ex, actual.currentContext()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelReduceSeed.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelReduceSeed.java index fdcc5d3681..e8551aba86 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelReduceSeed.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelReduceSeed.java @@ -82,7 +82,8 @@ public void subscribe(CoreSubscriber[] subscribers) { "The initialSupplier returned a null value"); } catch (Throwable ex) { - reportError(subscribers, Operators.onOperatorError(ex)); + reportError(subscribers, Operators.onOperatorError(ex, + subscribers[i].currentContext())); return; } parents[i] = @@ -137,7 +138,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, actual.currentContext()); return; } @@ -147,7 +148,7 @@ public void onNext(T t) { v = Objects.requireNonNull(reducer.apply(accumulator, t), "The reducer returned a null value"); } catch (Throwable ex) { - onError(Operators.onOperatorError(this, ex, t)); + onError(Operators.onOperatorError(this, ex, t, actual.currentContext())); return; } @@ -157,7 +158,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, actual.currentContext()); return; } done = true; diff --git a/reactor-core/src/main/java/reactor/core/publisher/ParallelSource.java b/reactor-core/src/main/java/reactor/core/publisher/ParallelSource.java index 67a59d0d66..1c57285e06 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ParallelSource.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ParallelSource.java @@ -221,12 +221,12 @@ void setupSubscribers() { @Override public void onNext(T t) { if (done) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); return; } if (sourceMode == Fuseable.NONE) { if (!queue.offer(t)) { - onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t)); + onError(Operators.onOperatorError(s, Exceptions.failWithOverflow(Exceptions.BACKPRESSURE_ERROR_QUEUE_FULL), t, currentContext())); return; } } @@ -236,7 +236,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } error = t; @@ -268,7 +268,7 @@ void drainAsync() { int missed = 1; Queue q = queue; - Subscriber[] a = this.subscribers; + CoreSubscriber[] a = this.subscribers; AtomicLongArray r = this.requests; long[] e = this.emissions; int n = e.length; @@ -319,7 +319,7 @@ void drainAsync() { try { v = q.poll(); } catch (Throwable ex) { - ex = Operators.onOperatorError(s, ex); + ex = Operators.onOperatorError(s, ex, a[idx].currentContext()); for (Subscriber s : a) { s.onError(ex); } @@ -372,7 +372,7 @@ void drainSync() { int missed = 1; Queue q = queue; - Subscriber[] a = this.subscribers; + CoreSubscriber[] a = this.subscribers; AtomicLongArray r = this.requests; long[] e = this.emissions; int n = e.length; @@ -388,19 +388,7 @@ void drainSync() { return; } - boolean empty; - - try { - empty = q.isEmpty(); - } catch (Throwable ex) { - ex = Operators.onOperatorError(s, ex); - for (Subscriber s : a) { - s.onError(ex); - } - return; - } - - if (empty) { + if (q.isEmpty()) { for (Subscriber s : a) { s.onComplete(); } @@ -416,7 +404,7 @@ void drainSync() { try { v = q.poll(); } catch (Throwable ex) { - ex = Operators.onOperatorError(s, ex); + ex = Operators.onOperatorError(s, ex, a[idx].currentContext()); for (Subscriber s : a) { s.onError(ex); } diff --git a/reactor-core/src/main/java/reactor/core/publisher/ReplayProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/ReplayProcessor.java index 7dfb627b37..e4e2695415 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ReplayProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ReplayProcessor.java @@ -27,7 +27,6 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.CoreSubscriber; -import reactor.core.Exceptions; import reactor.core.Fuseable; import reactor.core.Scannable; import reactor.core.scheduler.Scheduler; @@ -424,7 +423,7 @@ public int getPrefetch() { public void onNext(T t) { FluxReplay.ReplayBuffer b = buffer; if (b.isDone()) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); } else { b.add(t); @@ -438,7 +437,7 @@ public void onNext(T t) { public void onError(Throwable t) { FluxReplay.ReplayBuffer b = buffer; if (b.isDone()) { - Operators.onErrorDropped(t); + Operators.onErrorDroppedMulticast(t); } else { b.onError(t); diff --git a/reactor-core/src/main/java/reactor/core/publisher/StrictSubscriber.java b/reactor-core/src/main/java/reactor/core/publisher/StrictSubscriber.java index 140ca50eb6..06d73729ee 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/StrictSubscriber.java +++ b/reactor-core/src/main/java/reactor/core/publisher/StrictSubscriber.java @@ -26,6 +26,7 @@ import reactor.core.CoreSubscriber; import reactor.core.Exceptions; import reactor.core.Scannable; +import reactor.util.context.Context; /** * Reactive Streams Commons safe exit @@ -106,7 +107,7 @@ public void onError(Throwable t) { } } else { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, Context.empty()); } } diff --git a/reactor-core/src/main/java/reactor/core/publisher/UnicastProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/UnicastProcessor.java index f349a1f59f..0e5051ad5b 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/UnicastProcessor.java +++ b/reactor-core/src/main/java/reactor/core/publisher/UnicastProcessor.java @@ -30,6 +30,7 @@ import reactor.core.Exceptions; import reactor.core.Fuseable; import reactor.util.concurrent.Queues; +import reactor.util.context.Context; /** * A Processor implementation that takes a custom queue and allows @@ -304,16 +305,22 @@ public int getPrefetch() { return Integer.MAX_VALUE; } + @Override + public Context currentContext() { + CoreSubscriber actual = this.actual; + return actual != null ? actual.currentContext() : Context.empty(); + } + @Override public void onNext(T t) { if (done || cancelled) { - Operators.onNextDropped(t); + Operators.onNextDropped(t, currentContext()); return; } if (!queue.offer(t)) { Throwable ex = Operators.onOperatorError(null, - Exceptions.failWithOverflow(), t); + Exceptions.failWithOverflow(), t, currentContext()); if(onOverflow != null) { try { onOverflow.accept(t); @@ -323,7 +330,7 @@ public void onNext(T t) { ex.initCause(e); } } - onError(Operators.onOperatorError(null, ex, t)); + onError(Operators.onOperatorError(null, ex, t, currentContext())); return; } drain(); @@ -332,7 +339,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (done || cancelled) { - Operators.onErrorDropped(t); + Operators.onErrorDropped(t, currentContext()); return; } diff --git a/reactor-core/src/test/java/reactor/core/publisher/HooksTest.java b/reactor-core/src/test/java/reactor/core/publisher/HooksTest.java index f90865cccc..e47f0f4244 100644 --- a/reactor-core/src/test/java/reactor/core/publisher/HooksTest.java +++ b/reactor-core/src/test/java/reactor/core/publisher/HooksTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,6 +41,7 @@ import reactor.test.StepVerifier; import reactor.test.publisher.TestPublisher; import reactor.test.subscriber.AssertSubscriber; +import reactor.util.context.Context; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -534,14 +535,14 @@ public void errorHooks() throws Exception { throw new TestException("errorDrop"); }); - Throwable w = Operators.onOperatorError(null, new Exception(), "hello"); + Throwable w = Operators.onOperatorError(null, new Exception(), "hello", Context.empty()); Assert.assertTrue(w instanceof TestException); Assert.assertTrue(w.getMessage() .equals("hello")); try { - Operators.onNextDropped("hello"); + Operators.onNextDropped("hello", Context.empty()); Assert.fail(); } catch (Throwable t) { @@ -552,7 +553,7 @@ public void errorHooks() throws Exception { } try { - Operators.onErrorDropped(new Exception()); + Operators.onErrorDropped(new Exception(), Context.empty()); Assert.fail(); } catch (Throwable t) { @@ -572,7 +573,7 @@ public void accumulatingHooks() throws Exception { ref.set(ref.get()+"bar"); }); - Operators.onNextDropped("foo"); + Operators.onNextDropped("foo", Context.empty()); assertThat(ref.get()).isEqualTo("foobar"); @@ -583,7 +584,7 @@ public void accumulatingHooks() throws Exception { ref.set(ref.get()+"bar"); }); - Operators.onErrorDropped(new Exception("foo")); + Operators.onErrorDropped(new Exception("foo"), Context.empty()); assertThat(ref.get()).isEqualTo("foobar"); @@ -599,7 +600,7 @@ public void accumulatingHooks() throws Exception { return error; }); - Operators.onOperatorError(null, null, "foo"); + Operators.onOperatorError(null, null, "foo", Context.empty()); assertThat(ref.get()).isEqualTo("foobar"); diff --git a/reactor-core/src/test/java/reactor/core/publisher/OperatorDisposablesTest.java b/reactor-core/src/test/java/reactor/core/publisher/OperatorDisposablesTest.java index 2c091f54d3..be0559be79 100644 --- a/reactor-core/src/test/java/reactor/core/publisher/OperatorDisposablesTest.java +++ b/reactor-core/src/test/java/reactor/core/publisher/OperatorDisposablesTest.java @@ -23,6 +23,7 @@ import reactor.core.Disposables; import reactor.core.scheduler.Schedulers; import reactor.test.RaceTestUtils; +import reactor.util.context.Context; import static org.assertj.core.api.Assertions.assertThat; @@ -61,7 +62,8 @@ public void validationNull() { Hooks.onErrorDropped(e -> assertThat(e).isInstanceOf(NullPointerException.class) .hasMessage("next is null")); try { - assertThat(OperatorDisposables.validate(null, null, Operators::onErrorDropped)).isFalse(); + assertThat(OperatorDisposables.validate(null, null, + e -> Operators.onErrorDropped(e, Context.empty()))).isFalse(); } finally { Hooks.resetOnErrorDropped(); } diff --git a/reactor-core/src/test/java/reactor/core/publisher/OperatorsTest.java b/reactor-core/src/test/java/reactor/core/publisher/OperatorsTest.java index 477f63ca1c..c767fd3cbb 100644 --- a/reactor-core/src/test/java/reactor/core/publisher/OperatorsTest.java +++ b/reactor-core/src/test/java/reactor/core/publisher/OperatorsTest.java @@ -16,8 +16,12 @@ package reactor.core.publisher; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLongFieldUpdater; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; +import java.util.function.Consumer; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -33,6 +37,7 @@ import reactor.core.publisher.Operators.MultiSubscriptionSubscriber; import reactor.core.publisher.Operators.ScalarSubscription; import reactor.test.RaceTestUtils; +import reactor.util.context.Context; import static org.assertj.core.api.Assertions.assertThat; @@ -250,4 +255,101 @@ public void scanScalarSubscription() { Assertions.assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); Assertions.assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue(); } + + @Test + public void onErrorDroppedLocal() { + AtomicReference hookState = new AtomicReference<>(); + Consumer localHook = hookState::set; + Context c = Context.of(Operators.KEY_ON_ERROR_DROPPED, localHook); + + Operators.onErrorDropped(new IllegalArgumentException("boom"), c); + + assertThat(hookState.get()).isInstanceOf(IllegalArgumentException.class) + .hasMessage("boom"); + } + + @Test + public void onNextDroppedLocal() { + AtomicReference hookState = new AtomicReference<>(); + Consumer localHook = hookState::set; + Context c = Context.of(Operators.KEY_ON_NEXT_DROPPED, localHook); + + Operators.onNextDropped("foo", c); + + assertThat(hookState.get()).isEqualTo("foo"); + } + + @Test + public void onOperatorErrorLocal() { + BiFunction localHook = (e, v) -> + new IllegalStateException("boom_" + v, e); + Context c = Context.of(Operators.KEY_ON_OPERATOR_ERROR, localHook); + + IllegalArgumentException failure = new IllegalArgumentException("foo"); + + final Throwable throwable = Operators.onOperatorError(null, failure, + "foo", c); + + assertThat(throwable).isInstanceOf(IllegalStateException.class) + .hasMessage("boom_foo") + .hasCause(failure); + } + + @Test + public void onRejectedExecutionWithoutDataSignalDelegatesToErrorLocal() { + BiFunction localHook = (e, v) -> + new IllegalStateException("boom_" + v, e); + Context c = Context.of(Operators.KEY_ON_OPERATOR_ERROR, localHook); + + IllegalArgumentException failure = new IllegalArgumentException("foo"); + final Throwable throwable = Operators.onRejectedExecution(failure, null, null, null, c); + + assertThat(throwable).isInstanceOf(IllegalStateException.class) + .hasMessage("boom_null") + .hasNoSuppressedExceptions(); + assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class) + .hasMessage("Scheduler unavailable") + .hasCause(failure); + } + + @Test + public void onRejectedExecutionWithDataSignalDelegatesToErrorLocal() { + BiFunction localHook = (e, v) -> + new IllegalStateException("boom_" + v, e); + Context c = Context.of(Operators.KEY_ON_OPERATOR_ERROR, localHook); + + IllegalArgumentException failure = new IllegalArgumentException("foo"); + final Throwable throwable = Operators.onRejectedExecution(failure, null, + null, "bar", c); + + assertThat(throwable).isInstanceOf(IllegalStateException.class) + .hasMessage("boom_bar") + .hasNoSuppressedExceptions(); + assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class) + .hasMessage("Scheduler unavailable") + .hasCause(failure); + } + + @Test + public void onRejectedExecutionLocalTakesPrecedenceOverOnOperatorError() { + BiFunction localOperatorErrorHook = (e, v) -> + new IllegalStateException("boom_" + v, e); + + BiFunction localReeHook = (e, v) -> + new IllegalStateException("rejected_" + v, e); + Context c = Context.of( + Operators.KEY_ON_OPERATOR_ERROR, localOperatorErrorHook, + Operators.KEY_ON_REJECTED_EXECUTION, localReeHook); + + IllegalArgumentException failure = new IllegalArgumentException("foo"); + final Throwable throwable = Operators.onRejectedExecution(failure, null, + null, "bar", c); + + assertThat(throwable).isInstanceOf(IllegalStateException.class) + .hasMessage("rejected_bar") + .hasNoSuppressedExceptions(); + assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class) + .hasMessage("Scheduler unavailable") + .hasCause(failure); + } } diff --git a/reactor-test/src/test/java/reactor/test/StepVerifierAssertionsTests.java b/reactor-test/src/test/java/reactor/test/StepVerifierAssertionsTests.java index e579333143..fe2d71977b 100644 --- a/reactor-test/src/test/java/reactor/test/StepVerifierAssertionsTests.java +++ b/reactor-test/src/test/java/reactor/test/StepVerifierAssertionsTests.java @@ -21,6 +21,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.Operators; +import reactor.util.context.Context; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -423,8 +424,8 @@ public void assertOperatorErrorsFailureWrongCount() { StepVerifier.create(Flux.from(s -> { s.onSubscribe(Operators.emptySubscription()); s.onError(err1); - Operators.onOperatorError(err2); - Operators.onOperatorError(err3); + Operators.onOperatorError(err2, Context.empty()); + Operators.onOperatorError(err3, Context.empty()); }).buffer(1)) .expectError() .verifyThenAssertThat() @@ -446,8 +447,8 @@ public void assertOperatorErrorsNotSatisfying() { StepVerifier.create(Flux.from(s -> { s.onSubscribe(Operators.emptySubscription()); s.onError(err1); - Operators.onOperatorError(err2); - Operators.onOperatorError(err3); + Operators.onOperatorError(err2, Context.empty()); + Operators.onOperatorError(err3, Context.empty()); }).buffer(1)) .expectError() .verifyThenAssertThat() @@ -470,8 +471,8 @@ public void assertOperatorErrorsNotMatching() { StepVerifier.create(Flux.from(s -> { s.onSubscribe(Operators.emptySubscription()); s.onError(err1); - Operators.onOperatorError(err2); - Operators.onOperatorError(err3); + Operators.onOperatorError(err2, Context.empty()); + Operators.onOperatorError(err3, Context.empty()); }).buffer(1)) .expectError() .verifyThenAssertThat() @@ -564,7 +565,7 @@ public void assertOperationErrorShortcutTestTupleContainsError() { try { StepVerifier.create(Flux.from(f -> { f.onSubscribe(Operators.emptySubscription()); - Operators.onOperatorError(null, null, "foo"); + Operators.onOperatorError(null, null, "foo", Context.empty()); f.onComplete(); })) .expectComplete()