/
GRpcServerProperties.java
143 lines (113 loc) · 4.07 KB
/
GRpcServerProperties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package org.lognet.springboot.grpc.autoconfigure;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.lognet.springboot.grpc.context.GRpcServerInitializedEvent;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.event.EventListener;
import org.springframework.core.io.Resource;
import org.springframework.util.unit.DataSize;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
/**
* Created by alexf on 26-Jan-16.
*/
@ConfigurationProperties("grpc")
@Getter
@Setter
public class GRpcServerProperties implements InitializingBean {
public static final int DEFAULT_GRPC_PORT = 6565;
/**
* gRPC server port
*/
private Integer port = null;
private SecurityProperties security;
private RecoveryProperties recovery;
private NettyServerProperties nettyServer;
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
private volatile Integer runningPort = null;
private int startUpPhase = SmartLifecycle.DEFAULT_PHASE;
/**
* Enables the embedded grpc server.
*/
private boolean enabled = true;
/**
* In process server name.
* If the value is not empty, the embedded in-process server will be created and started.
*/
private String inProcessServerName;
/**
* Enables server reflection using <a href="https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md">ProtoReflectionService</a>.
* Available only from gRPC 1.3 or higher.
*/
private boolean enableReflection = false;
/**
* Number of seconds to wait for preexisting calls to finish before shutting down.
* A negative value is equivalent to an infinite grace period
*/
private int shutdownGrace = 0;
@EventListener
public void onServerStarted(GRpcServerInitializedEvent event) {
runningPort = event.getServer().getPort();
}
public Integer getPortOrDefault() {
return Optional.ofNullable(port).orElse(DEFAULT_GRPC_PORT);
}
public Integer getRunningPort() {
return runningPort;
}
@Override
public void afterPropertiesSet() throws Exception {
Optional.ofNullable(nettyServer)
.map(NettyServerProperties::getPrimaryListenAddress)
.ifPresent(a -> port = a.getPort());
}
@Getter
@Setter
public static class RecoveryProperties {
private Integer interceptorOrder;
}
@Getter
@Setter
public static class SecurityProperties {
private Resource certChain;
private Resource privateKey;
private Auth auth;
@Getter
@Setter
public static class Auth {
private Integer interceptorOrder;
private boolean failFast = true;
}
}
@Getter
@Setter
public static class NettyServerProperties {
private boolean onCollisionPreferShadedNetty;
private Integer flowControlWindow;
private Integer initialFlowControlWindow;
private Integer maxConcurrentCallsPerConnection;
private Duration keepAliveTime;
private Duration keepAliveTimeout;
private Duration maxConnectionAge;
private Duration maxConnectionAgeGrace;
private Duration maxConnectionIdle;
private Duration permitKeepAliveTime;
private DataSize maxInboundMessageSize;
private DataSize maxInboundMetadataSize;
private Boolean permitKeepAliveWithoutCalls;
/**
* grpc listen address. <P>If configured, takes precedence over {@code grpc.port} property value.</p>
* Supported format:
* <ul><li>{@code host:port} (if port is less than 1, uses random value)
* <li>{@code host:} (uses default grpc port, 6565 )</ul>
*/
private InetSocketAddress primaryListenAddress;
private List<InetSocketAddress> additionalListenAddresses;
}
}