Skip to content

Commit 5c81286

Browse files
committed
Incorporate feedback from server code review
Addresses the following: - nits - visibility (move to package protected etc..) - javadocs - make server properties anemic Does not cover the following points: - rename / restructure the ConditionalOn... for server - observation API verify/check on direction - security concerns (need more review but should be good the way it is) Signed-off-by: onobc <[email protected]>
1 parent a1c2b04 commit 5c81286

File tree

13 files changed

+154
-197
lines changed

13 files changed

+154
-197
lines changed

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/DefaultServerFactoryPropertyMapper.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
class DefaultServerFactoryPropertyMapper<T extends ServerBuilder<T>> {
3838

39-
final GrpcServerProperties properties;
39+
private final GrpcServerProperties properties;
4040

4141
DefaultServerFactoryPropertyMapper(GrpcServerProperties properties) {
4242
this.properties = properties;
@@ -47,37 +47,37 @@ class DefaultServerFactoryPropertyMapper<T extends ServerBuilder<T>> {
4747
* @param serverBuilder the builder
4848
*/
4949
void customizeServerBuilder(T serverBuilder) {
50-
PropertyMapper mapper = PropertyMapper.get();
51-
customizeKeepAlive(serverBuilder, mapper);
52-
customizeInboundLimits(serverBuilder, mapper);
50+
PropertyMapper map = PropertyMapper.get();
51+
customizeKeepAlive(serverBuilder, map);
52+
customizeInboundLimits(serverBuilder, map);
5353
}
5454

5555
/**
5656
* Map the keep-alive properties to the server factory's server builder.
5757
* @param serverBuilder the builder
58-
* @param mapper the property mapper
58+
* @param map the property mapper
5959
*/
60-
void customizeKeepAlive(T serverBuilder, PropertyMapper mapper) {
60+
void customizeKeepAlive(T serverBuilder, PropertyMapper map) {
6161
GrpcServerProperties.KeepAlive keepAliveProps = this.properties.getKeepAlive();
62-
mapper.from(keepAliveProps.getTime()).to(durationProperty(serverBuilder::keepAliveTime));
63-
mapper.from(keepAliveProps.getTimeout()).to(durationProperty(serverBuilder::keepAliveTimeout));
64-
mapper.from(keepAliveProps.getMaxIdle()).to(durationProperty(serverBuilder::maxConnectionIdle));
65-
mapper.from(keepAliveProps.getMaxAge()).to(durationProperty(serverBuilder::maxConnectionAge));
66-
mapper.from(keepAliveProps.getMaxAgeGrace()).to(durationProperty(serverBuilder::maxConnectionAgeGrace));
67-
mapper.from(keepAliveProps.getPermitTime()).to(durationProperty(serverBuilder::permitKeepAliveTime));
68-
mapper.from(keepAliveProps.isPermitWithoutCalls()).to(serverBuilder::permitKeepAliveWithoutCalls);
62+
map.from(keepAliveProps.getTime()).to(durationProperty(serverBuilder::keepAliveTime));
63+
map.from(keepAliveProps.getTimeout()).to(durationProperty(serverBuilder::keepAliveTimeout));
64+
map.from(keepAliveProps.getMaxIdle()).to(durationProperty(serverBuilder::maxConnectionIdle));
65+
map.from(keepAliveProps.getMaxAge()).to(durationProperty(serverBuilder::maxConnectionAge));
66+
map.from(keepAliveProps.getMaxAgeGrace()).to(durationProperty(serverBuilder::maxConnectionAgeGrace));
67+
map.from(keepAliveProps.getPermitTime()).to(durationProperty(serverBuilder::permitKeepAliveTime));
68+
map.from(keepAliveProps.isPermitWithoutCalls()).to(serverBuilder::permitKeepAliveWithoutCalls);
6969
}
7070

7171
/**
7272
* Map the inbound limits properties to the server factory's server builder.
7373
* @param serverBuilder the builder
74-
* @param mapper the property mapper
74+
* @param map the property mapper
7575
*/
76-
void customizeInboundLimits(T serverBuilder, PropertyMapper mapper) {
77-
mapper.from(this.properties.getMaxInboundMessageSize())
76+
void customizeInboundLimits(T serverBuilder, PropertyMapper map) {
77+
map.from(this.properties.getMaxInboundMessageSize())
7878
.asInt(DataSize::toBytes)
7979
.to(serverBuilder::maxInboundMessageSize);
80-
mapper.from(this.properties.getMaxInboundMetadataSize())
80+
map.from(this.properties.getMaxInboundMetadataSize())
8181
.asInt(DataSize::toBytes)
8282
.to(serverBuilder::maxInboundMetadataSize);
8383
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.grpc.server.autoconfigure.codec;
17+
package org.springframework.boot.grpc.server.autoconfigure;
1818

1919
import io.grpc.Codec;
2020
import io.grpc.Compressor;
@@ -29,14 +29,13 @@
2929
import org.springframework.context.annotation.Configuration;
3030

3131
/**
32-
* The configuration that contains all codec related beans for clients/servers.
32+
* The configuration that contains all codec related beans for gRPC servers.
3333
*
3434
* @author Andrei Lisa
35-
* @since 4.0.0
3635
*/
3736
@Configuration(proxyBeanMethods = false)
3837
@ConditionalOnClass(Codec.class)
39-
public class GrpcCodecConfiguration {
38+
class GrpcCodecConfiguration {
4039

4140
@Bean
4241
@ConditionalOnMissingBean

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerAutoConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2929
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3030
import org.springframework.boot.context.properties.EnableConfigurationProperties;
31-
import org.springframework.boot.grpc.server.autoconfigure.codec.GrpcCodecConfiguration;
3231
import org.springframework.context.ApplicationContext;
3332
import org.springframework.context.annotation.Bean;
3433
import org.springframework.context.annotation.Configuration;

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerExecutorProvider.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818

1919
import java.util.concurrent.Executor;
2020

21+
/**
22+
* Strategy interface to determine the {@link Executor} to use for the gRPC server.
23+
*
24+
* @author Chris Bono
25+
* @since 4.0.0
26+
*/
27+
@FunctionalInterface
2128
public interface GrpcServerExecutorProvider {
2229

2330
/**
24-
* Returns a {@link Executor} for the gRPC server, if it needs tio be customized.
31+
* Returns a {@link Executor} for the gRPC server, if it needs to be customized.
2532
* @return the executor to use for the gRPC server
2633
*/
2734
Executor getExecutor();

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerFactoryConfigurations.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ ShadedNettyGrpcServerFactory shadedNettyGrpcServerFactory(GrpcServerProperties p
7878
.of(mapper::customizeServerBuilder, serverBuilderCustomizers::customize);
7979
KeyManagerFactory keyManager = null;
8080
TrustManagerFactory trustManager = null;
81-
if (properties.getSsl().isEnabled()) {
81+
if (properties.getSsl().determineEnabled()) {
8282
String bundleName = properties.getSsl().getBundle();
8383
Assert.notNull(bundleName, () -> "SSL bundleName must not be null");
8484
SslBundle bundle = bundles.getBundle(bundleName);
8585
keyManager = bundle.getManagers().getKeyManagerFactory();
8686
trustManager = properties.getSsl().isSecure() ? bundle.getManagers().getTrustManagerFactory()
8787
: io.grpc.netty.shaded.io.netty.handler.ssl.util.InsecureTrustManagerFactory.INSTANCE;
8888
}
89-
ShadedNettyGrpcServerFactory factory = new ShadedNettyGrpcServerFactory(properties.getAddress(),
89+
ShadedNettyGrpcServerFactory factory = new ShadedNettyGrpcServerFactory(properties.determineAddress(),
9090
builderCustomizers, keyManager, trustManager, properties.getSsl().getClientAuth());
9191
applyServerFactoryCustomizers(customizers, factory);
9292
serviceDiscoverer.findServices()
@@ -124,16 +124,16 @@ NettyGrpcServerFactory nettyGrpcServerFactory(GrpcServerProperties properties,
124124
.of(mapper::customizeServerBuilder, serverBuilderCustomizers::customize);
125125
KeyManagerFactory keyManager = null;
126126
TrustManagerFactory trustManager = null;
127-
if (properties.getSsl().isEnabled()) {
127+
if (properties.getSsl().determineEnabled()) {
128128
String bundleName = properties.getSsl().getBundle();
129129
Assert.notNull(bundleName, () -> "SSL bundleName must not be null");
130130
SslBundle bundle = bundles.getBundle(bundleName);
131131
keyManager = bundle.getManagers().getKeyManagerFactory();
132132
trustManager = properties.getSsl().isSecure() ? bundle.getManagers().getTrustManagerFactory()
133133
: InsecureTrustManagerFactory.INSTANCE;
134134
}
135-
NettyGrpcServerFactory factory = new NettyGrpcServerFactory(properties.getAddress(), builderCustomizers,
136-
keyManager, trustManager, properties.getSsl().getClientAuth());
135+
NettyGrpcServerFactory factory = new NettyGrpcServerFactory(properties.determineAddress(),
136+
builderCustomizers, keyManager, trustManager, properties.getSsl().getClientAuth());
137137
applyServerFactoryCustomizers(customizers, factory);
138138
serviceDiscoverer.findServices()
139139
.stream()

module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerFactoryCustomizer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818

1919
import org.springframework.grpc.server.GrpcServerFactory;
2020

21+
/**
22+
* Callback interface that can be implemented by beans wishing to customize the
23+
* {@link GrpcServerFactory server factory} before it is fully initialized.
24+
*
25+
* @author Chris Bono
26+
* @since 4.0.0
27+
*/
28+
@FunctionalInterface
2129
public interface GrpcServerFactoryCustomizer {
2230

2331
/**

0 commit comments

Comments
 (0)