Skip to content

Commit

Permalink
address review comment: rename get to getProviderForScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaypujare committed Nov 2, 2023
1 parent 40ce927 commit 1fd6923
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions api/src/main/java/io/grpc/ManagedChannelRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ ManagedChannelBuilder<?> newChannelBuilder(NameResolverRegistry nameResolverRegi
NameResolverProvider nameResolverProvider = null;
try {
URI uri = new URI(target);
nameResolverProvider = nameResolverRegistry.get(uri.getScheme());
nameResolverProvider = nameResolverRegistry.getProviderForScheme(uri.getScheme());
} catch (URISyntaxException ignore) {
// bad URI found, just ignore and continue
}
if (nameResolverProvider == null) {
nameResolverProvider = nameResolverRegistry.get(nameResolverRegistry.getDefaultScheme());
nameResolverProvider = nameResolverRegistry.getProviderForScheme(
nameResolverRegistry.getDefaultScheme());
}
Collection<Class<? extends SocketAddress>> nameResolverSocketAddressTypes
= (nameResolverProvider != null)
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/grpc/NameResolverRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public synchronized String getDefaultScheme() {
return defaultScheme;
}

public NameResolverProvider get(String scheme) {
public NameResolverProvider getProviderForScheme(String scheme) {
if (scheme == null) {
return null;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private final class NameResolverFactory extends NameResolver.Factory {
@Override
@Nullable
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
NameResolverProvider provider = get(targetUri.getScheme());
NameResolverProvider provider = getProviderForScheme(targetUri.getScheme());
return provider == null ? null : provider.newNameResolver(targetUri, args);
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,19 +722,19 @@ private static NameResolver getNameResolver(
if (targetUri != null) {
// For "localhost:8080" this would likely cause provider to be null, because "localhost" is
// parsed as the scheme. Will hit the next case and try "dns:///localhost:8080".
provider = nameResolverRegistry.get(targetUri.getScheme());
provider = nameResolverRegistry.getProviderForScheme(targetUri.getScheme());
}

if (provider == null && !URI_PATTERN.matcher(target).matches()) {
// It doesn't look like a URI target. Maybe it's an authority string. Try with the default
// scheme from the factory.
// scheme from the registry.
try {
targetUri = new URI(nameResolverRegistry.getDefaultScheme(), "", "/" + target, null);
} catch (URISyntaxException e) {
// Should not be possible.
throw new IllegalArgumentException(e);
}
provider = nameResolverRegistry.get(targetUri.getScheme());
provider = nameResolverRegistry.getProviderForScheme(targetUri.getScheme());
}

if (provider == null) {
Expand Down

0 comments on commit 1fd6923

Please sign in to comment.