Skip to content

Commit dfcf57f

Browse files
committed
Remove deprecated keepAlive support in SocketSettings
JAVA-3184
1 parent 44b062b commit dfcf57f

File tree

8 files changed

+8
-57
lines changed

8 files changed

+8
-57
lines changed

driver-core/src/main/com/mongodb/connection/SocketSettings.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
public class SocketSettings {
3434
private final long connectTimeoutMS;
3535
private final long readTimeoutMS;
36-
private final boolean keepAlive;
3736
private final int receiveBufferSize;
3837
private final int sendBufferSize;
3938

@@ -62,7 +61,6 @@ public static Builder builder(final SocketSettings socketSettings) {
6261
public static final class Builder {
6362
private long connectTimeoutMS = 10000;
6463
private long readTimeoutMS;
65-
private boolean keepAlive = true;
6664
private int receiveBufferSize;
6765
private int sendBufferSize;
6866

@@ -82,7 +80,6 @@ public Builder applySettings(final SocketSettings socketSettings) {
8280
notNull("socketSettings", socketSettings);
8381
connectTimeoutMS = socketSettings.connectTimeoutMS;
8482
readTimeoutMS = socketSettings.readTimeoutMS;
85-
keepAlive = socketSettings.keepAlive;
8683
receiveBufferSize = socketSettings.receiveBufferSize;
8784
sendBufferSize = socketSettings.sendBufferSize;
8885
return this;
@@ -112,21 +109,6 @@ public Builder readTimeout(final int readTimeout, final TimeUnit timeUnit) {
112109
return this;
113110
}
114111

115-
/**
116-
* Sets keep-alive.
117-
*
118-
* @param keepAlive false if keep-alive should be disabled
119-
* @return this
120-
* @deprecated configuring keep-alive has been deprecated. It now defaults to true and disabling it is not recommended.
121-
* @see <a href="https://docs.mongodb.com/manual/faq/diagnostics/#does-tcp-keepalive-time-affect-mongodb-deployments">
122-
* Does TCP keep-alive time affect MongoDB Deployments?</a>
123-
*/
124-
@Deprecated
125-
public Builder keepAlive(final boolean keepAlive) {
126-
this.keepAlive = keepAlive;
127-
return this;
128-
}
129-
130112
/**
131113
* Sets the receive buffer size.
132114
*
@@ -200,19 +182,6 @@ public int getReadTimeout(final TimeUnit timeUnit) {
200182
return (int) timeUnit.convert(readTimeoutMS, MILLISECONDS);
201183
}
202184

203-
/**
204-
* Gets whether keep-alive is enabled. Defaults to true.
205-
*
206-
* @return true if keep-alive is enabled.
207-
* @deprecated configuring keep-alive has been deprecated. It now defaults to true and disabling it is not recommended.
208-
* @see <a href="https://docs.mongodb.com/manual/faq/diagnostics/#does-tcp-keepalive-time-affect-mongodb-deployments">
209-
* Does TCP keep-alive time affect MongoDB Deployments?</a>
210-
*/
211-
@Deprecated
212-
public boolean isKeepAlive() {
213-
return keepAlive;
214-
}
215-
216185
/**
217186
* Gets the receive buffer size. Defaults to the operating system default.
218187
* @return the receive buffer size
@@ -244,9 +213,6 @@ public boolean equals(final Object o) {
244213
if (connectTimeoutMS != that.connectTimeoutMS) {
245214
return false;
246215
}
247-
if (keepAlive != that.keepAlive) {
248-
return false;
249-
}
250216
if (readTimeoutMS != that.readTimeoutMS) {
251217
return false;
252218
}
@@ -264,7 +230,6 @@ public boolean equals(final Object o) {
264230
public int hashCode() {
265231
int result = (int) (connectTimeoutMS ^ (connectTimeoutMS >>> 32));
266232
result = 31 * result + (int) (readTimeoutMS ^ (readTimeoutMS >>> 32));
267-
result = 31 * result + (keepAlive ? 1 : 0);
268233
result = 31 * result + receiveBufferSize;
269234
result = 31 * result + sendBufferSize;
270235
return result;
@@ -275,16 +240,14 @@ public String toString() {
275240
return "SocketSettings{"
276241
+ "connectTimeoutMS=" + connectTimeoutMS
277242
+ ", readTimeoutMS=" + readTimeoutMS
278-
+ ", keepAlive=" + keepAlive
279243
+ ", receiveBufferSize=" + receiveBufferSize
280244
+ ", sendBufferSize=" + sendBufferSize
281245
+ '}';
282246
}
283247

284-
SocketSettings(final Builder builder) {
248+
private SocketSettings(final Builder builder) {
285249
connectTimeoutMS = builder.connectTimeoutMS;
286250
readTimeoutMS = builder.readTimeoutMS;
287-
keepAlive = builder.keepAlive;
288251
receiveBufferSize = builder.receiveBufferSize;
289252
sendBufferSize = builder.sendBufferSize;
290253
}

driver-core/src/main/com/mongodb/connection/netty/NettyStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private void initializeChannel(final AsyncCompletionHandler<Void> handler, final
122122

123123
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, settings.getConnectTimeout(MILLISECONDS));
124124
bootstrap.option(ChannelOption.TCP_NODELAY, true);
125-
bootstrap.option(ChannelOption.SO_KEEPALIVE, settings.isKeepAlive());
125+
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
126126

127127
if (settings.getReceiveBufferSize() > 0) {
128128
bootstrap.option(ChannelOption.SO_RCVBUF, settings.getReceiveBufferSize());

driver-core/src/main/com/mongodb/internal/connection/AsynchronousSocketChannelStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void initializeSocketChannel(final AsyncCompletionHandler<Void> handler,
6868
try {
6969
AsynchronousSocketChannel attemptConnectionChannel = AsynchronousSocketChannel.open(group);
7070
attemptConnectionChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
71-
attemptConnectionChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, settings.isKeepAlive());
71+
attemptConnectionChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
7272
if (settings.getReceiveBufferSize() > 0) {
7373
attemptConnectionChannel.setOption(StandardSocketOptions.SO_RCVBUF, settings.getReceiveBufferSize());
7474
}

driver-core/src/main/com/mongodb/internal/connection/SocketStreamHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void initialize(final Socket socket, final InetSocketAddress inetSocketAd
3737
final SslSettings sslSettings) throws IOException {
3838
socket.setTcpNoDelay(true);
3939
socket.setSoTimeout(settings.getReadTimeout(MILLISECONDS));
40-
socket.setKeepAlive(settings.isKeepAlive());
40+
socket.setKeepAlive(true);
4141
if (settings.getReceiveBufferSize() > 0) {
4242
socket.setReceiveBufferSize(settings.getReceiveBufferSize());
4343
}

driver-core/src/test/functional/com/mongodb/internal/connection/SocketStreamHelperSpecification.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class SocketStreamHelperSpecification extends Specification {
3939
Socket socket = SocketFactory.default.createSocket()
4040
def socketSettings = SocketSettings.builder()
4141
.readTimeout(10, SECONDS)
42-
.keepAlive(true)
4342
.build()
4443
4544
when:

driver-core/src/test/unit/com/mongodb/MongoClientSettingsSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class MongoClientSettingsSpecification extends Specification {
147147
settings.getReadConcern() == ReadConcern.LOCAL
148148
settings.getApplicationName() == 'app1'
149149
settings.getSocketSettings() == SocketSettings.builder().build()
150-
settings.getHeartbeatSocketSettings() == SocketSettings.builder().readTimeout(10000, TimeUnit.MILLISECONDS).keepAlive(true).build()
150+
settings.getHeartbeatSocketSettings() == SocketSettings.builder().readTimeout(10000, TimeUnit.MILLISECONDS).build()
151151
settings.getCommandListeners().get(0) == commandListener
152152
settings.getCodecRegistry() == codecRegistry
153153
settings.getCredential() == credential

driver-core/src/test/unit/com/mongodb/connection/SocketSettingsSpecification.groovy

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class SocketSettingsSpecification extends Specification {
3131
then:
3232
settings.getConnectTimeout(MILLISECONDS) == 10000
3333
settings.getReadTimeout(MILLISECONDS) == 0
34-
settings.keepAlive
3534
settings.receiveBufferSize == 0
3635
settings.sendBufferSize == 0
3736
}
@@ -41,7 +40,6 @@ class SocketSettingsSpecification extends Specification {
4140
def settings = SocketSettings.builder()
4241
.connectTimeout(5000, MILLISECONDS)
4342
.readTimeout(2000, MILLISECONDS)
44-
.keepAlive(false)
4543
.sendBufferSize(1000)
4644
.receiveBufferSize(1500)
4745
.build()
@@ -50,7 +48,6 @@ class SocketSettingsSpecification extends Specification {
5048
then:
5149
settings.getConnectTimeout(MILLISECONDS) == 5000
5250
settings.getReadTimeout(MILLISECONDS) == 2000
53-
!settings.keepAlive
5451
settings.sendBufferSize == 1000
5552
settings.receiveBufferSize == 1500
5653
}
@@ -60,7 +57,6 @@ class SocketSettingsSpecification extends Specification {
6057
def original = SocketSettings.builder()
6158
.connectTimeout(5000, MILLISECONDS)
6259
.readTimeout(2000, MILLISECONDS)
63-
.keepAlive(false)
6460
.sendBufferSize(1000)
6561
.receiveBufferSize(1500)
6662
.build()
@@ -70,7 +66,6 @@ class SocketSettingsSpecification extends Specification {
7066
then:
7167
settings.getConnectTimeout(MILLISECONDS) == 5000
7268
settings.getReadTimeout(MILLISECONDS) == 2000
73-
!settings.keepAlive
7469
settings.sendBufferSize == 1000
7570
settings.receiveBufferSize == 1500
7671
}
@@ -86,7 +81,6 @@ class SocketSettingsSpecification extends Specification {
8681
then:
8782
settings.getConnectTimeout(MILLISECONDS) == 5000
8883
settings.getReadTimeout(MILLISECONDS) == 2000
89-
settings.keepAlive
9084
settings.sendBufferSize == 0
9185
settings.receiveBufferSize == 0
9286
}
@@ -97,7 +91,6 @@ class SocketSettingsSpecification extends Specification {
9791
def customSettings = SocketSettings.builder()
9892
.connectTimeout(5000, MILLISECONDS)
9993
.readTimeout(2000, MILLISECONDS)
100-
.keepAlive(false)
10194
.sendBufferSize(1000)
10295
.receiveBufferSize(1500)
10396
.build()
@@ -113,22 +106,20 @@ class SocketSettingsSpecification extends Specification {
113106
SocketSettings.builder()
114107
.connectTimeout(5000, MILLISECONDS)
115108
.readTimeout(2000, MILLISECONDS)
116-
.keepAlive(true)
117109
.sendBufferSize(1000)
118110
.receiveBufferSize(1500)
119111
.build() ==
120112
SocketSettings.builder()
121113
.connectTimeout(5000, MILLISECONDS)
122114
.readTimeout(2000, MILLISECONDS)
123-
.keepAlive(true)
124115
.sendBufferSize(1000)
125116
.receiveBufferSize(1500)
126117
.build()
127118
}
128119

129120
def 'different settings should not be equal'() {
130121
expect:
131-
SocketSettings.builder().keepAlive(true).build() != SocketSettings.builder().keepAlive(false).build()
122+
SocketSettings.builder().receiveBufferSize(4) != SocketSettings.builder().receiveBufferSize(3).build()
132123
}
133124

134125
def 'identical settings should have same hash code'() {
@@ -137,21 +128,19 @@ class SocketSettingsSpecification extends Specification {
137128
SocketSettings.builder()
138129
.connectTimeout(5000, MILLISECONDS)
139130
.readTimeout(2000, MILLISECONDS)
140-
.keepAlive(true)
141131
.sendBufferSize(1000)
142132
.receiveBufferSize(1500)
143133
.build().hashCode() ==
144134
SocketSettings.builder()
145135
.connectTimeout(5000, MILLISECONDS)
146136
.readTimeout(2000, MILLISECONDS)
147-
.keepAlive(true)
148137
.sendBufferSize(1000)
149138
.receiveBufferSize(1500)
150139
.build().hashCode()
151140
}
152141

153142
def 'different settings should have different hash codes'() {
154143
expect:
155-
SocketSettings.builder().keepAlive(true).build().hashCode() != SocketSettings.builder().keepAlive(false).build().hashCode()
144+
SocketSettings.builder().sendBufferSize(4).build().hashCode() != SocketSettings.builder().sendBufferSize(3).build().hashCode()
156145
}
157146
}

driver-core/src/test/unit/com/mongodb/connection/netty/NettyStreamFactorySpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import spock.lang.Specification
2929

3030
class NettyStreamFactorySpecification extends Specification {
3131

32-
private static final SOCKET_SETTINGS = SocketSettings.builder().keepAlive(true).build()
32+
private static final SOCKET_SETTINGS = SocketSettings.builder().build()
3333
private static final SSL_SETTINGS = SslSettings.builder().enabled(true).invalidHostNameAllowed(true).build()
3434
private static final EVENT_LOOP_GROUP = new OioEventLoopGroup()
3535
private static final SOCKET_CHANNEL_CLASS = OioSocketChannel

0 commit comments

Comments
 (0)