com.mongodb
Class MongoOptions

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

public class MongoOptions
extends Object

Various settings for a Mongo instance. Not thread safe, and superseded by MongoClientOptions. This class may be deprecated in a future release.

See Also:
MongoClientOptions, MongoClient

Field Summary
 boolean alwaysUseMBeans
          Sets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is Java 6 or greater.
 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.
 boolean cursorFinalizerEnabled
          Sets whether there is a a finalize method created that cleans up instances of DBCursor that the client does not close.
 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 milliseconds that a thread may wait for a connection to become available.
 ReadPreference readPreference
          Specifies the read preference.
 boolean safe
          If true the driver will use a WriteConcern of WriteConcern.SAFE for all operations.
 boolean slaveOk
          Deprecated. Replaced with ReadPreference.secondaryPreferred()
 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, (number of writes), of the global WriteConcern.
 WriteConcern writeConcern
          Sets the write concern.
 int wtimeout
          The "wtimeout" value of the global WriteConcern.
 
Constructor Summary
MongoOptions()
          Deprecated. 
MongoOptions(MongoClientOptions options)
          Deprecated. Replaced by MongoClientOptions
 
Method Summary
 MongoOptions copy()
           
 boolean equals(Object o)
           
 int getConnectionsPerHost()
           
 int getConnectTimeout()
           
 DBDecoderFactory getDbDecoderFactory()
           
 DBEncoderFactory getDbEncoderFactory()
           
 String getDescription()
           
 long getMaxAutoConnectRetryTime()
           
 int getMaxWaitTime()
           
 ReadPreference getReadPreference()
           
 SocketFactory getSocketFactory()
           
 int getSocketTimeout()
           
 int getThreadsAllowedToBlockForConnectionMultiplier()
           
 int getW()
           
 WriteConcern getWriteConcern()
          Helper method to return the appropriate WriteConcern instance based on the current related options settings.
 int getWtimeout()
           
 int hashCode()
           
 boolean isAlwaysUseMBeans()
           
 boolean isAutoConnectRetry()
           
 boolean isCursorFinalizerEnabled()
           
 boolean isFsync()
           
 boolean isJ()
           
 boolean isSafe()
           
 boolean isSocketKeepAlive()
           
 void reset()
           
 void setAlwaysUseMBeans(boolean alwaysUseMBeans)
           
 void setAutoConnectRetry(boolean retry)
           
 void setConnectionsPerHost(int connections)
           
 void setConnectTimeout(int timeoutMS)
           
 void setCursorFinalizerEnabled(boolean cursorFinalizerEnabled)
           
 void setDbDecoderFactory(DBDecoderFactory factory)
           
 void setDbEncoderFactory(DBEncoderFactory factory)
           
 void setDescription(String desc)
           
 void setFsync(boolean sync)
           
 void setJ(boolean safe)
           
 void setMaxAutoConnectRetryTime(long retryTimeMS)
           
 void setMaxWaitTime(int timeMS)
           
 void setReadPreference(ReadPreference readPreference)
           
 void setSafe(boolean isSafe)
           
 void setSocketFactory(SocketFactory factory)
           
 void setSocketKeepAlive(boolean keepAlive)
           
 void setSocketTimeout(int timeoutMS)
           
 void setThreadsAllowedToBlockForConnectionMultiplier(int threads)
           
 void setW(int val)
           
 void setWriteConcern(WriteConcern writeConcern)
           
 void setWtimeout(int timeoutMS)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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 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.


connectTimeout

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


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 with ReadPreference.secondaryPreferred()
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:
ReadPreference.secondaryPreferred()

readPreference

public ReadPreference readPreference
Specifies the read preference.


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, (number of writes), 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. true indicates writes should wait for data to be written to server data file Default is false.


j

public boolean j
The "j" value of the global WriteConcern. true indicates writes should wait for a journaling group commit Default is false.


socketFactory

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


cursorFinalizerEnabled

public boolean cursorFinalizerEnabled
Sets 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.

See Also:
Default is true.

writeConcern

public WriteConcern writeConcern
Sets the write concern. If this is not set, the write concern defaults to the combination of settings of the other write concern-related fields. If set, this will override all of the other write concern-related fields.

See Also:
w, safe, wtimeout, fsync, j

alwaysUseMBeans

public boolean alwaysUseMBeans
Sets 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.

Constructor Detail

MongoOptions

@Deprecated
public MongoOptions()
Deprecated. 


MongoOptions

@Deprecated
public MongoOptions(MongoClientOptions options)
Deprecated. Replaced by MongoClientOptions

Method Detail

reset

public void reset()

copy

public MongoOptions copy()

getWriteConcern

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


equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getDescription

public String getDescription()
Returns:
The description for MongoClient instances created with these options

setDescription

public void setDescription(String desc)
Parameters:
desc - The description for Mongo instances created with these options

getConnectionsPerHost

public int getConnectionsPerHost()
Returns:
the maximum number of connections allowed per host for this Mongo instance

setConnectionsPerHost

public void setConnectionsPerHost(int connections)
Parameters:
connections - sets the maximum number of connections allowed per host for this Mongo instance

getThreadsAllowedToBlockForConnectionMultiplier

public int getThreadsAllowedToBlockForConnectionMultiplier()
Returns:
the maximum number of threads that may be waiting for a connection

setThreadsAllowedToBlockForConnectionMultiplier

public void setThreadsAllowedToBlockForConnectionMultiplier(int threads)
Parameters:
threads - multiplied with connectionsPerHost, sets the maximum number of threads that may be waiting for a connection

getMaxWaitTime

public int getMaxWaitTime()
Returns:
The maximum time in milliseconds that threads wait for a connection

setMaxWaitTime

public void setMaxWaitTime(int timeMS)
Parameters:
timeMS - set the maximum time in milliseconds that threads wait for a connection

getConnectTimeout

public int getConnectTimeout()
Returns:
the connection timeout in milliseconds.

setConnectTimeout

public void setConnectTimeout(int timeoutMS)
Parameters:
timeoutMS - set the connection timeout in milliseconds.

getSocketTimeout

public int getSocketTimeout()
Returns:
The socket timeout in milliseconds

setSocketTimeout

public void setSocketTimeout(int timeoutMS)
Parameters:
timeoutMS - set the socket timeout in milliseconds

isSocketKeepAlive

public boolean isSocketKeepAlive()
Returns:
connection keep-alive flag

setSocketKeepAlive

public void setSocketKeepAlive(boolean keepAlive)
Parameters:
keepAlive - set connection keep-alive flag

isAutoConnectRetry

public boolean isAutoConnectRetry()
Returns:
keep trying connection flag

setAutoConnectRetry

public void setAutoConnectRetry(boolean retry)
Parameters:
retry - sets keep trying connection flag

getMaxAutoConnectRetryTime

public long getMaxAutoConnectRetryTime()
Returns:
max time in MS to retrying open connection

setMaxAutoConnectRetryTime

public void setMaxAutoConnectRetryTime(long retryTimeMS)
Parameters:
retryTimeMS - set max time in MS to retrying open connection

getDbDecoderFactory

public DBDecoderFactory getDbDecoderFactory()
Returns:
the DBCallback decoding factory

setDbDecoderFactory

public void setDbDecoderFactory(DBDecoderFactory factory)
Parameters:
factory - sets the DBCallback decoding factory

getDbEncoderFactory

public DBEncoderFactory getDbEncoderFactory()
Returns:
the encoding factory

setDbEncoderFactory

public void setDbEncoderFactory(DBEncoderFactory factory)
Parameters:
factory - sets the encoding factory

isSafe

public boolean isSafe()
Returns:
true if driver uses WriteConcern.SAFE for all operations.

setSafe

public void setSafe(boolean isSafe)
Parameters:
isSafe - true if driver uses WriteConcern.SAFE for all operations.

getW

public int getW()
Returns:
value returns the number of writes of the global WriteConcern.

setW

public void setW(int val)
Parameters:
val - set the number of writes of the global WriteConcern.

getWtimeout

public int getWtimeout()
Returns:
timeout for write operation

setWtimeout

public void setWtimeout(int timeoutMS)
Parameters:
timeoutMS - sets timeout for write operation

isFsync

public boolean isFsync()
Returns:
true if global write concern is set to fsync

setFsync

public void setFsync(boolean sync)
Parameters:
sync - sets global write concern's fsync safe value

isJ

public boolean isJ()
Returns:
true if global write concern is set to journal safe

setJ

public void setJ(boolean safe)
Parameters:
safe - sets global write concern's journal safe value

setWriteConcern

public void setWriteConcern(WriteConcern writeConcern)
Parameters:
writeConcern - sets the write concern

getSocketFactory

public SocketFactory getSocketFactory()
Returns:
the socket factory for creating sockets to mongod

setSocketFactory

public void setSocketFactory(SocketFactory factory)
Parameters:
factory - sets the socket factory for creating sockets to mongod

getReadPreference

public ReadPreference getReadPreference()
Returns:
the read preference

setReadPreference

public void setReadPreference(ReadPreference readPreference)
Parameters:
readPreference - the read preference

isCursorFinalizerEnabled

public boolean isCursorFinalizerEnabled()
Returns:
whether DBCursor finalizer is enabled

setCursorFinalizerEnabled

public void setCursorFinalizerEnabled(boolean cursorFinalizerEnabled)
Parameters:
cursorFinalizerEnabled - whether cursor finalizer is enabled

isAlwaysUseMBeans

public boolean isAlwaysUseMBeans()
Returns:
true if the driver should always use MBeans, regardless of VM

setAlwaysUseMBeans

public void setAlwaysUseMBeans(boolean alwaysUseMBeans)
Parameters:
alwaysUseMBeans - sets whether the driver should always use MBeans, regardless of VM

toString

public String toString()
Overrides:
toString in class Object