Class Hooks
-
Method Summary
Modifier and TypeMethodDescriptionaddCallSiteInfo(@Nullable P publisher, String callSite) Deprecated.Should only be used by the instrumentation, DOES NOT guarantee any compatibilitystatic voidaddQueueWrapper(String key, Function<Queue<?>, Queue<?>> decorator) Adds a wrapper for everyQueueused in Reactor.addReturnInfo(@Nullable P publisher, String method) Deprecated.Should only be used by the instrumentation, DOES NOT guarantee any compatibilitystatic <T> Flux<T>convertToFluxBypassingHooks(Publisher<T> publisher) static <T> Mono<T>convertToMonoBypassingHooks(Publisher<T> publisher, boolean enforceMonoContract) static voidGlobally disables automatic context propagation toThreadLocals.static voidGlobally disables theContextloss detection that was previously enabled byenableContextLossTracking().static voidGlobally enables automatic context propagation toThreadLocals.static voidGlobally enables theContextloss detection in operators likeFlux.transform(java.util.function.Function<? super reactor.core.publisher.Flux<T>, ? extends org.reactivestreams.Publisher<V>>)orMono.transformDeferred(java.util.function.Function<? super reactor.core.publisher.Mono<T>, ? extends org.reactivestreams.Publisher<V>>)when non-Reactor types are used.static booleanstatic voidonEachOperator(String key, Function<? super Publisher<Object>, ? extends Publisher<Object>> onEachOperator) static voidstatic voidonErrorDropped(Consumer<? super Throwable> c) Override global error dropped strategy which by default bubble back the error.static voidonLastOperator(String key, Function<? super Publisher<Object>, ? extends Publisher<Object>> onLastOperator) static voidstatic voidOverride global data dropped strategy which by default logs at DEBUG level.static voidResetsonNextDropped hook(s)and apply a strategy of throwingExceptions.failWithCancel()instead.static voidonNextError(BiFunction<? super Throwable, Object, ? extends Throwable> onNextError) Set the custom global error mode hook for operators that support resuming during an error in theirSubscriber.onNext(Object).static voidEnable operator stack recorder that captures a declaration stack whenever an operator is instantiated.static voidonOperatorError(String key, BiFunction<? super Throwable, @Nullable Object, ? extends Throwable> onOperatorError) Add or replace a named custom error mapping, overriding the default one.static voidonOperatorError(BiFunction<? super Throwable, @Nullable Object, ? extends Throwable> onOperatorError) Add a custom error mapping, overriding the default one.static voidremoveQueueWrapper(String key) Removes existingQueuewrapper by key.static voidRemove all queue wrappers.static voidReset global "assembly" hook trackingstatic voidRemove the sub-hook with keykeyfrom the onEachOperator hook.static voidReset global error dropped strategy to bubbling back the error.static voidReset global "subscriber" hook trackingstatic voidRemove the sub-hook with keykeyfrom the onLastOperator hook.static voidReset global data dropped strategy to throwing viaExceptions.failWithCancel()static voidReset global onNext error handling strategy to terminating the sequence with an onError and cancelling upstream (OnNextFailureStrategy.STOP).static voidReset global operator debug.static voidReset global operator error mapping to the default behavior.static voidRemove the sub-hook with keykeyfrom the onOperatorError hook.static <T> Queue<T>Applies theQueuewrappers that were previously registered.
-
Method Details
-
convertToFluxBypassingHooks
-
convertToMonoBypassingHooks
public static <T> Mono<T> convertToMonoBypassingHooks(Publisher<T> publisher, boolean enforceMonoContract) Utility method to convert aPublisherto aMonowithout applyingHooks. Can optionally perform a "direct" (or unsafe) conversion when the caller is certain thePublisherhasMonosemantics.- Type Parameters:
T- the type of data emitted by thePublisher- Parameters:
publisher- thePublisherto convert to aMonoenforceMonoContract-trueto ensureMonosemantics (by cancelling on first onNext if source isn't already aMono),falseto perform a direct conversion (seeMono.fromDirect(Publisher)).- Returns:
- the
Publisherwrapped as aMono, or the original if it was aMono
-
onEachOperator
public static void onEachOperator(Function<? super Publisher<Object>, ? extends Publisher<Object>> onEachOperator) Add aPublisheroperator interceptor for each operator created (FluxorMono). The passed function is applied to the original operatorPublisherand can return a differentPublisher, on the condition that it generically maintains the same data type as the original. Use of theFlux/MonoAPIs is discouraged as it will recursively call this hook, leading toStackOverflowError.Note that sub-hooks are cumulative, but invoking this method twice with the same instance (or any instance that has the same `toString`) will result in only a single instance being applied. See
onEachOperator(String, Function)for a variant that allows you to name the sub-hooks (and thus replace them or remove them individually later on). Can be fully reset viaresetOnEachOperator().This pointcut function cannot make use of
Flux,MonoorParallelFluxAPIs as it would lead to a recursive call to the hook: the operator calls would effectively invoke onEachOperator from onEachOperator. SeeconvertToFluxBypassingHooks(Publisher)andconvertToMonoBypassingHooks(Publisher, boolean).- Parameters:
onEachOperator- the sub-hook: a function to intercept each operation call (e.g.map (fn)andmap(fn2)influx.map(fn).map(fn2).subscribe())- See Also:
-
onEachOperator
public static void onEachOperator(String key, Function<? super Publisher<Object>, ? extends Publisher<Object>> onEachOperator) Add or replace a namedPublisheroperator interceptor for each operator created (FluxorMono). The passed function is applied to the original operatorPublisherand can return a differentPublisher, on the condition that it generically maintains the same data type as the original. Use of theFlux/MonoAPIs is discouraged as it will recursively call this hook, leading toStackOverflowError.Note that sub-hooks are cumulative. Invoking this method twice with the same key will replace the old sub-hook with that name, but keep the execution order (eg. A-h1, B-h2, A-h3 will keep A-B execution order, leading to hooks h3 then h2 being executed). Removing a particular key using
resetOnEachOperator(String)then adding it back will result in the execution order changing (the later sub-hook being executed last). Can be fully reset viaresetOnEachOperator().This pointcut function cannot make use of
Flux,MonoorParallelFluxAPIs as it would lead to a recursive call to the hook: the operator calls would effectively invoke onEachOperator from onEachOperator. SeeconvertToFluxBypassingHooks(Publisher)andconvertToMonoBypassingHooks(Publisher, boolean).- Parameters:
key- the key for the sub-hook to add/replaceonEachOperator- the sub-hook: a function to intercept each operation call (e.g.map (fn)andmap(fn2)influx.map(fn).map(fn2).subscribe())- See Also:
-
resetOnEachOperator
Remove the sub-hook with keykeyfrom the onEachOperator hook. No-op if no such key has been registered, and equivalent to callingresetOnEachOperator()if it was the last sub-hook.- Parameters:
key- the key of the sub-hook to remove
-
resetOnEachOperator
public static void resetOnEachOperator()Reset global "assembly" hook tracking -
onErrorDropped
Override global error dropped strategy which by default bubble back the error.The hook is cumulative, so calling this method several times will set up the hook for as many consumer invocations (even if called with the same consumer instance).
- Parameters:
c- theConsumerto apply to dropped errors
-
onLastOperator
public static void onLastOperator(Function<? super Publisher<Object>, ? extends Publisher<Object>> onLastOperator) Add aPublisheroperator interceptor for the last operator created in every flow (FluxorMono). The passed function is applied to the original operatorPublisherand can return a differentPublisher, on the condition that it generically maintains the same data type as the original.Note that sub-hooks are cumulative, but invoking this method twice with the same instance (or any instance that has the same `toString`) will result in only a single instance being applied. See
onLastOperator(String, Function)for a variant that allows you to name the sub-hooks (and thus replace them or remove them individually later on). Can be fully reset viaresetOnLastOperator().This pointcut function cannot make use of
Flux,MonoorParallelFluxAPIs as it would lead to a recursive call to the hook: the operator calls would effectively invoke onEachOperator from onEachOperator. SeeconvertToFluxBypassingHooks(Publisher)andconvertToMonoBypassingHooks(Publisher, boolean).- Parameters:
onLastOperator- the sub-hook: a function to intercept last operation call (e.g.map(fn2)influx.map(fn).map(fn2).subscribe())- See Also:
-
onLastOperator
public static void onLastOperator(String key, Function<? super Publisher<Object>, ? extends Publisher<Object>> onLastOperator) Add or replace a namedPublisheroperator interceptor for the last operator created in every flow (FluxorMono). The passed function is applied to the original operatorPublisherand can return a differentPublisher, on the condition that it generically maintains the same data type as the original. Use of theFlux/MonoAPIs is discouraged as it will recursively call this hook, leading toStackOverflowError.Note that sub-hooks are cumulative. Invoking this method twice with the same key will replace the old sub-hook with that name, but keep the execution order (eg. A-h1, B-h2, A-h3 will keep A-B execution order, leading to hooks h3 then h2 being executed). Removing a particular key using
resetOnLastOperator(String)then adding it back will result in the execution order changing (the later sub-hook being executed last). Can be fully reset viaresetOnLastOperator().This pointcut function cannot make use of
Flux,MonoorParallelFluxAPIs as it would lead to a recursive call to the hook: the operator calls would effectively invoke onEachOperator from onEachOperator. SeeconvertToFluxBypassingHooks(Publisher)andconvertToMonoBypassingHooks(Publisher, boolean).- Parameters:
key- the key for the sub-hook to add/replaceonLastOperator- the sub-hook: a function to intercept last operation call (e.g.map(fn2)influx.map(fn).map(fn2).subscribe())- See Also:
-
resetOnLastOperator
Remove the sub-hook with keykeyfrom the onLastOperator hook. No-op if no such key has been registered, and equivalent to callingresetOnLastOperator()if it was the last sub-hook.- Parameters:
key- the key of the sub-hook to remove
-
resetOnLastOperator
public static void resetOnLastOperator()Reset global "subscriber" hook tracking -
onNextDropped
Override global data dropped strategy which by default logs at DEBUG level.The hook is cumulative, so calling this method several times will set up the hook for as many consumer invocations (even if called with the same consumer instance).
- Parameters:
c- theConsumerto apply to data (onNext) that is dropped- See Also:
-
onNextDroppedFail
public static void onNextDroppedFail()ResetsonNextDropped hook(s)and apply a strategy of throwingExceptions.failWithCancel()instead.Use
resetOnNextDropped()to reset to the default strategy of logging. -
onOperatorDebug
public static void onOperatorDebug()Enable operator stack recorder that captures a declaration stack whenever an operator is instantiated. When errors are observed later on, they will be enriched with a Suppressed Exception detailing the original assembly line stack. Must be called before producers (e.g. Flux.map, Mono.fromCallable) are actually called to intercept the right stack information.This is added as a specifically-keyed sub-hook in
onEachOperator(String, Function). -
resetOnOperatorDebug
public static void resetOnOperatorDebug()Reset global operator debug. -
onNextError
public static void onNextError(BiFunction<? super Throwable, Object, ? extends Throwable> onNextError) Set the custom global error mode hook for operators that support resuming during an error in theirSubscriber.onNext(Object).The hook is a
BiFunctionofThrowableand potentially nullObject. If it is also aBiPredicate, itstestmethod should be used to determine if an error should be processed (matching predicate) or completely skipped (non-matching predicate). Typical usage, as inOperators, is to check if the predicate matches and fallback toOperators.onOperatorError(Throwable, Context)if it doesn't.- Parameters:
onNextError- the newBiFunctionto use.
-
onOperatorError
public static void onOperatorError(BiFunction<? super Throwable, @Nullable Object, ? extends Throwable> onOperatorError) Add a custom error mapping, overriding the default one. Custom mapping can be an accumulation of several sub-hooks each subsequently added via this method.Note that sub-hooks are cumulative, but invoking this method twice with the same instance (or any instance that has the same `toString`) will result in only a single instance being applied. See
onOperatorError(String, BiFunction)for a variant that allows you to name the sub-hooks (and thus replace them or remove them individually later on). Can be fully reset viaresetOnOperatorError().For reference, the default mapping is to unwrap the exception and, if the second parameter is another exception, to add it to the first as suppressed.
- Parameters:
onOperatorError- an operator errorBiFunctionmapper, returning an arbitrary exception given the failure and optionally some original context (data or error).- See Also:
-
onOperatorError
public static void onOperatorError(String key, BiFunction<? super Throwable, @Nullable Object, ? extends Throwable> onOperatorError) Add or replace a named custom error mapping, overriding the default one. Custom mapping can be an accumulation of several sub-hooks each subsequently added via this method.Note that invoking this method twice with the same key will replace the old sub-hook with that name, but keep the execution order (eg. A-h1, B-h2, A-h3 will keep A-B execution order, leading to hooks h3 then h2 being executed). Removing a particular key using
resetOnOperatorError(String)then adding it back will result in the execution order changing (the later sub-hook being executed last). Can be fully reset viaresetOnOperatorError().For reference, the default mapping is to unwrap the exception and, if the second parameter is another exception, to add it to the first as a suppressed.
- Parameters:
key- the key for the sub-hook to add/replaceonOperatorError- an operator errorBiFunctionmapper, returning an arbitrary exception given the failure and optionally some original context (data or error).- See Also:
-
resetOnOperatorError
Remove the sub-hook with keykeyfrom the onOperatorError hook. No-op if no such key has been registered, and equivalent to callingresetOnOperatorError()if it was the last sub-hook.- Parameters:
key- the key of the sub-hook to remove
-
resetOnOperatorError
public static void resetOnOperatorError()Reset global operator error mapping to the default behavior.For reference, the default mapping is to unwrap the exception and, if the second parameter is another exception, to add it to the first as a suppressed.
-
resetOnErrorDropped
public static void resetOnErrorDropped()Reset global error dropped strategy to bubbling back the error. -
resetOnNextDropped
public static void resetOnNextDropped()Reset global data dropped strategy to throwing viaExceptions.failWithCancel() -
resetOnNextError
public static void resetOnNextError()Reset global onNext error handling strategy to terminating the sequence with an onError and cancelling upstream (OnNextFailureStrategy.STOP). -
enableContextLossTracking
public static void enableContextLossTracking()Globally enables theContextloss detection in operators likeFlux.transform(java.util.function.Function<? super reactor.core.publisher.Flux<T>, ? extends org.reactivestreams.Publisher<V>>)orMono.transformDeferred(java.util.function.Function<? super reactor.core.publisher.Mono<T>, ? extends org.reactivestreams.Publisher<V>>)when non-Reactor types are used. An exception will be thrown upon applying the transformation if the originalContextisn't reachable (ie. it has been replaced by a totally differentContext, or noContextat all) -
disableContextLossTracking
public static void disableContextLossTracking()Globally disables theContextloss detection that was previously enabled byenableContextLossTracking(). -
enableAutomaticContextPropagation
public static void enableAutomaticContextPropagation()Globally enables automatic context propagation toThreadLocals.It requires the context-propagation library to be on the classpath to have an effect. Using the implicit global
ContextRegistryit reads entries present in the modifiedContextusingFlux.contextWrite(ContextView)(orMono.contextWrite(ContextView)) andFlux.contextWrite(Function)(orMono.contextWrite(Function)) and restores allThreadLocals associated via same keys for whichThreadLocalAccessors are registered.The
ThreadLocals are present in the upstream operators from thecontextWrite(...)call and the unmodified (downstream)Contextis used when signals are delivered downstream, making thecontextWrite(...)a logical boundary for the context propagation mechanism.This mechanism automatically performs
Flux.contextCapture()andMono.contextCapture()inFlux.blockFirst(),Flux.blockLast(),Flux.toIterable(), andMono.block()(and their overloads).- Since:
- 3.5.3
-
disableAutomaticContextPropagation
public static void disableAutomaticContextPropagation()Globally disables automatic context propagation toThreadLocals.- See Also:
-
isAutomaticContextPropagationEnabled
public static boolean isAutomaticContextPropagationEnabled()- Returns:
- true if automatic context propagation to
ThreadLocals is enabled, false otherwise - Since:
- 3.7.12
- See Also:
-
addReturnInfo
@Deprecated public static <T,P extends Publisher<T>> @Nullable Publisher<T> addReturnInfo(@Nullable P publisher, String method) Deprecated.Should only be used by the instrumentation, DOES NOT guarantee any compatibility -
addCallSiteInfo
@Deprecated public static <T,P extends Publisher<T>> @Nullable Publisher<T> addCallSiteInfo(@Nullable P publisher, String callSite) Deprecated.Should only be used by the instrumentation, DOES NOT guarantee any compatibility -
addQueueWrapper
Adds a wrapper for everyQueueused in Reactor. Note that it won't affect existing instances ofQueue. Hint: one may useAbstractQueueto reduce the number of methods to implement. -
removeQueueWrapper
Removes existingQueuewrapper by key.- See Also:
-
removeQueueWrappers
public static void removeQueueWrappers()Remove all queue wrappers. -
wrapQueue
Applies theQueuewrappers that were previously registered. SHOULD NOT change the behavior of the providedQueue.- Parameters:
queue- theQueueto wrap.- Returns:
- the result of applying
Queuewrappers registered withaddQueueWrapper(String, Function). - See Also:
-