2323
2424/**
2525 * Various settings to control the behavior of a <code>MongoClient</code>.
26- * <p>
26+ * <p/ >
2727 * Note: This class is a replacement for {@code MongoOptions}, to be used with {@code MongoClient}. The main difference
2828 * in behavior is that the default write concern is {@code WriteConcern.ACKNOWLEDGED}.
29+ *
2930 * @see MongoClient
3031 * @since 2.10.0
3132 */
@@ -54,6 +55,7 @@ public static class Builder {
5455 private WriteConcern writeConcern = WriteConcern .ACKNOWLEDGED ;
5556 private SocketFactory socketFactory = SocketFactory .getDefault ();
5657 private boolean cursorFinalizerEnabled = true ;
58+ private boolean alwaysUseMBeans = false ;
5759
5860 /**
5961 * Sets the description.
@@ -86,7 +88,8 @@ public Builder connectionsPerHost(final int connectionsPerHost) {
8688 /**
8789 * Sets the multiplier for number of threads allowed to block waiting for a connection.
8890 *
89- * @param threadsAllowedToBlockForConnectionMultiplier the multiplier
91+ * @param threadsAllowedToBlockForConnectionMultiplier
92+ * the multiplier
9093 * @return {@code this}
9194 * @throws IllegalArgumentException if <code>threadsAllowedToBlockForConnectionMultiplier < 1</code>
9295 * @see com.mongodb.MongoClientOptions#getThreadsAllowedToBlockForConnectionMultiplier()
@@ -106,7 +109,6 @@ public Builder threadsAllowedToBlockForConnectionMultiplier(final int threadsAll
106109 * @return {@code this}
107110 * @throws IllegalArgumentException if <code>maxWaitTime < 0</code>
108111 * @see com.mongodb.MongoClientOptions#getMaxWaitTime()
109- *
110112 */
111113 public Builder maxWaitTime (final int maxWaitTime ) {
112114 if (maxWaitTime < 0 ) {
@@ -133,6 +135,7 @@ public Builder connectTimeout(final int connectTimeout) {
133135
134136 /**
135137 * Sets the socket timeout.
138+ *
136139 * @param socketTimeout the socket timeout
137140 * @return {@code this}
138141 * @see com.mongodb.MongoClientOptions#getSocketTimeout()
@@ -163,7 +166,6 @@ public Builder socketKeepAlive(final boolean socketKeepAlive) {
163166 * @param autoConnectRetry auto connect retry
164167 * @return {@code this}
165168 * @see MongoClientOptions#isAutoConnectRetry()
166- *
167169 */
168170 public Builder autoConnectRetry (final boolean autoConnectRetry ) {
169171 this .autoConnectRetry = autoConnectRetry ;
@@ -264,7 +266,6 @@ public Builder socketFactory(final SocketFactory socketFactory) {
264266 * Sets whether cursor finalizers are enabled.
265267 *
266268 * @param cursorFinalizerEnabled whether cursor finalizers are enabled.
267- *
268269 * @return {@code this}
269270 * @see MongoClientOptions#isCursorFinalizerEnabled()
270271 */
@@ -273,6 +274,20 @@ public Builder cursorFinalizerEnabled(final boolean cursorFinalizerEnabled) {
273274 return this ;
274275 }
275276
277+ /**
278+ * Sets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is
279+ * Java 6 or greater. If false, the driver will use MXBeans if the VM is Java 6 or greater, and use MBeans if
280+ * the VM is Java 5.
281+ *
282+ * @param alwaysUseMBeans true if driver should always use MBeans, regardless of VM version
283+ * @return this
284+ * @see MongoClientOptions#isAlwaysUseMBeans()
285+ */
286+ public Builder alwaysUseMBeans (final boolean alwaysUseMBeans ) {
287+ this .alwaysUseMBeans = alwaysUseMBeans ;
288+ return this ;
289+ }
290+
276291 /**
277292 * Sets defaults to be what they are in {@code MongoOptions}.
278293 *
@@ -297,8 +312,9 @@ public MongoClientOptions build() {
297312
298313 /**
299314 * Gets the description for this MongoClient, which is used in various places like logging and JMX.
300- * <p>
315+ * <p/ >
301316 * Default is null.
317+ *
302318 * @return the description
303319 */
304320 public String getDescription () {
@@ -309,8 +325,9 @@ public String getDescription() {
309325 * The maximum number of connections allowed per host for this MongoClient instance.
310326 * Those connections will be kept in a pool when idle.
311327 * Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.
312- * <p>
328+ * <p/ >
313329 * Default is 100.
330+ *
314331 * @return the maximum size of the connection pool per host
315332 * @see MongoClientOptions#getThreadsAllowedToBlockForConnectionMultiplier()
316333 */
@@ -323,8 +340,9 @@ public int getConnectionsPerHost() {
323340 * may be waiting for a connection to become available from the pool. All further threads will get an exception right
324341 * away. For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50
325342 * threads can wait for a connection.
326- * <p>
343+ * <p/ >
327344 * Default is 5.
345+ *
328346 * @return the multiplier
329347 */
330348 public int getThreadsAllowedToBlockForConnectionMultiplier () {
@@ -333,8 +351,9 @@ public int getThreadsAllowedToBlockForConnectionMultiplier() {
333351
334352 /**
335353 * The maximum wait time in milliseconds that a thread may wait for a connection to become available.
336- * <p>
354+ * <p/ >
337355 * Default is 120,000. A value of 0 means that it will not wait. A negative value means to wait indefinitely.
356+ *
338357 * @return the maximum wait time.
339358 */
340359 public int getMaxWaitTime () {
@@ -344,8 +363,9 @@ public int getMaxWaitTime() {
344363 /**
345364 * The connection timeout in milliseconds. A value of 0 means no timeout.
346365 * It is used solely when establishing a new connection {@link java.net.Socket#connect(java.net.SocketAddress, int) }
347- * <p>
366+ * <p/ >
348367 * Default is 10,000.
368+ *
349369 * @return the socket connect timeout
350370 */
351371 public int getConnectTimeout () {
@@ -355,8 +375,9 @@ public int getConnectTimeout() {
355375 /**
356376 * The socket timeout in milliseconds.
357377 * It is used for I/O socket read and write operations {@link java.net.Socket#setSoTimeout(int)}
358- * <p>
378+ * <p/ >
359379 * Default is 0 and means no timeout.
380+ *
360381 * @return the socket timeout
361382 */
362383 public int getSocketTimeout () {
@@ -365,7 +386,7 @@ public int getSocketTimeout() {
365386
366387 /**
367388 * This flag controls the socket keep alive feature that keeps a connection alive through firewalls {@link java.net.Socket#setKeepAlive(boolean)}
368- * <p>
389+ * <p/ >
369390 * * Default is false.
370391 *
371392 * @return whether keep-alive is enabled on each socket
@@ -382,7 +403,7 @@ public boolean isSocketKeepAlive() {
382403 * Note that when using this flag:
383404 * - for a replica set, the driver will trying to connect to the old master for that time, instead of failing over to the new one right away
384405 * - this does not prevent exception from being thrown in read/write operations on the socket, which must be handled by application
385- *
406+ * <p/>
386407 * Even if this flag is false, the driver already has mechanisms to automatically recreate broken connections and retry the read operations.
387408 * Default is false.
388409 *
@@ -404,8 +425,9 @@ public long getMaxAutoConnectRetryTime() {
404425
405426 /**
406427 * The read preference to use for queries, map-reduce, aggregation, and count.
407- * <p>
428+ * <p/ >
408429 * Default is {@code ReadPreference.primary()}.
430+ *
409431 * @return the read preference
410432 * @see com.mongodb.ReadPreference#primary()
411433 */
@@ -433,8 +455,9 @@ public DBEncoderFactory getDbEncoderFactory() {
433455
434456 /**
435457 * The write concern to use.
436- * <p>
458+ * <p/ >
437459 * Default is {@code WriteConcern.ACKNOWLEDGED}.
460+ *
438461 * @return the write concern
439462 * @see WriteConcern#ACKNOWLEDGED
440463 */
@@ -444,7 +467,7 @@ public WriteConcern getWriteConcern() {
444467
445468 /**
446469 * The socket factory for creating sockets to the mongo server.
447- * <p>
470+ * <p/ >
448471 * Default is SocketFactory.getDefault()
449472 *
450473 * @return the socket factory
@@ -454,9 +477,9 @@ public SocketFactory getSocketFactory() {
454477 }
455478
456479 /**
457- * Sets whether there is a a finalize method created that cleans up instances of DBCursor that the client
480+ * Gets whether there is a a finalize method created that cleans up instances of DBCursor that the client
458481 * does not close. If you are careful to always call the close method of DBCursor, then this can safely be set to false.
459- * <p>
482+ * <p/ >
460483 * Default is true.
461484 *
462485 * @return whether finalizers are enabled on cursors
@@ -467,6 +490,18 @@ public boolean isCursorFinalizerEnabled() {
467490 return cursorFinalizerEnabled ;
468491 }
469492
493+ /**
494+ * Gets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is
495+ * Java 6 or greater. If false, the driver will use MXBeans if the VM is Java 6 or greater, and use MBeans if
496+ * the VM is Java 5.
497+ * <p>
498+ * Default is false.
499+ * </p>
500+ */
501+ public boolean isAlwaysUseMBeans () {
502+ return alwaysUseMBeans ;
503+ }
504+
470505 private MongoClientOptions (final Builder builder ) {
471506 description = builder .description ;
472507 connectionsPerHost = builder .connectionsPerHost ;
@@ -483,6 +518,7 @@ private MongoClientOptions(final Builder builder) {
483518 writeConcern = builder .writeConcern ;
484519 socketFactory = builder .socketFactory ;
485520 cursorFinalizerEnabled = builder .cursorFinalizerEnabled ;
521+ alwaysUseMBeans = builder .alwaysUseMBeans ;
486522 }
487523
488524
@@ -501,4 +537,5 @@ private MongoClientOptions(final Builder builder) {
501537 private final WriteConcern writeConcern ;
502538 private final SocketFactory socketFactory ;
503539 private final boolean cursorFinalizerEnabled ;
540+ private final boolean alwaysUseMBeans ;
504541}
0 commit comments