Skip to content

Commit

Permalink
Emulate AbstractManagedChannelImplBuilder maxInboundMessageSize(int)
Browse files Browse the repository at this point in the history
In dbd903c we started generatating AbstractManagedChannelImplBuilder
methods in a way that they are present for ABI but on recompilation only
public ManagedChannelBuilder-returning methods would be used. However,
this sorta missed maxInboundMessageSize which is now being handled by
the concrete classes (e.g, NettyChannelBuilder) instead of
ManagedChannelImplBuilder. Users on the old ABI will end up getting
ManagedChannelImplBuilder.maxInboundMessageSize() which does nothing.

So, let's just implement the method and have it jump back up to the
concrete class. Hacky, but easy and predictable and will go away once we
remove the rest of the AbstractManagedChannelImplBuilder compatibility
hacks.

Fixes grpc#8313
  • Loading branch information
ejona86 committed Oct 13, 2021
1 parent 9266174 commit 6790323
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java
Expand Up @@ -707,6 +707,28 @@ int getDefaultPort() {
return channelBuilderDefaultPortProvider.getDefaultPort();
}

// Remove this emulation when we delete AbstractManagedChannelImplBuilder
private AbstractManagedChannelImplBuilderEmulator abstractManagedChannelImplBuilderEmulator;

public interface AbstractManagedChannelImplBuilderEmulator {
void maxInboundMessageSize(int max);
}

public void emulateAbstractManagedChannelImplBuilder(
AbstractManagedChannelImplBuilderEmulator abstractManagedChannelImplBuilderEmulator) {
this.abstractManagedChannelImplBuilderEmulator = abstractManagedChannelImplBuilderEmulator;
}

@Override
public ManagedChannelImplBuilder maxInboundMessageSize(int max) {
if (abstractManagedChannelImplBuilderEmulator != null) {
abstractManagedChannelImplBuilderEmulator.maxInboundMessageSize(max);
return this;
} else {
return super.maxInboundMessageSize(max); // noop
}
}

private static class DirectAddressNameResolverFactory extends NameResolver.Factory {
final SocketAddress address;
final String authority;
Expand Down
11 changes: 11 additions & 0 deletions netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java
Expand Up @@ -201,6 +201,7 @@ public int getDefaultPort() {
managedChannelImplBuilder = new ManagedChannelImplBuilder(target,
new NettyChannelTransportFactoryBuilder(),
new NettyChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.freezeProtocolNegotiatorFactory = false;
}

Expand All @@ -211,6 +212,7 @@ public int getDefaultPort() {
target, channelCreds, callCreds,
new NettyChannelTransportFactoryBuilder(),
new NettyChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.protocolNegotiatorFactory = checkNotNull(negotiator, "negotiator");
this.freezeProtocolNegotiatorFactory = true;
}
Expand All @@ -221,6 +223,7 @@ public int getDefaultPort() {
getAuthorityFromAddress(address),
new NettyChannelTransportFactoryBuilder(),
new NettyChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.freezeProtocolNegotiatorFactory = false;
}

Expand All @@ -232,6 +235,7 @@ public int getDefaultPort() {
channelCreds, callCreds,
new NettyChannelTransportFactoryBuilder(),
new NettyChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.protocolNegotiatorFactory = checkNotNull(negotiator, "negotiator");
this.freezeProtocolNegotiatorFactory = true;
}
Expand Down Expand Up @@ -764,4 +768,11 @@ public void close() {
groupPool.returnObject(group);
}
}

private final class OldBuilderEmulator implements
ManagedChannelImplBuilder.AbstractManagedChannelImplBuilderEmulator {
@Override public void maxInboundMessageSize(int max) {
NettyChannelBuilder.this.maxInboundMessageSize(max);
}
}
}
9 changes: 9 additions & 0 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java
Expand Up @@ -191,6 +191,7 @@ private OkHttpChannelBuilder(String target) {
managedChannelImplBuilder = new ManagedChannelImplBuilder(target,
new OkHttpChannelTransportFactoryBuilder(),
new OkHttpChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.freezeSecurityConfiguration = false;
}

Expand All @@ -201,6 +202,7 @@ private OkHttpChannelBuilder(String target) {
target, channelCreds, callCreds,
new OkHttpChannelTransportFactoryBuilder(),
new OkHttpChannelDefaultPortProvider());
managedChannelImplBuilder.emulateAbstractManagedChannelImplBuilder(new OldBuilderEmulator());
this.sslSocketFactory = factory;
this.negotiationType = factory == null ? NegotiationType.PLAINTEXT : NegotiationType.TLS;
this.freezeSecurityConfiguration = true;
Expand Down Expand Up @@ -830,4 +832,11 @@ public void close() {
}
}
}

private final class OldBuilderEmulator implements
ManagedChannelImplBuilder.AbstractManagedChannelImplBuilderEmulator {
@Override public void maxInboundMessageSize(int max) {
OkHttpChannelBuilder.this.maxInboundMessageSize(max);
}
}
}

0 comments on commit 6790323

Please sign in to comment.