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

api: When forwarding from Listener onAddresses to Listener2 continue to use onResult #11666

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/src/main/java/io/grpc/NameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ public abstract static class Listener2 implements Listener {
@Override
@Deprecated
@InlineMe(
replacement = "this.onResult2(ResolutionResult.newBuilder().setAddressesOrError("
replacement = "this.onResult(ResolutionResult.newBuilder().setAddressesOrError("
+ "StatusOr.fromValue(servers)).setAttributes(attributes).build())",
imports = {"io.grpc.NameResolver.ResolutionResult", "io.grpc.StatusOr"})
public final void onAddresses(
List<EquivalentAddressGroup> servers, @ResolutionResultAttr Attributes attributes) {
// TODO(jihuncho) need to promote Listener2 if we want to use ConfigOrError
onResult2(
// Calling onResult and not onResult2 because onResult2 can only be called from a
// synchronization context.
onResult(
ResolutionResult.newBuilder().setAddressesOrError(
StatusOr.fromValue(servers)).setAttributes(attributes).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,14 @@ public String getServiceAuthority() {

@Override
public void start(Listener2 listener) {
listener.onResult2(
ResolutionResult.newBuilder()
.setAddressesOrError(
StatusOr.fromValue(
Collections.singletonList(new EquivalentAddressGroup(address))))
.setAttributes(Attributes.EMPTY)
.build());
args.getSynchronizationContext().execute(() ->
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
listener.onResult2(
ResolutionResult.newBuilder()
.setAddressesOrError(
StatusOr.fromValue(
Collections.singletonList(new EquivalentAddressGroup(address))))
.setAttributes(Attributes.EMPTY)
.build()));
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion netty/src/main/java/io/grpc/netty/UdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
final class UdsNameResolver extends NameResolver {
private NameResolver.Listener2 listener;
private final String authority;
private final Args args;

UdsNameResolver(String authority, String targetPath, Args args) {
checkArgument(authority == null, "non-null authority not supported");
this.authority = targetPath;
this.args = args;
}

@Override
Expand All @@ -58,7 +60,8 @@ private void resolve() {
List<EquivalentAddressGroup> servers = new ArrayList<>(1);
servers.add(new EquivalentAddressGroup(new DomainSocketAddress(authority)));
resolutionResultBuilder.setAddressesOrError(StatusOr.fromValue(servers));
listener.onResult2(resolutionResultBuilder.build());
args.getSynchronizationContext().execute(() ->
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
listener.onResult2(resolutionResultBuilder.build()));
}

@Override
Expand Down