-
Notifications
You must be signed in to change notification settings - Fork 181
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
Add ContextMaps
to let users create various ContextMap
s
#2906
base: main
Are you sure you want to change the base?
Conversation
Motivation: If we plan to use `ContextMap` for more and more use-cases as a strictly typed variant of a `Map`, we need to open a way to create various versions of the `ContextMap`. Modifications: - Add `ContextMaps` utility class; - Add `SingletonContextMap` and `UnmodifiableContextMap`; - Move `NoopAsyncContextProvider.NoopContextMap` to `EmptyContextMap`; - Move `ConcurrentContextMap` and `CopyOnWriteContextMap` to context-api; - Copy `io.servicetalk.concurrent.internal.DefaultContextMap` to `io.servicetalk.context.api.DefaultContextMap`; - Deprecate `io.servicetalk.concurrent.internal.DefaultContextMap`; - Copy `io.servicetalk.concurrent.internal.ContextMapUtils` to `io.servicetalk.context.api.ContextMapUtils`; - Deprecate `io.servicetalk.concurrent.internal.ContextMapUtils`; Result: New public API to create various `ContextMap`s.
10580c3
to
b69e976
Compare
I don't like the idea of introducing a new unmodifiable context map: it's not really the same notion as regular context map because all the set operations don't work and then all the places you currently consume context map you'll have to start wondering if it's going to throw if you try to modify it. |
Is it not the same for Alternatively, we can keep the The main purpose of this PR is to provide public API to create |
It is the same for
I appreciate the strong type extraction based on the key, but in the case of meta-data I don't like the strong instance based coupling that
That gets us back to the difficulty of having a |
I haven't seen many cases when it was a problem for the
That was a design decision for
Can you elaborate what is the difficulty? |
Much of this is perhaps a moot point as I'm starting to think that maybe we don't need meta-data at all, but in case we change our minds here it is.
Fair enough. I've seen a number of cases where either trying to mutate threw exceptions or someone mutated a map they shouldn't have (someone forgot to make it unmodifiable) and it made something else sad (much harder to track down). Admittedly my opinion of it is largely influenced by Scala where there are mutable and immutable collections which made it really easy to reason about and prevent these types of problems at compile time. Java just doesn't have this in the standard library so I suppose people just have to get used to relying on convention instead of tooling.
To be clear, in general I really like the instance based coupling of abstractions like
For sure. Lets say we want to preserve the API of
|
Depending on how we would like to define meta-data. If we say in its javadoc that it's immutable, then we return |
This wont work. Let's say there is a filter that wants to set a meta-data entry. When it calls |
Hm, that's a good point. Then it's better to either use |
Motivation:
If we plan to use
ContextMap
for more and more use-cases as a strictly typed variant of aMap
, we need to open a way to create various versions of theContextMap
.Modifications:
ContextMaps
utility class;SingletonContextMap
andUnmodifiableContextMap
;NoopAsyncContextProvider.NoopContextMap
toEmptyContextMap
;ConcurrentContextMap
andCopyOnWriteContextMap
to context-api;io.servicetalk.concurrent.internal.DefaultContextMap
toio.servicetalk.context.api.DefaultContextMap
;io.servicetalk.concurrent.internal.DefaultContextMap
;io.servicetalk.concurrent.internal.ContextMapUtils
toio.servicetalk.context.api.ContextMapUtils
;io.servicetalk.concurrent.internal.ContextMapUtils
;Result:
New public API to create various
ContextMap
s.