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

core: Deprecate ForwardingChannelBuilder #10587

Merged
merged 11 commits into from
Nov 2, 2023
4 changes: 2 additions & 2 deletions alts/src/main/java/io/grpc/alts/AltsChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.common.annotations.VisibleForTesting;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.GrpcUtil;
Expand All @@ -32,7 +32,7 @@
* commmunication between two cloud VMs using ALTS.
*/
@ExperimentalApi("/~https://github.com/grpc/grpc-java/issues/4151")
public final class AltsChannelBuilder extends ForwardingChannelBuilder<AltsChannelBuilder> {
public final class AltsChannelBuilder extends ForwardingChannelBuilder2<AltsChannelBuilder> {
private final NettyChannelBuilder delegate;
private final AltsChannelCredentials.Builder credentialsBuilder =
new AltsChannelCredentials.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static ComputeEngineChannelBuilder forAddress(String name, int port) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected NettyChannelBuilder delegate() {
return delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static GoogleDefaultChannelBuilder forAddress(String name, int port) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected NettyChannelBuilder delegate() {
return delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public AndroidChannelBuilder context(Context context) {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected ManagedChannelBuilder<?> delegate() {
return delegateBuilder;
}
Expand Down
21 changes: 18 additions & 3 deletions api/src/main/java/io/grpc/ForwardingChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* A {@link ManagedChannelBuilder} that delegates all its builder methods to another builder by
* default.
*
* <p>Important! Use {@link ForwardingChannelBuilder2} instead!
* <p>DEPRECATED: Use {@link ForwardingChannelBuilder2} instead!
*
* <p>This class mistakenly used {@code <T extends ForwardingChannelBuilder<T>>} which causes
* return types to be {@link ForwardingChannelBuilder} instead of {@link ManagedChannelBuilder}.
Expand All @@ -38,14 +38,29 @@
*/
public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>
extends ForwardingChannelBuilder2<T> {
// TODO(sergiitk): deprecate after stabilizing

/**
* The default constructor.
*/
protected ForwardingChannelBuilder() {
}


/**
* Returns the delegated {@code ManagedChannelBuilder}.
*
* <p>NOTE: this method is marked deprecated instead the class itself, so that classes extending
* {@link ForwardingChannelBuilder2} won't need class-level
* {@code @SuppressWarnings("deprecation")} annotation. Such annotation would suppress all
* deprecation warnings in all methods, inadvertently hiding any real deprecation warnings needing
* to be addressed. However, each child class is expected to implement {@code delegate()}.
* Therefore, the {@code @Deprecated} annotation is added to this method, and not to the class.
*
* @deprecated As of 1.60.0, use {@link ForwardingChannelBuilder2} instead.
*/
@Override
@Deprecated
protected abstract ManagedChannelBuilder<?> delegate();

@Override
public T directExecutor() {
delegate().directExecutor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ForwardingChannelBuilderTest {

private final class TestBuilder extends ForwardingChannelBuilder<TestBuilder> {
@Override
@SuppressWarnings("deprecation")
protected ManagedChannelBuilder<?> delegate() {
return mockDelegate;
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/test/java/io/grpc/ManagedChannelRegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public NewChannelBuilderResult newChannelBuilder(
return NewChannelBuilderResult.error("dodging");
}
});
class MockChannelBuilder extends ForwardingChannelBuilder<MockChannelBuilder> {
class MockChannelBuilder extends ForwardingChannelBuilder2<MockChannelBuilder> {
@Override public ManagedChannelBuilder<?> delegate() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public NewChannelBuilderResult newChannelBuilder(
throw new AssertionError();
}
});
class MockChannelBuilder extends ForwardingChannelBuilder<MockChannelBuilder> {
class MockChannelBuilder extends ForwardingChannelBuilder2<MockChannelBuilder> {
@Override public ManagedChannelBuilder<?> delegate() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public void newChannelBuilder_emptySet_asDefault() {
NameResolverRegistry nameResolverRegistry = new NameResolverRegistry();

ManagedChannelRegistry registry = new ManagedChannelRegistry();
class MockChannelBuilder extends ForwardingChannelBuilder<MockChannelBuilder> {
class MockChannelBuilder extends ForwardingChannelBuilder2<MockChannelBuilder> {
@Override public ManagedChannelBuilder<?> delegate() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -320,7 +320,7 @@ protected Collection<Class<? extends SocketAddress>> getProducedSocketAddressTyp
});

ManagedChannelRegistry registry = new ManagedChannelRegistry();
class MockChannelBuilder extends ForwardingChannelBuilder<MockChannelBuilder> {
class MockChannelBuilder extends ForwardingChannelBuilder2<MockChannelBuilder> {
@Override public ManagedChannelBuilder<?> delegate() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -351,7 +351,7 @@ class SocketAddress1 extends SocketAddress {

ManagedChannelRegistry registry = new ManagedChannelRegistry();

class MockChannelBuilder extends ForwardingChannelBuilder<MockChannelBuilder> {
class MockChannelBuilder extends ForwardingChannelBuilder2<MockChannelBuilder> {
@Override public ManagedChannelBuilder<?> delegate() {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public ClientTransportFactory buildClientTransportFactory() {
}

@Override
@SuppressWarnings("deprecation") // Not extending ForwardingChannelBuilder2 to preserve ABI.
protected ManagedChannelBuilder<?> delegate() {
return managedChannelImplBuilder;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import io.grpc.Deadline;
import io.grpc.DecompressorRegistry;
import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.ForwardingClientCall;
import io.grpc.Grpc;
import io.grpc.InternalChannelz;
Expand Down Expand Up @@ -1593,7 +1593,7 @@ public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(
checkNotNull(channelCreds, "channelCreds");

final class ResolvingOobChannelBuilder
extends ForwardingChannelBuilder<ResolvingOobChannelBuilder> {
extends ForwardingChannelBuilder2<ResolvingOobChannelBuilder> {
final ManagedChannelBuilder<?> delegate;

ResolvingOobChannelBuilder() {
Expand Down
4 changes: 2 additions & 2 deletions rls/src/test/java/io/grpc/rls/CachingRlsLbClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import io.grpc.ChannelLogger;
import io.grpc.ConnectivityState;
import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickResult;
Expand Down Expand Up @@ -817,7 +817,7 @@ public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(
final InProcessChannelBuilder builder =
InProcessChannelBuilder.forName(target).directExecutor();

class CleaningChannelBuilder extends ForwardingChannelBuilder<CleaningChannelBuilder> {
class CleaningChannelBuilder extends ForwardingChannelBuilder2<CleaningChannelBuilder> {

@Override
protected ManagedChannelBuilder<?> delegate() {
Expand Down
4 changes: 2 additions & 2 deletions rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.grpc.ConnectivityState;
import io.grpc.ConnectivityStateInfo;
import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickResult;
Expand Down Expand Up @@ -519,7 +519,7 @@ public ManagedChannelBuilder<?> createResolvingOobChannelBuilder(
final InProcessChannelBuilder builder =
InProcessChannelBuilder.forName(target).directExecutor();

class CleaningChannelBuilder extends ForwardingChannelBuilder<CleaningChannelBuilder> {
class CleaningChannelBuilder extends ForwardingChannelBuilder2<CleaningChannelBuilder> {

@Override
protected ManagedChannelBuilder<?> delegate() {
Expand Down