@NotThreadSafe public static class MongoClientOptions.Builder extends Object
| Constructor and Description |
|---|
Builder()
Creates a Builder for MongoClientOptions, getting the appropriate system properties for initialization.
|
Builder(MongoClientOptions options)
Creates a Builder from an existing MongoClientOptions.
|
| Modifier and Type | Method and Description |
|---|---|
MongoClientOptions.Builder |
addClusterListener(ClusterListener clusterListener)
Adds the given cluster listener.
|
MongoClientOptions.Builder |
addCommandListener(CommandListener commandListener)
Adds the given command listener.
|
MongoClientOptions.Builder |
addServerListener(ServerListener serverListener)
Adds the given server listener.
|
MongoClientOptions.Builder |
addServerMonitorListener(ServerMonitorListener serverMonitorListener)
Adds the given server monitro listener.
|
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 |
applicationName(String applicationName)
Sets the logical name of the application using this MongoClient.
|
MongoClientOptions |
build()
Build an instance of MongoClientOptions.
|
MongoClientOptions.Builder |
codecRegistry(CodecRegistry codecRegistry)
Sets the codec registry
|
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 |
heartbeatConnectTimeout(int connectTimeout)
Sets the connect timeout for connections used for the cluster heartbeat.
|
MongoClientOptions.Builder |
heartbeatFrequency(int heartbeatFrequency)
Sets the heartbeat frequency.
|
MongoClientOptions.Builder |
heartbeatSocketTimeout(int socketTimeout)
Sets the socket timeout for connections used for the cluster heartbeat.
|
MongoClientOptions.Builder |
legacyDefaults()
Sets defaults to be what they are in
MongoOptions. |
MongoClientOptions.Builder |
localThreshold(int localThreshold)
Sets the local threshold.
|
MongoClientOptions.Builder |
maxConnectionIdleTime(int maxConnectionIdleTime)
Sets the maximum idle time for a pooled connection.
|
MongoClientOptions.Builder |
maxConnectionLifeTime(int maxConnectionLifeTime)
Sets the maximum life time for a pooled connection.
|
MongoClientOptions.Builder |
maxWaitTime(int maxWaitTime)
Sets the maximum time that a thread will block waiting for a connection.
|
MongoClientOptions.Builder |
minConnectionsPerHost(int minConnectionsPerHost)
Sets the minimum number of connections per host.
|
MongoClientOptions.Builder |
minHeartbeatFrequency(int minHeartbeatFrequency)
Sets the minimum heartbeat frequency.
|
MongoClientOptions.Builder |
readConcern(ReadConcern readConcern)
Sets the read concern.
|
MongoClientOptions.Builder |
readPreference(ReadPreference readPreference)
Sets the read preference.
|
MongoClientOptions.Builder |
requiredReplicaSetName(String requiredReplicaSetName)
Sets the required replica set name for the cluster.
|
MongoClientOptions.Builder |
serverSelectionTimeout(int serverSelectionTimeout)
Sets the server selection timeout in milliseconds, which defines how long the driver will wait for server selection to
succeed before throwing an exception.
|
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 |
sslEnabled(boolean sslEnabled)
Sets whether to use SSL.
|
MongoClientOptions.Builder |
sslInvalidHostNameAllowed(boolean sslInvalidHostNameAllowed)
Define whether invalid host names should be allowed.
|
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.
|
public Builder()
public Builder(MongoClientOptions options)
options - create a builder from existing optionspublic MongoClientOptions.Builder description(String description)
description - the description of this MongoClientthisMongoClientOptions.getDescription()public MongoClientOptions.Builder applicationName(String applicationName)
applicationName - the logical name of the application using this MongoClient. It may be null.
The UTF-8 encoding may not exceed 128 bytes.thisMongoClientOptions.getApplicationName()public MongoClientOptions.Builder minConnectionsPerHost(int minConnectionsPerHost)
minConnectionsPerHost - minimum number of connectionsthisIllegalArgumentException - if minConnectionsPerHost < 0MongoClientOptions.getMinConnectionsPerHost()public MongoClientOptions.Builder connectionsPerHost(int connectionsPerHost)
connectionsPerHost - maximum number of connectionsthisIllegalArgumentException - if connectionsPerHost < 1MongoClientOptions.getConnectionsPerHost()public MongoClientOptions.Builder threadsAllowedToBlockForConnectionMultiplier(int threadsAllowedToBlockForConnectionMultiplier)
threadsAllowedToBlockForConnectionMultiplier - the multiplierthisIllegalArgumentException - if threadsAllowedToBlockForConnectionMultiplier < 1MongoClientOptions.getThreadsAllowedToBlockForConnectionMultiplier()public MongoClientOptions.Builder serverSelectionTimeout(int serverSelectionTimeout)
Sets the server selection timeout in milliseconds, which defines how long the driver will wait for server selection to succeed before throwing an exception.
A value of 0 means that it will timeout immediately if no server is available. A negative value means to wait indefinitely.
serverSelectionTimeout - the server selection timeout, in millisecondsthisMongoClientOptions.getServerSelectionTimeout()public MongoClientOptions.Builder maxWaitTime(int maxWaitTime)
maxWaitTime - the maximum wait time, in millisecondsthisMongoClientOptions.getMaxWaitTime()public MongoClientOptions.Builder maxConnectionIdleTime(int maxConnectionIdleTime)
maxConnectionIdleTime - the maximum idle time, in milliseconds, which must be > 0thisIllegalArgumentException - if maxConnectionIdleTime <= 0MongoClientOptions.getMaxConnectionIdleTime()public MongoClientOptions.Builder maxConnectionLifeTime(int maxConnectionLifeTime)
maxConnectionLifeTime - the maximum life time, in milliseconds, which must be > 0thisIllegalArgumentException - if maxConnectionLifeTime <= 0MongoClientOptions.getMaxConnectionIdleTime()public MongoClientOptions.Builder connectTimeout(int connectTimeout)
connectTimeout - the connection timeout, in milliseconds, which must be > 0thisIllegalArgumentException - if connectTimeout <= 0MongoClientOptions.getConnectTimeout()public MongoClientOptions.Builder socketTimeout(int socketTimeout)
socketTimeout - the socket timeout, in millisecondsthisMongoClientOptions.getSocketTimeout()public MongoClientOptions.Builder socketKeepAlive(boolean socketKeepAlive)
socketKeepAlive - keep alivethisMongoClientOptions.isSocketKeepAlive()public MongoClientOptions.Builder sslEnabled(boolean sslEnabled)
SSLSocketFactory.getDefault() and
setting it to false will set the socketFactory to SocketFactory.getDefault()sslEnabled - set to true if using SSLthisMongoClientOptions.isSslEnabled()public MongoClientOptions.Builder sslInvalidHostNameAllowed(boolean sslInvalidHostNameAllowed)
sslInvalidHostNameAllowed - whether invalid host names are allowed in SSL certificates.public MongoClientOptions.Builder readPreference(ReadPreference readPreference)
readPreference - read preferencethisMongoClientOptions.getReadPreference()public MongoClientOptions.Builder writeConcern(WriteConcern writeConcern)
writeConcern - the write concernthisMongoClientOptions.getWriteConcern()public MongoClientOptions.Builder readConcern(ReadConcern readConcern)
readConcern - the read concern.MongoClientOptions.getReadConcern()public MongoClientOptions.Builder codecRegistry(CodecRegistry codecRegistry)
Note that instances of DB and DBCollection do not use the registry, so it's not necessary to include a
codec for DBObject in the registry.
codecRegistry - the codec registrythisMongoClientOptions.getCodecRegistry()public MongoClientOptions.Builder addCommandListener(CommandListener commandListener)
commandListener - the non-null command listenerpublic MongoClientOptions.Builder addClusterListener(ClusterListener clusterListener)
clusterListener - the non-null cluster listenerpublic MongoClientOptions.Builder addServerListener(ServerListener serverListener)
serverListener - the non-null server listenerpublic MongoClientOptions.Builder addServerMonitorListener(ServerMonitorListener serverMonitorListener)
serverMonitorListener - the non-null server monitor listenerpublic MongoClientOptions.Builder socketFactory(SocketFactory socketFactory)
socketFactory - the socket factorythisMongoClientOptions.getSocketFactory()public MongoClientOptions.Builder cursorFinalizerEnabled(boolean cursorFinalizerEnabled)
cursorFinalizerEnabled - whether cursor finalizers are enabled.thisMongoClientOptions.isCursorFinalizerEnabled()public MongoClientOptions.Builder alwaysUseMBeans(boolean alwaysUseMBeans)
alwaysUseMBeans - true if driver should always use MBeans, regardless of VM versionMongoClientOptions.isAlwaysUseMBeans()public MongoClientOptions.Builder dbDecoderFactory(DBDecoderFactory dbDecoderFactory)
dbDecoderFactory - the decoder factorythisMongoClientOptions.getDbDecoderFactory()public MongoClientOptions.Builder dbEncoderFactory(DBEncoderFactory dbEncoderFactory)
dbEncoderFactory - the encoder factorythisMongoClientOptions.getDbEncoderFactory()public MongoClientOptions.Builder heartbeatFrequency(int heartbeatFrequency)
heartbeatFrequency - the heartbeat frequency for the cluster, in milliseconds, which must be > 0thisIllegalArgumentException - if heartbeatFrequency is not > 0MongoClientOptions.getHeartbeatFrequency()public MongoClientOptions.Builder minHeartbeatFrequency(int minHeartbeatFrequency)
minHeartbeatFrequency - the minimum heartbeat frequency, in milliseconds, which must be > 0thisIllegalArgumentException - if minHeartbeatFrequency <= 0MongoClientOptions.getMinHeartbeatFrequency()public MongoClientOptions.Builder heartbeatConnectTimeout(int connectTimeout)
connectTimeout - the connection timeout, in millisecondsthisMongoClientOptions.getHeartbeatConnectTimeout()public MongoClientOptions.Builder heartbeatSocketTimeout(int socketTimeout)
socketTimeout - the socket timeout, in millisecondsthisMongoClientOptions.getHeartbeatSocketTimeout()public MongoClientOptions.Builder localThreshold(int localThreshold)
localThreshold - the acceptable latency difference, in milliseconds, which must be >= 0thisIllegalArgumentException - if localThreshold < 0MongoClientOptions.getLocalThreshold()public MongoClientOptions.Builder requiredReplicaSetName(String requiredReplicaSetName)
requiredReplicaSetName - the required replica set name for the replica set.MongoClientOptions.getRequiredReplicaSetName()public MongoClientOptions.Builder legacyDefaults()
MongoOptions.thisMongoOptionspublic MongoClientOptions build()