com.mongodb
Class MongoClientOptions.Builder

java.lang.Object
  extended by com.mongodb.MongoClientOptions.Builder
Enclosing class:
MongoClientOptions

public static class MongoClientOptions.Builder
extends Object

A builder for MongoClientOptions so that MongoClientOptions can be immutable, and to support easier construction through chaining.

Since:
2.10.0

Constructor Summary
MongoClientOptions.Builder()
           
 
Method Summary
 MongoClientOptions.Builder alwaysUseMBeans(boolean alwaysUseMBeans)
          Sets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is Java 6 or greater.
 MongoClientOptions.Builder autoConnectRetry(boolean autoConnectRetry)
          Sets whether auto connect retry is enabled.
 MongoClientOptions build()
          Build an instance of MongoClientOptions.
 MongoClientOptions.Builder connectionsPerHost(int connectionsPerHost)
          Sets the maximum number of connections per host.
 MongoClientOptions.Builder connectTimeout(int connectTimeout)
          Sets the connection timeout.
 MongoClientOptions.Builder cursorFinalizerEnabled(boolean cursorFinalizerEnabled)
          Sets whether cursor finalizers are enabled.
 MongoClientOptions.Builder dbDecoderFactory(DBDecoderFactory dbDecoderFactory)
          Sets the decoder factory.
 MongoClientOptions.Builder dbEncoderFactory(DBEncoderFactory dbEncoderFactory)
          Sets the encoder factory.
 MongoClientOptions.Builder description(String description)
          Sets the description.
 MongoClientOptions.Builder legacyDefaults()
          Sets defaults to be what they are in MongoOptions.
 MongoClientOptions.Builder maxAutoConnectRetryTime(long maxAutoConnectRetryTime)
          Sets the maximum auto connect retry time.
 MongoClientOptions.Builder maxWaitTime(int maxWaitTime)
          Sets the maximum time that a thread will block waiting for a connection.
 MongoClientOptions.Builder readPreference(ReadPreference readPreference)
          Sets the read preference.
 MongoClientOptions.Builder socketFactory(SocketFactory socketFactory)
          Sets the socket factory.
 MongoClientOptions.Builder socketKeepAlive(boolean socketKeepAlive)
          Sets whether socket keep alive is enabled.
 MongoClientOptions.Builder socketTimeout(int socketTimeout)
          Sets the socket timeout.
 MongoClientOptions.Builder threadsAllowedToBlockForConnectionMultiplier(int threadsAllowedToBlockForConnectionMultiplier)
          Sets the multiplier for number of threads allowed to block waiting for a connection.
 MongoClientOptions.Builder writeConcern(WriteConcern writeConcern)
          Sets the write concern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoClientOptions.Builder

public MongoClientOptions.Builder()
Method Detail

description

public MongoClientOptions.Builder description(String description)
Sets the description.

Parameters:
description - the description of this MongoClient
Returns:
this
See Also:
MongoClientOptions.getDescription()

connectionsPerHost

public MongoClientOptions.Builder connectionsPerHost(int connectionsPerHost)
Sets the maximum number of connections per host.

Parameters:
connectionsPerHost - maximum number of connections
Returns:
this
Throws:
IllegalArgumentException - if connnectionsPerHost < 1
See Also:
MongoClientOptions.getConnectionsPerHost()

threadsAllowedToBlockForConnectionMultiplier

public MongoClientOptions.Builder threadsAllowedToBlockForConnectionMultiplier(int threadsAllowedToBlockForConnectionMultiplier)
Sets the multiplier for number of threads allowed to block waiting for a connection.

Parameters:
threadsAllowedToBlockForConnectionMultiplier - the multiplier
Returns:
this
Throws:
IllegalArgumentException - if threadsAllowedToBlockForConnectionMultiplier < 1
See Also:
MongoClientOptions.getThreadsAllowedToBlockForConnectionMultiplier()

maxWaitTime

