com.mongodb
Class MongoClientOptions

java.lang.Object
  extended by com.mongodb.MongoClientOptions

@Immutable
public class MongoClientOptions
extends Object

Various settings to control the behavior of a MongoClient.

Note: This class is a replacement for MongoOptions, to be used with MongoClient. The main difference in behavior is that the default write concern is WriteConcern.ACKNOWLEDGED.

Since:
2.10.0
See Also:
MongoClient

Nested Class Summary
static class MongoClientOptions.Builder
          A builder for MongoClientOptions so that MongoClientOptions can be immutable, and to support easier construction through chaining.
 
Method Summary
static MongoClientOptions.Builder builder()
          Create a new Builder instance.
 boolean equals(Object o)
           
 int getConnectionsPerHost()
          The maximum number of connections allowed per host for this MongoClient instance.
 int getConnectTimeout()
          The connection timeout in milliseconds.
 DBDecoderFactory getDbDecoderFactory()
          Override the decoder factory.
 DBEncoderFactory getDbEncoderFactory()
          Override the encoder factory.
 String getDescription()
          Gets the description for this MongoClient, which is used in various places like logging and JMX.
 long getMaxAutoConnectRetryTime()
          The maximum amount of time in MS to spend retrying to open connection to the same server.
 int getMaxWaitTime()
          The maximum wait time in milliseconds that a thread may wait for a connection to become available.
 ReadPreference getReadPreference()
          The read preference to use for queries, map-reduce, aggregation, and count.
 SocketFactory getSocketFactory()
          The socket factory for creating sockets to the mongo server.
 int getSocketTimeout()
          The socket timeout in milliseconds.
 int getThreadsAllowedToBlockForConnectionMultiplier()
          this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool.
 WriteConcern getWriteConcern()
          The write concern to use.
 int hashCode()
           
 boolean isAlwaysUseMBeans()
          Gets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is Java 6 or greater.
 boolean isAutoConnectRetry()
          If true, the driver will keep trying to connect to the same server in case that the socket cannot be established.
 boolean isCursorFinalizerEnabled()
          Gets whether there is a a finalize method created that cleans up instances of DBCursor that the client does not close.
 boolean isSocketKeepAlive()
          This flag controls the socket keep alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean)

* Default is false.

 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

builder

public static MongoClientOptions.Builder builder()
Create a new Builder instance. This is a convenience method, equivalent to new MongoClientOptions.Builder().

Returns:
a new instance of a Builder

getDescription

public String getDescription()
Gets the description for this MongoClient, which is used in various places like logging and JMX.

Default is null.

Returns:
the description

getConnectionsPerHost

public int getConnectionsPerHost()
The maximum number of connections allowed per host for this MongoClient instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.

Default is 100.

Returns:
the maximum size of the connection pool per host
See Also:
getThreadsAllowedToBlockForConnectionMultiplier()

getThreadsAllowedToBlockForConnectionMultiplier

public int getThreadsAllowedToBlockForConnectionMultiplier()
this multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool. All further threads will get an exception right away. For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50 threads can wait for a connection.

Default is 5.

Returns:
the multiplier

getMaxWaitTime

public int getMaxWaitTime()
The maximum wait time in milliseconds that a thread may wait for a connection to become available.

Default is 120,000. A value of 0 means that it will not wait. A negative value means to wait indefinitely.

Returns:
the maximum wait time.

getConnectTimeout

public int getConnectTimeout()
The connection timeout in milliseconds. A value of 0 means no timeout. It is used solely when establishing a new connection Socket.connect(java.net.SocketAddress, int)

Default is 10,000.

Returns:
the socket connect timeout

getSocketTimeout

public int getSocketTimeout()
The socket timeout in milliseconds. It is used for I/O socket read and write operations Socket.setSoTimeout(int)

Default is 0 and means no timeout.

Returns:
the socket timeout

isSocketKeepAlive

public boolean isSocketKeepAlive()
This flag controls the socket keep alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean)

* Default is false.

Returns:
whether keep-alive is enabled on each socket

isAutoConnectRetry

public boolean isAutoConnectRetry()
If true, the driver will keep trying to connect to the same server in case that the socket cannot be established. There is maximum amount of time to keep retrying, which is 15s by default. This can be useful to avoid some exceptions being thrown when a server is down temporarily by blocking the operations. It also can be useful to smooth the transition to a new master (so that a new master is elected within the retry time). Note that when using this flag: - 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 - this does not prevent exception from being thrown in read/write operations on the socket, which must be handled by application

Even if this flag is false, the driver already has mechanisms to automatically recreate broken connections and retry the read operations. Default is false.

Returns:
whether socket connect is retried

getMaxAutoConnectRetryTime

public long getMaxAutoConnectRetryTime()
The maximum amount of time in MS to spend retrying to open connection to the same server. Default is 0, which means to use the default 15s if autoConnectRetry is on.

Returns:
the maximum socket connect retry time.

getReadPreference

public ReadPreference getReadPreference()
The read preference to use for queries, map-reduce, aggregation, and count.

Default is ReadPreference.primary().

Returns:
the read preference
See Also:
ReadPreference.primary()

getDbDecoderFactory

public DBDecoderFactory getDbDecoderFactory()
Override the decoder factory. Default is for the standard Mongo Java driver configuration.

Returns:
the decoder factory

getDbEncoderFactory

public DBEncoderFactory getDbEncoderFactory()
Override the encoder factory. Default is for the standard Mongo Java driver configuration.

Returns:
the encoder factory

getWriteConcern

public WriteConcern getWriteConcern()
The write concern to use.

Default is WriteConcern.ACKNOWLEDGED.

Returns:
the write concern
See Also:
WriteConcern.ACKNOWLEDGED

getSocketFactory

public SocketFactory getSocketFactory()
The socket factory for creating sockets to the mongo server.

Default is SocketFactory.getDefault()

Returns:
the socket factory

isCursorFinalizerEnabled

public boolean isCursorFinalizerEnabled()
Gets whether there is a a finalize method created that cleans up instances of DBCursor that the client does not close. If you are careful to always call the close method of DBCursor, then this can safely be set to false.

Default is true.

Returns:
whether finalizers are enabled on cursors
See Also:
DBCursor, DBCursor.close()

isAlwaysUseMBeans

public boolean isAlwaysUseMBeans()
Gets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is Java 6 or greater. If false, the driver will use MXBeans if the VM is Java 6 or greater, and use MBeans if the VM is Java 5.

Default is false.


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object