-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace trac(k)ing abstract with more generic context tracking #1495
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2018-Present Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.core.publisher; | ||
|
||
import reactor.core.Disposable; | ||
import reactor.core.Disposables; | ||
import reactor.util.annotation.NonNull; | ||
import reactor.util.context.Context; | ||
|
||
/** | ||
* A set of callbacks to track the {@link Context} propagation inside a reactive execution | ||
* chain. | ||
* | ||
* @author Sergei Egorov | ||
* @since 3.2.6 | ||
*/ | ||
public interface ContextTracker { | ||
|
||
/** | ||
* A callback to be triggered on the subscription. | ||
* Implementors should return a new, enriched {@link Context} (see {@link Context#put(Object, Object)}), | ||
* or the same context if the tracking is not desired. | ||
* <p> | ||
* Example implementation: | ||
* <pre>{@code | ||
* if (!shouldTrack()) return context; | ||
* Marker parent = context.getOrDefault(Marker.class, null); | ||
* Marker marker = new Marker(parent); | ||
* return context.put(Marker.class, marker); | ||
* }</pre> | ||
* | ||
* @param context the {@link Context} of {@link reactor.core.CoreSubscriber} | ||
* @see reactor.core.CoreSubscriber | ||
* @return modified or the same {@link Context} | ||
*/ | ||
@NonNull | ||
Context onSubscribe(Context context); | ||
|
||
/** | ||
* {@link ContextTracker} implementors receive this callback before | ||
* the {@link reactor.core.scheduler.Scheduler}s execute scheduled {@link Runnable}s. | ||
* <p> | ||
* Consider implementing it if your tracking relies on {@link ThreadLocal}s. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe flesh out this sentence: the method would extract key-value pairs from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most tracers use But I like the idea of guiding how to implement it, will add 👍 |
||
* | ||
* @param context the current {@link Context} | ||
* @return {@link Disposable} to be disposed after the scheduled {@link Runnable} | ||
*/ | ||
default Disposable onContextPassing(Context context) { | ||
return Disposables.disposed(); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snippet still references
Marker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an example,
Marker
is something provided by the implementation