public MongoClientOptions.Builder maxWaitTime(int maxWaitTime)
Sets the maximum time that a thread will block waiting for a connection.

Parameters:
maxWaitTime - the maximum wait time
Returns:
this
Throws:
IllegalArgumentException - if maxWaitTime < 0
See Also:
MongoClientOptions.getMaxWaitTime()

connectTimeout

public MongoClientOptions.Builder connectTimeout(int connectTimeout)
Sets the connection timeout.

Parameters:
connectTimeout - the connection timeout
Returns:
this
See Also:
MongoClientOptions.getConnectTimeout()

socketTimeout

public MongoClientOptions.Builder socketTimeout(int socketTimeout)
Sets the socket timeout.

Parameters:
socketTimeout - the socket timeout
Returns:
this
See Also:
MongoClientOptions.getSocketTimeout()

socketKeepAlive

public MongoClientOptions.Builder socketKeepAlive(boolean socketKeepAlive)
Sets whether socket keep alive is enabled.

Parameters:
socketKeepAlive - keep alive
Returns:
this
See Also:
MongoClientOptions.isSocketKeepAlive()

autoConnectRetry

public MongoClientOptions.Builder autoConnectRetry(boolean autoConnectRetry)
Sets whether auto connect retry is enabled.

Parameters:
autoConnectRetry - auto connect retry
Returns:
this
See Also:
MongoClientOptions.isAutoConnectRetry()

maxAutoConnectRetryTime

public MongoClientOptions.Builder maxAutoConnectRetryTime(long maxAutoConnectRetryTime)
Sets the maximum auto connect retry time.

Parameters:
maxAutoConnectRetryTime - the maximum auto connect retry time
Returns:
this
See Also:
MongoClientOptions.getMaxAutoConnectRetryTime()

readPreference

public MongoClientOptions.Builder readPreference(ReadPreference readPreference)
Sets the read preference.

Parameters:
readPreference - read preference
Returns:
this
See Also:
MongoClientOptions.getReadPreference()

dbDecoderFactory

public MongoClientOptions.Builder dbDecoderFactory(DBDecoderFactory dbDecoderFactory)
Sets the decoder factory.

Parameters:
dbDecoderFactory - the decoder factory
Returns:
this
See Also:
MongoClientOptions.getDbDecoderFactory()

dbEncoderFactory

public MongoClientOptions.Builder dbEncoderFactory(DBEncoderFactory dbEncoderFactory)
Sets the encoder factory.

Parameters:
dbEncoderFactory - the encoder factory
Returns:
this
See Also:
MongoClientOptions.getDbEncoderFactory()

writeConcern

public MongoClientOptions.Builder writeConcern(WriteConcern writeConcern)
Sets the write concern.

Parameters:
writeConcern - the write concern
Returns:
this
See Also:
MongoClientOptions.getWriteConcern()

socketFactory

public MongoClientOptions.Builder socketFactory(SocketFactory socketFactory)
Sets the socket factory.

Parameters:
socketFactory - the socket factory
Returns:
this
See Also:
MongoClientOptions.getSocketFactory()

cursorFinalizerEnabled

public MongoClientOptions.Builder cursorFinalizerEnabled(boolean cursorFinalizerEnabled)
Sets whether cursor finalizers are enabled.

Parameters:
cursorFinalizerEnabled - whether cursor finalizers are enabled.
Returns:
this
See Also:
MongoClientOptions.isCursorFinalizerEnabled()

alwaysUseMBeans

public MongoClientOptions.Builder alwaysUseMBeans(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.

Parameters:
alwaysUseMBeans - true if driver should always use MBeans, regardless of VM version
Returns:
this
See Also:
MongoClientOptions.isAlwaysUseMBeans()

legacyDefaults

public MongoClientOptions.Builder legacyDefaults()
Sets defaults to be what they are in MongoOptions.

Returns:
this
See Also:
MongoOptions

build

public MongoClientOptions build()
Build an instance of MongoClientOptions.

Returns:
the options from this builder