|
1 | 1 | /*
|
2 |
| - * Copyright 2020 The gRPC Authors |
| 2 | + * Copyright 2023 The gRPC Authors |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -package io.grpc.internal; |
| 17 | +package io.grpc; |
18 | 18 |
|
19 | 19 | import com.google.common.base.MoreObjects;
|
20 |
| -import com.google.common.base.Preconditions; |
21 | 20 | import com.google.errorprone.annotations.DoNotCall;
|
22 |
| -import io.grpc.BinaryLog; |
23 |
| -import io.grpc.ClientInterceptor; |
24 |
| -import io.grpc.CompressorRegistry; |
25 |
| -import io.grpc.DecompressorRegistry; |
26 |
| -import io.grpc.ManagedChannel; |
27 |
| -import io.grpc.ManagedChannelBuilder; |
28 |
| -import io.grpc.NameResolver; |
29 |
| -import io.grpc.ProxyDetector; |
30 | 21 | import java.util.List;
|
31 | 22 | import java.util.Map;
|
32 | 23 | import java.util.concurrent.Executor;
|
33 | 24 | import java.util.concurrent.TimeUnit;
|
34 | 25 | import javax.annotation.Nullable;
|
35 | 26 |
|
36 | 27 | /**
|
37 |
| - * Temporarily duplicates {@link io.grpc.ForwardingChannelBuilder} to fix ABI backward |
38 |
| - * compatibility. |
| 28 | + * A {@link ManagedChannelBuilder} that delegates all its builder methods to another builder by |
| 29 | + * default. |
39 | 30 | *
|
40 |
| - * @param <T> The concrete type of this builder. |
41 |
| - * @see <a href="https://github.com/grpc/grpc-java/issues/7211">grpc/grpc-java#7211</a> |
| 31 | + * <p>Always choose this over {@link ForwardingChannelBuilder}, because |
| 32 | + * {@link ForwardingChannelBuilder2} is ABI-safe. |
| 33 | + * |
| 34 | + * @param <T> The type of the subclass extending this abstract class. |
| 35 | + * @since 1.59.0 |
42 | 36 | */
|
43 |
| -public abstract class AbstractManagedChannelImplBuilder |
44 |
| - <T extends AbstractManagedChannelImplBuilder<T>> extends ManagedChannelBuilder<T> { |
45 |
| - |
46 |
| - /** |
47 |
| - * Added for ABI compatibility. |
48 |
| - * |
49 |
| - * <p>See details in {@link #maxInboundMessageSize(int)}. |
50 |
| - * TODO(sergiitk): move back to concrete classes as a private field, when this class is removed. |
51 |
| - */ |
52 |
| - protected int maxInboundMessageSize = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE; |
| 37 | +@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10585") |
| 38 | +public abstract class ForwardingChannelBuilder2<T extends ManagedChannelBuilder<T>> |
| 39 | + extends ManagedChannelBuilder<T> { |
53 | 40 |
|
54 | 41 | /**
|
55 | 42 | * The default constructor.
|
56 | 43 | */
|
57 |
| - protected AbstractManagedChannelImplBuilder() {} |
| 44 | + protected ForwardingChannelBuilder2() { |
| 45 | + } |
58 | 46 |
|
59 | 47 | /**
|
60 |
| - * This method serves to force sub classes to "hide" this static factory. |
| 48 | + * This method serves to force subclasses to "hide" this static factory. |
61 | 49 | */
|
62 | 50 | @DoNotCall("Unsupported")
|
63 | 51 | public static ManagedChannelBuilder<?> forAddress(String name, int port) {
|
64 | 52 | throw new UnsupportedOperationException("Subclass failed to hide static factory");
|
65 | 53 | }
|
66 | 54 |
|
67 | 55 | /**
|
68 |
| - * This method serves to force sub classes to "hide" this static factory. |
| 56 | + * This method serves to force subclasses to "hide" this static factory. |
69 | 57 | */
|
70 | 58 | @DoNotCall("Unsupported")
|
71 | 59 | public static ManagedChannelBuilder<?> forTarget(String target) {
|
@@ -170,31 +158,7 @@ public T idleTimeout(long value, TimeUnit unit) {
|
170 | 158 |
|
171 | 159 | @Override
|
172 | 160 | public T maxInboundMessageSize(int max) {
|
173 |
| - /* |
174 |
| - Why this method is not delegating, as the rest of the methods? |
175 |
| -
|
176 |
| - In refactoring described in #7211, the implementation of #maxInboundMessageSize(int) |
177 |
| - (and its corresponding field) was pulled down from internal AbstractManagedChannelImplBuilder |
178 |
| - to concrete classes that actually enforce this setting. For the same reason, it wasn't ported |
179 |
| - to ManagedChannelImplBuilder (the #delegate()). |
180 |
| -
|
181 |
| - Then AbstractManagedChannelImplBuilder was brought back to fix ABI backward compatibility, |
182 |
| - and temporarily turned into a ForwardingChannelBuilder, ref PR #7564. Eventually it will |
183 |
| - be deleted, after a period with "bridge" ABI solution introduced in #7834. |
184 |
| -
|
185 |
| - However, restoring AbstractManagedChannelImplBuilder unintentionally made ABI of |
186 |
| - #maxInboundMessageSize(int) implemented by the concrete classes backward incompatible: |
187 |
| - pre-refactoring builds expect it to be a method of AbstractManagedChannelImplBuilder, |
188 |
| - and not concrete classes, ref #8313. |
189 |
| -
|
190 |
| - The end goal is to keep #maxInboundMessageSize(int) only in concrete classes that enforce it. |
191 |
| - To fix method's ABI, we temporary reintroduce it to the original layer it was removed from: |
192 |
| - AbstractManagedChannelImplBuilder. This class' only intention is to provide short-term |
193 |
| - ABI compatibility. Once we move forward with dropping the ABI, both fixes are no longer |
194 |
| - necessary, and both will perish with removing AbstractManagedChannelImplBuilder. |
195 |
| - */ |
196 |
| - Preconditions.checkArgument(max >= 0, "negative max"); |
197 |
| - maxInboundMessageSize = max; |
| 161 | + delegate().maxInboundMessageSize(max); |
198 | 162 | return thisT();
|
199 | 163 | }
|
200 | 164 |
|
@@ -305,7 +269,7 @@ public String toString() {
|
305 | 269 | /**
|
306 | 270 | * Returns the correctly typed version of the builder.
|
307 | 271 | */
|
308 |
| - protected final T thisT() { |
| 272 | + private T thisT() { |
309 | 273 | @SuppressWarnings("unchecked")
|
310 | 274 | T thisT = (T) this;
|
311 | 275 | return thisT;
|
|
0 commit comments