Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

jdcormie
Copy link
Member

@jdcormie jdcormie commented Nov 6, 2024

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 the android.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-specific Key<T> pattern used by CallOptions, Context and CreateSubchannelArgs. New "extension" arguments could apply to all NameResolvers of a certain URI scheme, to all NameResolvers producing a particular type of java.net.SocketAddress, or even to a specific NameResolver subclass.

A follow up PR will move the target UserHandle from being a property of the ManagedChannel to being a property of the SocketAddress.

@jdcormie jdcormie requested a review from ejona86 November 6, 2024 04:52
@jdcormie jdcormie added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Nov 8, 2024
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Nov 8, 2024
@jdcormie
Copy link
Member Author

Friendly 1 week ping. This is the domain-specific Key<>-based approach you requested in our last meeting.

Copy link
Member

@ejona86 ejona86 left a 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().

}

/**
* The port number used in case the target or the underlying naming system doesn't provide a
* port number.
*
* <p>TODO: Only meaningful for InetSocketAddress producers. Move to {@link Extensions}?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this as a // comment, not a javadoc one?

/**
* Gets the value of an extended arg by key, or {@code null} if it's not set.
*/
@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the warning suppression? Extensions.get() does the cast; there's none here.

*
* <p>Optional, {@link Extensions#EMPTY} by default.
*/
public Builder setExtensions(Extensions extensions) {
Copy link
Member

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.

* <p>Optional, {@link Extensions#EMPTY} by default.
*/
public Builder setExtensions(Extensions extensions) {
this.extensions = extensions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkNotNull


private IdentityHashMap<Key<?>, Object> data(int size) {
if (newdata == null) {
newdata = new IdentityHashMap<>(size);
Copy link
Member

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);

this.channelLogger = channelLogger;
this.executor = executor;
this.overrideAuthority = overrideAuthority;
private Args(Builder builder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it needed this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants