com.mongodb
Class MongoOptions

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

public class MongoOptions
extends Object

Various settings for the driver


Field Summary
 boolean autoConnectRetry
          If true, the driver will keep trying to connect to the same server in case that the socket cannot be established.
 int connectionsPerHost
          The maximum number of connections allowed per host for this Mongo instance.
 int connectTimeout
          The connection timeout in milliseconds.
 DBDecoderFactory dbDecoderFactory
          Override the DBCallback factory.
 DBEncoderFactory dbEncoderFactory
          Override the encoding factory.
 String description
          The description for Mongo instances created with these options.
 boolean fsync
          The "fsync" value of the global WriteConcern.
 boolean j
          The "j" value of the global WriteConcern.
 long maxAutoConnectRetryTime
          The maximum amount of time in MS to spend retrying to open connection to the same server.
 int maxWaitTime
          The maximum wait time in ms that a thread may wait for a connection to become available.
 boolean safe
          If true the driver will use a WriteConcern of WriteConcern.SAFE for all operations.
 boolean slaveOk
          Deprecated. Replaced in MongoDB 2.0/Java Driver 2.7 with ReadPreference.SECONDARY
 SocketFactory socketFactory
          sets the socket factory for creating sockets to mongod Default is SocketFactory.getDefault()
 boolean socketKeepAlive
          This flag controls the socket keep alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean) Default is false.
 int socketTimeout
          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.
 int threadsAllowedToBlockForConnectionMultiplier
          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.
 int w
          The "w" value of the global WriteConcern.
 int wtimeout
          The "wtimeout" value of the global WriteConcern.
 
Constructor Summary
MongoOptions()
           
 
Method Summary
 WriteConcern getWriteConcern()
          Helper method to return the appropriate WriteConcern instance based on the current related options settings.
 void reset()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

description

public String description

The description for Mongo instances created with these options. This is used in various places like logging.


connectionsPerHost

public int connectionsPerHost
The maximum number of connections allowed per host for this Mongo 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 10.

See Also:
MongoOptions#threadsAllowedToBlockForConnectionMultiplier}


threadsAllowedToBlockForConnectionMultiplier

public int threadsAllowedToBlockForConnectionMultiplier
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.


maxWaitTime

public int maxWaitTime
The maximum wait time in ms that a thread may wait for a connection to become available. Default is 120,000.


connectTimeout

public int connectTimeout
The connection timeout in milliseconds. It is used solely when establishing a new connection Socket.connect(java.net.SocketAddress, int) Default is 0 and means no timeout.


socketTimeout

public int socketTimeout
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.


socketKeepAlive

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


autoConnectRetry

public boolean autoConnectRetry
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.


maxAutoConnectRetryTime

public long maxAutoConnectRetryTime
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.


slaveOk

@Deprecated
public boolean slaveOk
Deprecated. Replaced in MongoDB 2.0/Java Driver 2.7 with ReadPreference.SECONDARY
This flag specifies if the driver is allowed to read from secondary (slave) servers. Specifically in the current implementation, the driver will avoid reading from the primary server and round robin requests to secondaries. Driver also factors in the latency to secondaries when choosing a server. Note that reading from secondaries can increase performance and reliability, but it may result in temporary inconsistent results. Default is false.

See Also:
com.mongodb.ReadPreference.SECONDARY

dbDecoderFactory

public DBDecoderFactory dbDecoderFactory
Override the DBCallback factory. Default is for the standard Mongo Java driver configuration.


dbEncoderFactory

public DBEncoderFactory dbEncoderFactory
Override the encoding factory. Default is for the standard Mongo Java driver configuration.


safe

public boolean safe
If true the driver will use a WriteConcern of WriteConcern.SAFE for all operations. If w, wtimeout, fsync or j are specified, this setting is ignored. Default is false.


w

public int w
The "w" value of the global WriteConcern. Default is 0.


wtimeout

public int wtimeout
The "wtimeout" value of the global WriteConcern. Default is 0.


fsync

public boolean fsync
The "fsync" value of the global WriteConcern. Default is false.


j

public boolean j
The "j" value of the global WriteConcern. Default is false.


socketFactory

public SocketFactory socketFactory
sets the socket factory for creating sockets to mongod Default is SocketFactory.getDefault()

Constructor Detail

MongoOptions

public MongoOptions()
Method Detail

reset

public void reset()

getWriteConcern

public WriteConcern getWriteConcern()
Helper method to return the appropriate WriteConcern instance based on the current related options settings.


toString

public String toString()
Overrides:
toString in class Object