Skip to content

Commit 367640e

Browse files
committed
fix: refactor from ChildChannelConfigurer to ChannelConfigurer
1 parent 374cbdf commit 367640e

26 files changed

Lines changed: 127 additions & 135 deletions

api/src/main/java/io/grpc/ChildChannelConfigurer.java renamed to api/src/main/java/io/grpc/ChannelConfigurer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
* <p><strong>Usage Example:</strong>
3333
* <pre>{@code
3434
* // 1. Define the configurer
35-
* ChildChannelConfigurer configurer = builder -> {
36-
* builder.intercept(new MyAuthInterceptor());
35+
* ChannelConfigurer configurer = builder -> {
3736
* builder.maxInboundMessageSize(4 * 1024 * 1024);
3837
* };
3938
*
@@ -47,10 +46,10 @@
4746
* <p>Implementations must be thread-safe as the configure methods may be invoked concurrently
4847
* by multiple internal components.
4948
*
50-
* @since 1.79.0
49+
* @since 1.81.0
5150
*/
5251
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574")
53-
public interface ChildChannelConfigurer {
52+
public interface ChannelConfigurer {
5453

5554
/**
5655
* Configures a builder for a new child channel.

api/src/main/java/io/grpc/ForwardingChannelBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ public T disableServiceConfigLookUp() {
244244

245245

246246
@Override
247-
public T childChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
248-
delegate().childChannelConfigurer(childChannelConfigurer);
247+
public T childChannelConfigurer(ChannelConfigurer channelConfigurer) {
248+
delegate().childChannelConfigurer(channelConfigurer);
249249
return thisT();
250250
}
251251

api/src/main/java/io/grpc/ForwardingChannelBuilder2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public T intercept(ClientInterceptor... interceptors) {
9595
}
9696

9797
@Override
98-
public T interceptWithTarget(InterceptorFactory factory) {
98+
protected T interceptWithTarget(InterceptorFactory factory) {
9999
delegate().interceptWithTarget(factory);
100100
return thisT();
101101
}
@@ -271,8 +271,8 @@ public <X> T setNameResolverArg(NameResolver.Args.Key<X> key, X value) {
271271

272272

273273
@Override
274-
public T childChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
275-
delegate().childChannelConfigurer(childChannelConfigurer);
274+
public T childChannelConfigurer(ChannelConfigurer channelConfigurer) {
275+
delegate().childChannelConfigurer(channelConfigurer);
276276
return thisT();
277277
}
278278

api/src/main/java/io/grpc/ForwardingServerBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public T setBinaryLog(BinaryLog binaryLog) {
193193
}
194194

195195
@Override
196-
public T childChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
197-
delegate().childChannelConfigurer(childChannelConfigurer);
196+
public T childChannelConfigurer(ChannelConfigurer channelConfigurer) {
197+
delegate().childChannelConfigurer(channelConfigurer);
198198
return thisT();
199199
}
200200

api/src/main/java/io/grpc/ManagedChannelBuilder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ public T offloadExecutor(Executor executor) {
160160
public abstract T intercept(ClientInterceptor... interceptors);
161161

162162
/**
163-
* Adds a factory that will construct an interceptor based on the channel's target.
163+
* Internal-only: Adds a factory that will construct an interceptor based on the channel's target.
164164
* This can be used to work around nameResolverFactory() changing the target string.
165165
*/
166-
public T interceptWithTarget(InterceptorFactory factory) {
166+
@Internal
167+
protected T interceptWithTarget(InterceptorFactory factory) {
167168
throw new UnsupportedOperationException();
168169
}
169170

@@ -664,12 +665,12 @@ public <X> T setNameResolverArg(NameResolver.Args.Key<X> key, X value) {
664665
* <p>This allows injecting configuration (like credentials, interceptors, or flow control)
665666
* into auxiliary channels created by gRPC infrastructure, such as xDS control plane connections.
666667
*
667-
* @param childChannelConfigurer the configurer to apply.
668+
* @param channelConfigurer the configurer to apply.
668669
* @return this
669-
* @since 1.79.0
670+
* @since 1.81.0
670671
*/
671672
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574")
672-
public T childChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
673+
public T childChannelConfigurer(ChannelConfigurer channelConfigurer) {
673674
throw new UnsupportedOperationException("Not implemented");
674675
}
675676

api/src/main/java/io/grpc/NameResolver.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public static final class Args {
358358
@Nullable private final MetricRecorder metricRecorder;
359359
@Nullable private final NameResolverRegistry nameResolverRegistry;
360360
@Nullable private final IdentityHashMap<Key<?>, Object> customArgs;
361-
@Nullable private final ChildChannelConfigurer childChannelConfigurer;
361+
@Nullable private final ChannelConfigurer channelConfigurer;
362362

363363
private Args(Builder builder) {
364364
this.defaultPort = checkNotNull(builder.defaultPort, "defaultPort not set");
@@ -373,7 +373,7 @@ private Args(Builder builder) {
373373
this.metricRecorder = builder.metricRecorder;
374374
this.nameResolverRegistry = builder.nameResolverRegistry;
375375
this.customArgs = cloneCustomArgs(builder.customArgs);
376-
this.childChannelConfigurer = builder.childChannelConfigurer;
376+
this.channelConfigurer = builder.channelConfigurer;
377377
}
378378

379379
/**
@@ -479,8 +479,8 @@ public ChannelLogger getChannelLogger() {
479479
*/
480480
@Nullable
481481
@Internal
482-
public ChildChannelConfigurer getChildChannelConfigurer() {
483-
return childChannelConfigurer;
482+
public ChannelConfigurer getChildChannelConfigurer() {
483+
return channelConfigurer;
484484
}
485485

486486
/**
@@ -592,7 +592,7 @@ public static final class Builder {
592592
private MetricRecorder metricRecorder;
593593
private NameResolverRegistry nameResolverRegistry;
594594
private IdentityHashMap<Key<?>, Object> customArgs;
595-
private ChildChannelConfigurer childChannelConfigurer;
595+
private ChannelConfigurer channelConfigurer = new ChannelConfigurer() {};
596596

597597
Builder() {
598598
}
@@ -713,8 +713,8 @@ public Builder setNameResolverRegistry(NameResolverRegistry registry) {
713713
*
714714
* @since 1.81.0
715715
*/
716-
public Builder setChildChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
717-
this.childChannelConfigurer = childChannelConfigurer;
716+
public Builder setChildChannelConfigurer(ChannelConfigurer channelConfigurer) {
717+
this.channelConfigurer = channelConfigurer;
718718
return this;
719719
}
720720

api/src/main/java/io/grpc/ServerBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,12 @@ public T setBinaryLog(BinaryLog binaryLog) {
432432
* into auxiliary channels created by gRPC infrastructure, such as xDS control plane connections
433433
* or OOB load balancing channels.
434434
*
435-
* @param childChannelConfigurer the configurer to apply.
435+
* @param channelConfigurer the configurer to apply.
436436
* @return this
437-
* @since 1.79.0
437+
* @since 1.81.0
438438
*/
439439
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574")
440-
public T childChannelConfigurer(ChildChannelConfigurer childChannelConfigurer) {
440+
public T childChannelConfigurer(ChannelConfigurer channelConfigurer) {
441441
throw new UnsupportedOperationException("Not implemented");
442442
}
443443

api/src/test/java/io/grpc/ChildChannelConfigurerTest.java renamed to api/src/test/java/io/grpc/ChannelConfigurerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import org.junit.runners.JUnit4;
2525

2626
@RunWith(JUnit4.class)
27-
public class ChildChannelConfigurerTest {
27+
public class ChannelConfigurerTest {
2828

2929
@Test
3030
public void defaultMethods_doNothing() {
31-
ChildChannelConfigurer configurer = new ChildChannelConfigurer() {};
31+
ChannelConfigurer configurer = new ChannelConfigurer() {};
3232

3333
ManagedChannelBuilder<?> mockChannelBuilder = mock(ManagedChannelBuilder.class);
3434
configurer.configureChannelBuilder(mockChannelBuilder);

api/src/test/java/io/grpc/NameResolverTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void args() {
105105
}
106106

107107
private NameResolver.Args createArgs() {
108-
ChildChannelConfigurer childChannelConfigurer = mock(ChildChannelConfigurer.class);
108+
ChannelConfigurer channelConfigurer = mock(ChannelConfigurer.class);
109109
return NameResolver.Args.newBuilder()
110110
.setDefaultPort(defaultPort)
111111
.setProxyDetector(proxyDetector)
@@ -117,15 +117,14 @@ private NameResolver.Args createArgs() {
117117
.setOverrideAuthority(overrideAuthority)
118118
.setMetricRecorder(metricRecorder)
119119
.setArg(FOO_ARG_KEY, customArgValue)
120-
.setChildChannelConfigurer(childChannelConfigurer)
120+
.setChildChannelConfigurer(channelConfigurer)
121121
.build();
122122
}
123123

124124
@Test
125125
public void args_childChannelConfigurer() {
126-
ChildChannelConfigurer childChannelConfigurer = mock(ChildChannelConfigurer.class);
126+
ChannelConfigurer channelConfigurer = mock(ChannelConfigurer.class);
127127

128-
// Create a real SynchronizationContext instead of mocking it
129128
SynchronizationContext realSyncContext = new SynchronizationContext(
130129
new Thread.UncaughtExceptionHandler() {
131130
@Override
@@ -140,15 +139,15 @@ public void uncaughtException(Thread t, Throwable e) {
140139
.setSynchronizationContext(realSyncContext)
141140
.setServiceConfigParser(mock(NameResolver.ServiceConfigParser.class))
142141
.setChannelLogger(mock(ChannelLogger.class))
143-
.setChildChannelConfigurer(childChannelConfigurer)
142+
.setChildChannelConfigurer(channelConfigurer)
144143
.build();
145144

146-
assertThat(args.getChildChannelConfigurer()).isSameInstanceAs(childChannelConfigurer);
145+
assertThat(args.getChildChannelConfigurer()).isSameInstanceAs(channelConfigurer);
147146

148147
// Validate configurer accepts builders
149148
ManagedChannelBuilder<?> mockBuilder = mock(ManagedChannelBuilder.class);
150149
args.getChildChannelConfigurer().configureChannelBuilder(mockBuilder);
151-
verify(childChannelConfigurer).configureChannelBuilder(mockBuilder);
150+
verify(channelConfigurer).configureChannelBuilder(mockBuilder);
152151
}
153152

154153
@Test

core/src/main/java/io/grpc/internal/ManagedChannelImpl.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
import io.grpc.CallCredentials;
3838
import io.grpc.CallOptions;
3939
import io.grpc.Channel;
40+
import io.grpc.ChannelConfigurer;
4041
import io.grpc.ChannelCredentials;
4142
import io.grpc.ChannelLogger;
4243
import io.grpc.ChannelLogger.ChannelLogLevel;
43-
import io.grpc.ChildChannelConfigurer;
4444
import io.grpc.ClientCall;
4545
import io.grpc.ClientInterceptor;
4646
import io.grpc.ClientInterceptors;
@@ -156,7 +156,13 @@ public Result selectConfig(PickSubchannelArgs args) {
156156
private static final LoadBalancer.PickDetailsConsumer NOOP_PICK_DETAILS_CONSUMER =
157157
new LoadBalancer.PickDetailsConsumer() {};
158158

159-
private ChildChannelConfigurer childChannelConfigurer = new ChildChannelConfigurer() {};
159+
/**
160+
* Retrieves the user-provided configuration function for internal child channels.
161+
*
162+
* <p>This is intended for use by gRPC internal components
163+
* that are responsible for creating auxiliary {@code ManagedChannel} instances.
164+
*/
165+
private ChannelConfigurer channelConfigurer = new ChannelConfigurer() {};
160166

161167
private final InternalLogId logId;
162168
private final String target;
@@ -548,8 +554,8 @@ ClientStream newSubstream(
548554
Supplier<Stopwatch> stopwatchSupplier,
549555
List<ClientInterceptor> interceptors,
550556
final TimeProvider timeProvider) {
551-
if (builder.childChannelConfigurer != null) {
552-
this.childChannelConfigurer = builder.childChannelConfigurer;
557+
if (builder.channelConfigurer != null) {
558+
this.channelConfigurer = builder.channelConfigurer;
553559
}
554560
this.target = checkNotNull(builder.target, "target");
555561
this.logId = InternalLogId.allocate("Channel", target);
@@ -596,7 +602,7 @@ ClientStream newSubstream(
596602
.setOverrideAuthority(this.authorityOverride)
597603
.setMetricRecorder(this.metricRecorder)
598604
.setNameResolverRegistry(builder.nameResolverRegistry)
599-
.setChildChannelConfigurer(this.childChannelConfigurer);
605+
.setChildChannelConfigurer(this.channelConfigurer);
600606
builder.copyAllNameResolverCustomArgsTo(nameResolverArgsBuilder);
601607
this.nameResolverArgs = nameResolverArgsBuilder.build();
602608
this.nameResolver = getNameResolver(
@@ -672,15 +678,6 @@ public CallTracer create() {
672678
}
673679
}
674680

675-
/**
676-
* Retrieves the user-provided configuration function for internal child channels.
677-
*
678-
* <p>This method is intended for use by gRPC internal components
679-
* that are responsible for creating auxiliary {@code ManagedChannel} instances.
680-
*
681-
* @return the ChildChannelConfigurer, guaranteed to be not null (defaults to no-op).
682-
*/
683-
684681
@VisibleForTesting
685682
static NameResolver getNameResolver(
686683
UriWrapper targetUri, @Nullable final String overrideAuthority,
@@ -1504,8 +1501,8 @@ protected ManagedChannelBuilder<?> delegate() {
15041501

15051502
// Note that we follow the global configurator pattern and try to fuse the configurations as
15061503
// soon as the builder gets created
1507-
if (childChannelConfigurer != null) {
1508-
childChannelConfigurer.configureChannelBuilder(builder);
1504+
if (channelConfigurer != null) {
1505+
channelConfigurer.configureChannelBuilder(builder);
15091506
}
15101507

15111508
return builder

0 commit comments

Comments
 (0)