Skip to content

Commit cad5b72

Browse files
onobcdsyer
authored andcommitted
Clarify "target" parameter in channel factory APIs
Clarifies the javadocs with the allowed values for the "target" input parameter on the `GrpcChannelFactory` create/supports APIs. Also clarifies the javadocs and renames the "authority" input parameter on `GrpcChannelBuilderCustomizer#customize` to "target". Signed-off-by: onobc <chris.bono@gmail.com>
1 parent e5a9cb3 commit cad5b72

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

spring-grpc-client-spring-boot-autoconfigure/src/main/java/org/springframework/boot/grpc/client/autoconfigure/ClientPropertiesChannelBuilderCustomizer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ class ClientPropertiesChannelBuilderCustomizer<T extends ManagedChannelBuilder<T
4848
}
4949

5050
@Override
51-
public void customize(String authority, T builder) {
52-
ChannelConfig channel = this.properties.getChannel(authority);
51+
public void customize(String target, T builder) {
52+
ChannelConfig channel = this.properties.getChannel(target);
5353
PropertyMapper mapper = PropertyMapper.get();
5454
mapper.from(channel.getUserAgent()).to(builder::userAgent);
55-
if (targetAllowsLoadBalancer(authority)) {
55+
if (targetAllowsLoadBalancer(target)) {
5656
mapper.from(channel.getDefaultLoadBalancingPolicy()).to(builder::defaultLoadBalancingPolicy);
5757
}
5858
mapper.from(channel.getMaxInboundMessageSize()).asInt(DataSize::toBytes).to(builder::maxInboundMessageSize);

spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public DefaultGrpcChannelFactory(List<GrpcChannelBuilderCustomizer<T>> globalCus
8181

8282
/**
8383
* {@inheritDoc}
84-
* @param target the target string as described in method javadocs
84+
* @param target the target string
8585
* @return true unless the target begins with 'in-process:'
8686
*/
8787
@Override

spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelBuilderCustomizer.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import java.util.function.Consumer;
2020

21+
import io.grpc.ChannelCredentials;
22+
import io.grpc.Grpc;
2123
import io.grpc.ManagedChannelBuilder;
2224

2325
/**
2426
* Callback interface that can be used to customize a {@link ManagedChannelBuilder} for a
25-
* specific authority.
27+
* specific target.
2628
*
2729
* @param <T> type of builder
2830
* @author Dave Syer
@@ -33,16 +35,19 @@ public interface GrpcChannelBuilderCustomizer<T extends ManagedChannelBuilder<T>
3335

3436
/**
3537
* Callback to customize a {@link ManagedChannelBuilder channel builder} instance for
36-
* a specific target authority.
37-
* @param authority the target authority for the channel
38+
* a specific target string. The target can be either a valid nameresolver-compliant
39+
* URI or an authority string as described in
40+
* {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or the name of a
41+
* user-configured channel (e.g. 'my-channel').
42+
* @param target the target string
3843
* @param builder the builder to customize
3944
*/
40-
void customize(String authority, T builder);
45+
void customize(String target, T builder);
4146

4247
default GrpcChannelBuilderCustomizer<T> then(GrpcChannelBuilderCustomizer<T> other) {
43-
return (authority, builder) -> {
44-
customize(authority, builder);
45-
other.customize(authority, builder);
48+
return (target, builder) -> {
49+
customize(target, builder);
50+
other.customize(target, builder);
4651
};
4752
}
4853

@@ -58,8 +63,8 @@ static <T extends ManagedChannelBuilder<T>> GrpcChannelBuilderCustomizer<T> defa
5863

5964
static <T extends ManagedChannelBuilder<T>> GrpcChannelBuilderCustomizer<T> matching(String pattern,
6065
Consumer<ManagedChannelBuilder<T>> consumer) {
61-
return (authority, channel) -> {
62-
if (pattern.matches(authority)) {
66+
return (target, channel) -> {
67+
if (pattern.matches(target)) {
6368
consumer.accept(channel);
6469
}
6570
};

spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
public interface GrpcChannelFactory {
3131

3232
/**
33-
* Whether this factory supports the given target string. The target can be either a
34-
* valid nameresolver-compliant URI, an authority string as described in
35-
* {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or a named channel
36-
* which will use the address of a user-configured channel as the target to check.
37-
* @param target the target string as described in method javadocs
33+
* Whether this factory supports the given target string.
34+
* <p>
35+
* The target can be either a valid nameresolver-compliant URI or an authority string
36+
* as described in {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or the
37+
* name of a user-configured channel (e.g. 'my-channel').
38+
* @param target the target string
3839
* @return whether this factory supports the given target string
3940
*/
4041
boolean supports(String target);
@@ -49,14 +50,15 @@ default boolean supports(ClientInterceptor interceptor) {
4950
}
5051

5152
/**
52-
* Creates a {@link ManagedChannel} for the given target string. The target can be
53-
* either a valid nameresolver-compliant URI, an authority string as described in
54-
* {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or a named channel
55-
* which will return a builder that is based on a user-configured channel.
53+
* Creates a {@link ManagedChannel} for the given target string.
54+
* <p>
55+
* The target can be either a valid nameresolver-compliant URI or an authority string
56+
* as described in {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or the
57+
* name of a user-configured channel (e.g. 'my-channel').
5658
* <p>
5759
* The returned channel is configured to use all globally registered
5860
* {@link ClientInterceptor interceptors}.
59-
* @param target the target string as described in method javadocs
61+
* @param target the target string
6062
* @return a channel for the given target
6163
*/
6264
default ManagedChannel createChannel(String target) {
@@ -65,9 +67,10 @@ default ManagedChannel createChannel(String target) {
6567

6668
/**
6769
* Creates a {@link ManagedChannel} for the given target string. The target can be
68-
* either a valid nameresolver-compliant URI, an authority string as described in
69-
* {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or a named channel
70-
* which will return a builder that is based on a user-configured channel.
70+
* <p>
71+
* The target can be either a valid nameresolver-compliant URI or an authority string
72+
* as described in {@link Grpc#newChannelBuilder(String, ChannelCredentials)}, or the
73+
* name of a user-configured channel (e.g. 'my-channel').
7174
* <p>
7275
* The returned channel is configured to use all globally registered
7376
* {@link ClientInterceptor interceptors} and any user-provided interceptor if

spring-grpc-core/src/main/java/org/springframework/grpc/client/InProcessGrpcChannelFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public InProcessGrpcChannelFactory(List<GrpcChannelBuilderCustomizer<InProcessCh
4444

4545
/**
4646
* {@inheritDoc}
47-
* @param target the target string as described in method javadocs
47+
* @param target the target string
4848
* @return true if the target begins with 'in-process:'
4949
*/
5050
@Override

0 commit comments

Comments
 (0)