-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Introduce NameResolver.Args.Extensions #11669
base: master
Are you sure you want to change the base?
Conversation
Friendly 1 week ping. This is the domain-specific Key<>-based approach you requested in our last meeting. |
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.
I like how Extensions was implemented to avoid copying the map on build().
* | ||
* <p>Optional, {@link Extensions#EMPTY} by default. | ||
*/ | ||
public Builder setExtensions(Extensions extensions) { |
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.
Hmmm... This makes Extensions
public, and you have to set all Extensions for this builder but reading gets only a single one. I see the awkwardness is because we're going through the ManagedChannelBuilder API. I'm tempted to just use a map in the channel builder and copy it to this API later.
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.
Completely removed Extensions from the public API (it's now @internal)
I tried maintaining a map in ManagedChannelImplBuilder but the code to copy entries over was problematic because 1) one more place needing unchecked casts 2) it's doing work that's best encapsulated and unit tested inside Args.Extensions.
I also tried out moving the NameResolver.Args.Builder to ManagedChannelImplBuilder. This worked but only because the current ManagedChannelImpl ctor unconditionally sets every property of Args.Builder. This is fragile - if this code ever changed to conditionally set a property it would silently leak that property across channels when the builder is reused. This seemed too fragile to me.
|
||
private IdentityHashMap<Key<?>, Object> data(int size) { | ||
if (newdata == null) { | ||
newdata = new IdentityHashMap<>(size); |
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.
Would it be nicer to copy base at this point:
newdata = new IdentityHashMap<>(base.data);
Yes, you're doing the sizing of the map here, but that size is pretty arbitrary. If we care:
newdata = new IdentityHashMap<>(base.data.size() + 1);
newdata.putAll(base.data);
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.
Hmm seems like that could work but for me it really muddies the meaning/invariant of 'base' and 'newdata'. Anyway, I just copy/pasted all this from Attributes. Seems to me like the idea is to do all the copying in one place, in build(). Does that change anything for you? Should we consider your proposed change for Attributes too?
Fully remove Args.Extensions from the public API (@internal) Make TODO non-javadoc google-java-format unused imports
👍 I can't take credit though, just copy pasted from Attributes. LMK if you think one of the other special-purpose containers would be a better fit. |
Update NameResolverTest. Include setAll() coverage
grpc-binder's upcoming
IntentNameResolver
needs to know the target Android user so it can resolve target URIs in the correct place. Unfortunately, Android's built in intent:// URI scheme has no way to specify a user and in fact theandroid.os.UserHandle
object can't reasonably be encoded as a String at all.We solve this problem by extending
NameResolver.Args
to permit externally defined arguments using the same type-safe and domain-specificKey<T>
pattern used byCallOptions
,Context
andCreateSubchannelArgs
. New "extension" arguments could apply to all NameResolvers of a certain URI scheme, to all NameResolvers producing a particular type ofjava.net.SocketAddress
, or even to a specificNameResolver
subclass.A follow up PR will move the target
UserHandle
from being a property of theManagedChannel
to being a property of theSocketAddress
.