32
32
33
33
/**
34
34
* A factory bean for construction of a {@link MongoClientOptions} instance.
35
- *
35
+ *
36
36
* @author Christoph Strobl
37
37
* @author Oliver Gierke
38
38
* @since 1.7
@@ -64,14 +64,14 @@ public class MongoClientOptionsFactoryBean extends AbstractFactoryBean<MongoClie
64
64
private int heartbeatConnectTimeout = DEFAULT_MONGO_OPTIONS .getHeartbeatConnectTimeout ();
65
65
private int heartbeatSocketTimeout = DEFAULT_MONGO_OPTIONS .getHeartbeatSocketTimeout ();
66
66
private String requiredReplicaSetName = DEFAULT_MONGO_OPTIONS .getRequiredReplicaSetName ();
67
- private int serverSelectionTimeout = - 1 ;
67
+ private int serverSelectionTimeout = Integer . MIN_VALUE ;
68
68
69
69
private boolean ssl ;
70
70
private SSLSocketFactory sslSocketFactory ;
71
71
72
72
/**
73
73
* Set the {@link MongoClient} description.
74
- *
74
+ *
75
75
* @param description
76
76
*/
77
77
public void setDescription (String description ) {
@@ -80,7 +80,7 @@ public void setDescription(String description) {
80
80
81
81
/**
82
82
* Set the minimum number of connections per host.
83
- *
83
+ *
84
84
* @param minConnectionsPerHost
85
85
*/
86
86
public void setMinConnectionsPerHost (int minConnectionsPerHost ) {
@@ -90,7 +90,7 @@ public void setMinConnectionsPerHost(int minConnectionsPerHost) {
90
90
/**
91
91
* Set the number of connections allowed per host. Will block if run out. Default is 10. System property
92
92
* {@code MONGO.POOLSIZE} can override
93
- *
93
+ *
94
94
* @param connectionsPerHost
95
95
*/
96
96
public void setConnectionsPerHost (int connectionsPerHost ) {
@@ -101,7 +101,7 @@ public void setConnectionsPerHost(int connectionsPerHost) {
101
101
* Set the multiplier for connectionsPerHost for # of threads that can block. Default is 5. If connectionsPerHost is
102
102
* 10, and threadsAllowedToBlockForConnectionMultiplier is 5, then 50 threads can block more than that and an
103
103
* exception will be thrown.
104
- *
104
+ *
105
105
* @param threadsAllowedToBlockForConnectionMultiplier
106
106
*/
107
107
public void setThreadsAllowedToBlockForConnectionMultiplier (int threadsAllowedToBlockForConnectionMultiplier ) {
@@ -110,7 +110,7 @@ public void setThreadsAllowedToBlockForConnectionMultiplier(int threadsAllowedTo
110
110
111
111
/**
112
112
* Set the max wait time of a blocking thread for a connection. Default is 12000 ms (2 minutes)
113
- *
113
+ *
114
114
* @param maxWaitTime
115
115
*/
116
116
public void setMaxWaitTime (int maxWaitTime ) {
@@ -119,7 +119,7 @@ public void setMaxWaitTime(int maxWaitTime) {
119
119
120
120
/**
121
121
* The maximum idle time for a pooled connection.
122
- *
122
+ *
123
123
* @param maxConnectionIdleTime
124
124
*/
125
125
public void setMaxConnectionIdleTime (int maxConnectionIdleTime ) {
@@ -128,7 +128,7 @@ public void setMaxConnectionIdleTime(int maxConnectionIdleTime) {
128
128
129
129
/**
130
130
* Set the maximum life time for a pooled connection.
131
- *
131
+ *
132
132
* @param maxConnectionLifeTime
133
133
*/
134
134
public void setMaxConnectionLifeTime (int maxConnectionLifeTime ) {
@@ -137,7 +137,7 @@ public void setMaxConnectionLifeTime(int maxConnectionLifeTime) {
137
137
138
138
/**
139
139
* Set the connect timeout in milliseconds. 0 is default and infinite.
140
- *
140
+ *
141
141
* @param connectTimeout
142
142
*/
143
143
public void setConnectTimeout (int connectTimeout ) {
@@ -146,7 +146,7 @@ public void setConnectTimeout(int connectTimeout) {
146
146
147
147
/**
148
148
* Set the socket timeout. 0 is default and infinite.
149
- *
149
+ *
150
150
* @param socketTimeout
151
151
*/
152
152
public void setSocketTimeout (int socketTimeout ) {
@@ -155,7 +155,7 @@ public void setSocketTimeout(int socketTimeout) {
155
155
156
156
/**
157
157
* Set the keep alive flag, controls whether or not to have socket keep alive timeout. Defaults to false.
158
- *
158
+ *
159
159
* @param socketKeepAlive
160
160
*/
161
161
public void setSocketKeepAlive (boolean socketKeepAlive ) {
@@ -164,7 +164,7 @@ public void setSocketKeepAlive(boolean socketKeepAlive) {
164
164
165
165
/**
166
166
* Set the {@link ReadPreference}.
167
- *
167
+ *
168
168
* @param readPreference
169
169
*/
170
170
public void setReadPreference (ReadPreference readPreference ) {
@@ -174,7 +174,7 @@ public void setReadPreference(ReadPreference readPreference) {
174
174
/**
175
175
* Set the {@link WriteConcern} that will be the default value used when asking the {@link MongoDbFactory} for a DB
176
176
* object.
177
- *
177
+ *
178
178
* @param writeConcern
179
179
*/
180
180
public void setWriteConcern (WriteConcern writeConcern ) {
@@ -190,7 +190,7 @@ public void setSocketFactory(SocketFactory socketFactory) {
190
190
191
191
/**
192
192
* Set the frequency that the driver will attempt to determine the current state of each server in the cluster.
193
- *
193
+ *
194
194
* @param heartbeatFrequency
195
195
*/
196
196
public void setHeartbeatFrequency (int heartbeatFrequency ) {
@@ -200,7 +200,7 @@ public void setHeartbeatFrequency(int heartbeatFrequency) {
200
200
/**
201
201
* In the event that the driver has to frequently re-check a server's availability, it will wait at least this long
202
202
* since the previous check to avoid wasted effort.
203
- *
203
+ *
204
204
* @param minHeartbeatFrequency
205
205
*/
206
206
public void setMinHeartbeatFrequency (int minHeartbeatFrequency ) {
@@ -209,7 +209,7 @@ public void setMinHeartbeatFrequency(int minHeartbeatFrequency) {
209
209
210
210
/**
211
211
* Set the connect timeout for connections used for the cluster heartbeat.
212
- *
212
+ *
213
213
* @param heartbeatConnectTimeout
214
214
*/
215
215
public void setHeartbeatConnectTimeout (int heartbeatConnectTimeout ) {
@@ -218,7 +218,7 @@ public void setHeartbeatConnectTimeout(int heartbeatConnectTimeout) {
218
218
219
219
/**
220
220
* Set the socket timeout for connections used for the cluster heartbeat.
221
- *
221
+ *
222
222
* @param heartbeatSocketTimeout
223
223
*/
224
224
public void setHeartbeatSocketTimeout (int heartbeatSocketTimeout ) {
@@ -227,7 +227,7 @@ public void setHeartbeatSocketTimeout(int heartbeatSocketTimeout) {
227
227
228
228
/**
229
229
* Configures the name of the replica set.
230
- *
230
+ *
231
231
* @param requiredReplicaSetName
232
232
*/
233
233
public void setRequiredReplicaSetName (String requiredReplicaSetName ) {
@@ -236,7 +236,7 @@ public void setRequiredReplicaSetName(String requiredReplicaSetName) {
236
236
237
237
/**
238
238
* This controls if the driver should us an SSL connection. Defaults to |@literal false}.
239
- *
239
+ *
240
240
* @param ssl
241
241
*/
242
242
public void setSsl (boolean ssl ) {
@@ -246,7 +246,7 @@ public void setSsl(boolean ssl) {
246
246
/**
247
247
* Set the {@link SSLSocketFactory} to use for the {@literal SSL} connection. If none is configured here,
248
248
* {@link SSLSocketFactory#getDefault()} will be used.
249
- *
249
+ *
250
250
* @param sslSocketFactory
251
251
*/
252
252
public void setSslSocketFactory (SSLSocketFactory sslSocketFactory ) {
@@ -255,7 +255,8 @@ public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
255
255
256
256
/**
257
257
* Set the {@literal server selection timeout} in msec for a 3.x MongoDB Java driver. If not set the default value of
258
- * 30 sec will be used.
258
+ * 30 sec will be used. A value of 0 means that it will timeout immediately if no server is available. A negative
259
+ * value means to wait indefinitely.
259
260
*
260
261
* @param serverSelectionTimeout in msec.
261
262
*/
@@ -275,7 +276,7 @@ protected MongoClientOptions createInstance() throws Exception {
275
276
276
277
MongoClientOptions .Builder builder = MongoClientOptions .builder ();
277
278
278
- if (MongoClientVersion .isMongo3Driver () && serverSelectionTimeout > 0 ) {
279
+ if (MongoClientVersion .isMongo3Driver () && serverSelectionTimeout != Integer . MIN_VALUE ) {
279
280
new DirectFieldAccessor (builder ).setPropertyValue ("serverSelectionTimeout" , serverSelectionTimeout );
280
281
}
281
282
0 commit comments