Skip to content

Commit b4d4244

Browse files
committed
JAVA-396: improve javadocs for connection options, they confuse people
1 parent 5613c10 commit b4d4244

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private synchronized Response go( OutMessage msg , DBCollection coll , boolean f
9090
}
9191

9292
_calls++;
93-
93+
9494
if ( _socket == null )
9595
_open();
9696

src/main/com/mongodb/MongoOptions.java

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -64,100 +64,99 @@ else if (safe)
6464
public String description;
6565

6666
/**
67-
* <p>The number of connections allowed per host
68-
* (the pool size, per host)</p>
69-
* <p>Once the pool is exhausted, this will block.
67+
* The maximum number of connections allowed per host for this Mongo instance.
68+
* Those connections will be kept in a pool when idle.
69+
* Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.
70+
* Default is 10.
7071
* @see {@linkplain MongoOptions#threadsAllowedToBlockForConnectionMultiplier}</p>
7172
*/
7273
public int connectionsPerHost;
7374

7475
/**
75-
* multiplier for connectionsPerHost for # of threads that
76-
* can block if connectionsPerHost is 10, and
77-
* threadsAllowedToBlockForConnectionMultiplier is 5,
78-
* then 50 threads can block
79-
* more than that and an exception will be throw
76+
* this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that
77+
* may be waiting for a connection to become available from the pool.
78+
* All further threads will get an exception right away.
79+
* For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50 threads can wait for a connection.
80+
* Default is 5.
8081
*/
8182
public int threadsAllowedToBlockForConnectionMultiplier;
8283

8384
/**
84-
* The max wait time for a blocking thread for a connection from the pool in ms.
85+
* The maximum wait time in ms that a thread may wait for a connection to become available.
86+
* Default is 120,000.
8587
*/
8688
public int maxWaitTime;
8789

8890
/**
89-
* The connection timeout in milliseconds; this is for
90-
* establishing the socket connections (open).
91-
* 0 is default and infinite
91+
* The connection timeout in milliseconds.
92+
* It is used solely when establishing a new connection {@link java.net.Socket#connect(java.net.SocketAddress, int) }
93+
* Default is 0 and means no timeout.
9294
*/
9395
public int connectTimeout;
9496

9597
/**
96-
* The socket timeout; this value is passed to
97-
* {@link java.net.Socket#setSoTimeout(int)}.
98-
* 0 is default and infinite
98+
* The socket timeout in milliseconds
99+
* It is used for I/O socket read and write operations {@link java.net.Socket#setSoTimeout(int)}
100+
* Default is 0 and means no timeout.
99101
*/
100102
public int socketTimeout;
101103

102104
/**
103-
* This controls whether or not to have socket keep alive
104-
* turned on (SO_KEEPALIVE).
105-
*
106-
* defaults to false
105+
* This flag controls the socket keep alive feature that keeps a connection alive through firewalls {@link java.net.Socket#setKeepAlive(boolean)}
106+
* Default is false.
107107
*/
108108
public boolean socketKeepAlive;
109109

110110
/**
111-
* This controls whether the system retries automatically
112-
* on connection errors.
113-
* defaults to false
111+
* If true, the driver will keep trying to connect to the server in case that the socket cannot be established.
112+
* This can be useful to avoid exceptions being thrown when a server is down temporarily by blocking the operations.
113+
* Note that it is not a good solution for many applications because:
114+
* - in general infinite retries is not advised, the application can get stuck in case of long server down time
115+
* - for a replica set, the driver will keep trying to connect to the same host, even if the master has changed
116+
* - this does not apply to read/write exceptions on the socket
117+
*
118+
* For most applications it is advised to keep this setting off and handle exceptions properly in the application.
119+
* The driver already has mechanisms to automatically recreate dead connections and retry read operations.
120+
* Default is false.
114121
*/
115122
public boolean autoConnectRetry;
116123

117124
/**
118-
* Specifies if the driver is allowed to read from secondaries
119-
* or slaves.
120-
*
121-
* defaults to false
125+
* This flag specifies if the driver is allowed to read from secondary (slave) servers.
126+
* Specifically in the current implementation, the driver will avoid reading from the primary server and round robin requests to secondaries.
127+
* Driver also factors in the latency to secondaries when choosing a server.
128+
* Note that reading from secondaries can increase performance and reliability, but it may result in temporary inconsistent results.
129+
* Default is false.
122130
*/
123131
public boolean slaveOk;
124132

125133
/**
126-
* Override the DBCallback factory. Default is for the standard Mongo Java
127-
* driver configuration.
134+
* Override the DBCallback factory. Default is for the standard Mongo Java driver configuration.
128135
*/
129136
public DBDecoderFactory dbDecoderFactory;
130137

131138
/**
132-
* If <b>true</b> the driver sends a getLastError command after
133-
* every update to ensure it succeeded (see also w and wtimeout)
134-
* If <b>false</b>, the driver does not send a getlasterror command
135-
* after every update.
136-
*
137-
* defaults to false
139+
* If <b>true</b> the driver will use a WriteConcern of WriteConcern.SAFE for all operations.
140+
* If w, wtimeout, fsync or j are specified, this setting is ignored.
141+
* Default is false.
138142
*/
139143
public boolean safe;
140144

141145
/**
142-
* If set, the w value of WriteConcern for the connection is set
143-
* to this.
144-
*
145-
* Defaults to 0; implies safe = true
146+
* The "w" value of the global WriteConcern.
147+
* Default is 0.
146148
*/
147149
public int w;
148150

149151
/**
150-
* If set, the wtimeout value of WriteConcern for the
151-
* connection is set to this.
152-
*
153-
* Defaults to 0; implies safe = true
152+
* The "wtimeout" value of the global WriteConcern.
153+
* Default is 0.
154154
*/
155155
public int wtimeout;
156156

157157
/**
158-
* Sets the fsync value of WriteConcern for the connection.
159-
*
160-
* Defaults to false; implies safe = true
158+
* The "fsync" value of the global WriteConcern.
159+
* Default is false.
161160
*/
162161
public boolean fsync;
163162

0 commit comments

Comments
 (0)