Skip to content

Commit 9a81cad

Browse files
authored
core: switch to LBv2 as the default. (grpc#2707)
1 parent 48e1430 commit 9a81cad

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

‎core/src/main/java/io/grpc/ManagedChannelBuilder.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
161161
* for the channel.
162162
*
163163
* <p>This overrides what was set by {@link #loadBalancerFactory(LoadBalancer2.Factory)}.
164+
*
165+
* <p>Calling this will revert the channel back to the original (LBv1) implementation.
164166
*/
165167
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
166168
public abstract T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory);
@@ -173,13 +175,11 @@ public static ManagedChannelBuilder<?> forTarget(String target) {
173175
*
174176
* <p>This overrides what was set by {@link #loadBalancerFactory(LoadBalancer.Factory)}.
175177
*
176-
* <p><strong>IMPORTANT: </strong>Calling this will make the channel to run the LBv2 code path,
177-
* which is new and not as well-exercised as the current one. You should use it only if you want
178-
* to try out LBv2, or you are migrating your LoadBalancer implementation to LBv2. See
179-
* <a href="https://github.com/grpc/grpc-java/issues/2656" for more
178+
* <p>Calling this will make the channel to run the LBv2 code path. See <a
179+
* href="https://github.com/grpc/grpc-java/issues/2656" for more
180180
* information.
181181
*
182-
* <p><strong>IMPORTANT: </strong>This method is implemented by all stock channel builders that
182+
* <p>This method is implemented by all stock channel builders that
183183
* are shipped with gRPC, but may not be implemented by custom channel builders, in which case
184184
* this method will throw.
185185
*/

‎core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import io.grpc.ManagedChannelBuilder;
5050
import io.grpc.NameResolver;
5151
import io.grpc.NameResolverProvider;
52-
import io.grpc.PickFirstBalancerFactory;
52+
import io.grpc.PickFirstBalancerFactory2;
5353
import io.grpc.ResolvedServerInfo;
5454
import io.grpc.ResolvedServerInfoGroup;
5555
import java.net.SocketAddress;
@@ -109,7 +109,7 @@ public abstract class AbstractManagedChannelImplBuilder
109109
@Nullable
110110
private NameResolver.Factory nameResolverFactory;
111111

112-
private LoadBalancer.Factory loadBalancerFactory;
112+
private LoadBalancer2.Factory loadBalancerFactory;
113113

114114
@Nullable
115115
private ChannelFactory channelFactory;
@@ -197,7 +197,7 @@ public final T nameResolverFactory(NameResolver.Factory resolverFactory) {
197197
}
198198

199199
@Override
200-
public final T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory) {
200+
public final T loadBalancerFactory(LoadBalancer2.Factory loadBalancerFactory) {
201201
Preconditions.checkState(directServerAddress == null,
202202
"directServerAddress is set (%s), which forbids the use of LoadBalancerFactory",
203203
directServerAddress);
@@ -207,14 +207,14 @@ public final T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory) {
207207
}
208208

209209
@Override
210-
public final T loadBalancerFactory(final LoadBalancer2.Factory loadBalancerFactory) {
210+
public final T loadBalancerFactory(final LoadBalancer.Factory loadBalancerFactory) {
211211
Preconditions.checkState(directServerAddress == null,
212212
"directServerAddress is set (%s), which forbids the use of LoadBalancerFactory",
213213
directServerAddress);
214214
this.channelFactory = new ChannelFactory() {
215215
@Override
216216
public ManagedChannel create(ClientTransportFactory transportFactory) {
217-
return new ManagedChannelImpl2(
217+
return new ManagedChannelImpl(
218218
target,
219219
// TODO(carl-mastrangelo): Allow clients to pass this in
220220
new ExponentialBackoffPolicy.Provider(),
@@ -224,12 +224,10 @@ public ManagedChannel create(ClientTransportFactory transportFactory) {
224224
transportFactory,
225225
firstNonNull(decompressorRegistry, DecompressorRegistry.getDefaultInstance()),
226226
firstNonNull(compressorRegistry, CompressorRegistry.getDefaultInstance()),
227-
SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE),
228-
getExecutorPool(executor),
229-
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR),
230-
GrpcUtil.STOPWATCH_SUPPLIER, idleTimeoutMillis,
231-
userAgent, interceptors, firstNonNull(statsFactory,
232-
firstNonNull(Stats.getStatsContextFactory(), NoopStatsContextFactory.INSTANCE)));
227+
GrpcUtil.TIMER_SERVICE, GrpcUtil.STOPWATCH_SUPPLIER, idleTimeoutMillis,
228+
executor, userAgent, interceptors,
229+
firstNonNull(statsFactory,
230+
firstNonNull(Stats.getStatsContextFactory(), NoopStatsContextFactory.INSTANCE)));
233231
}
234232
};
235233
return thisT();
@@ -312,19 +310,21 @@ public ManagedChannel build() {
312310
if (channelFactory != null) {
313311
return channelFactory.create(transportFactory);
314312
} else {
315-
return new ManagedChannelImpl(
313+
return new ManagedChannelImpl2(
316314
target,
317315
// TODO(carl-mastrangelo): Allow clients to pass this in
318316
new ExponentialBackoffPolicy.Provider(),
319317
nameResolverFactory,
320318
getNameResolverParams(),
321-
firstNonNull(loadBalancerFactory, PickFirstBalancerFactory.getInstance()),
319+
firstNonNull(loadBalancerFactory, PickFirstBalancerFactory2.getInstance()),
322320
transportFactory,
323321
firstNonNull(decompressorRegistry, DecompressorRegistry.getDefaultInstance()),
324322
firstNonNull(compressorRegistry, CompressorRegistry.getDefaultInstance()),
325-
GrpcUtil.TIMER_SERVICE, GrpcUtil.STOPWATCH_SUPPLIER, idleTimeoutMillis,
326-
executor, userAgent, interceptors,
327-
firstNonNull(statsFactory,
323+
SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE),
324+
getExecutorPool(executor),
325+
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR),
326+
GrpcUtil.STOPWATCH_SUPPLIER, idleTimeoutMillis,
327+
userAgent, interceptors, firstNonNull(statsFactory,
328328
firstNonNull(Stats.getStatsContextFactory(), NoopStatsContextFactory.INSTANCE)));
329329
}
330330
}
@@ -431,9 +431,9 @@ private T thisT() {
431431
}
432432

433433
/**
434-
* A temporary solution to contain the reference to ManagedChannelImpl2 in the v2 LoadBalancer
435-
* setter, so that on Android ManagedChannelImpl2 can be stripped out by ProGuard since the v2
436-
* setter will not be called. This should be deleted along with the old ManagedChannelImpl.
434+
* A temporary solution to contain the reference to ManagedChannelImpl in the v1 LoadBalancer
435+
* setter, so that on Android ManagedChannelImpl can be stripped out by ProGuard since the v1
436+
* setter will not be called. This should be deleted along with v1 ManagedChannelImpl.
437437
*/
438438
private interface ChannelFactory {
439439
ManagedChannel create(ClientTransportFactory transportFactory);

0 commit comments

Comments
 (0)