@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 |
addConnectionPoolListener(ConnectionPoolListener connectionPoolListener)
Adds the given connection pool listener.
|
MongoClientOptions.Builder |
addServerListener(ServerListener serverListener)
Adds the given server listener.
|
MongoClientOptions.Builder |
addServerMonitorListener(ServerMonitorListener serverMonitorListener)
Adds the given server monitor 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)
Deprecated.
configuring keep-alive has been deprecated. It now defaults to true and disabling it is not recommended.
|
MongoClientOptions.Builder |
socketTimeout(int socketTimeout)
Sets the socket timeout.
|
MongoClientOptions.Builder |
sslContext(SSLContext sslContext)
Sets the SSLContext to be used with SSL is enabled.
|
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 MongoClientthis
MongoClientOptions.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.this
MongoClientOptions.getApplicationName()
public MongoClientOptions.Builder minConnectionsPerHost(int minConnectionsPerHost)
minConnectionsPerHost
- minimum number of connectionsthis
IllegalArgumentException
- if minConnectionsPerHost < 0
MongoClientOptions.getMinConnectionsPerHost()
public MongoClientOptions.Builder connectionsPerHost(int connectionsPerHost)
connectionsPerHost
- maximum number of connectionsthis
IllegalArgumentException
- if connectionsPerHost < 1
MongoClientOptions.getConnectionsPerHost()
public MongoClientOptions.Builder threadsAllowedToBlockForConnectionMultiplier(int threadsAllowedToBlockForConnectionMultiplier)
threadsAllowedToBlockForConnectionMultiplier
- the multiplierthis
IllegalArgumentException
- if threadsAllowedToBlockForConnectionMultiplier < 1
MongoClientOptions.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 millisecondsthis
MongoClientOptions.getServerSelectionTimeout()
public MongoClientOptions.Builder maxWaitTime(int maxWaitTime)
maxWaitTime
- the maximum wait time, in millisecondsthis
MongoClientOptions.getMaxWaitTime()
public MongoClientOptions.Builder maxConnectionIdleTime(int maxConnectionIdleTime)
maxConnectionIdleTime
- the maximum idle time, in milliseconds, which must be >= 0.
A zero value indicates no limit to the life time.this
IllegalArgumentException
- if maxConnectionIdleTime < 0
MongoClientOptions.getMaxConnectionIdleTime()
public MongoClientOptions.Builder maxConnectionLifeTime(int maxConnectionLifeTime)
maxConnectionLifeTime
- the maximum life time, in milliseconds, which must be >= 0.
A zero value indicates no limit to the life time.this
IllegalArgumentException
- if maxConnectionLifeTime < 0
MongoClientOptions.getMaxConnectionIdleTime()
public MongoClientOptions.Builder connectTimeout(int connectTimeout)
connectTimeout
- the connection timeout, in milliseconds, which must be > 0this
IllegalArgumentException
- if connectTimeout <= 0
MongoClientOptions.getConnectTimeout()
public MongoClientOptions.Builder socketTimeout(int socketTimeout)
socketTimeout
- the socket timeout, in millisecondsthis
MongoClientOptions.getSocketTimeout()
@Deprecated public MongoClientOptions.Builder socketKeepAlive(boolean socketKeepAlive)
socketKeepAlive
- keep-alivethis
public MongoClientOptions.Builder sslEnabled(boolean sslEnabled)
If the socketFactory is unset, setting this to true will also set the socketFactory to
SSLSocketFactory.getDefault()
and setting it to false will set the socketFactory to
SocketFactory.getDefault()
If the socket factory is set and sslEnabled is also set, the socket factory must create instances of
SSLSocket
. Otherwise, MongoClient will refuse to connect.
sslEnabled
- set to true if using SSLthis
MongoClientOptions.isSslEnabled()
,
MongoClientOptions.getSocketFactory()
public MongoClientOptions.Builder sslInvalidHostNameAllowed(boolean sslInvalidHostNameAllowed)
sslInvalidHostNameAllowed
- whether invalid host names are allowed in SSL certificates.public MongoClientOptions.Builder sslContext(SSLContext sslContext)
sslContext
- the SSLContext to be used for SSL connectionsthis
public MongoClientOptions.Builder readPreference(ReadPreference readPreference)
readPreference
- read preferencethis
MongoClientOptions.getReadPreference()
public MongoClientOptions.Builder writeConcern(WriteConcern writeConcern)
writeConcern
- the write concernthis
MongoClientOptions.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 registrythis
MongoClientOptions.getCodecRegistry()
public MongoClientOptions.Builder addCommandListener(CommandListener commandListener)
commandListener
- the non-null command listenerpublic MongoClientOptions.Builder addConnectionPoolListener(ConnectionPoolListener connectionPoolListener)
connectionPoolListener
- the non-null connection pool 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 factorythis
MongoClientOptions.getSocketFactory()
public MongoClientOptions.Builder cursorFinalizerEnabled(boolean cursorFinalizerEnabled)
cursorFinalizerEnabled
- whether cursor finalizers are enabled.this
MongoClientOptions.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 factorythis
MongoClientOptions.getDbDecoderFactory()
public MongoClientOptions.Builder dbEncoderFactory(DBEncoderFactory dbEncoderFactory)
dbEncoderFactory
- the encoder factorythis
MongoClientOptions.getDbEncoderFactory()
public MongoClientOptions.Builder heartbeatFrequency(int heartbeatFrequency)
heartbeatFrequency
- the heartbeat frequency for the cluster, in milliseconds, which must be > 0this
IllegalArgumentException
- if heartbeatFrequency is not > 0MongoClientOptions.getHeartbeatFrequency()
public MongoClientOptions.Builder minHeartbeatFrequency(int minHeartbeatFrequency)
minHeartbeatFrequency
- the minimum heartbeat frequency, in milliseconds, which must be > 0this
IllegalArgumentException
- if minHeartbeatFrequency <= 0
MongoClientOptions.getMinHeartbeatFrequency()
public MongoClientOptions.Builder heartbeatConnectTimeout(int connectTimeout)
connectTimeout
- the connection timeout, in millisecondsthis
MongoClientOptions.getHeartbeatConnectTimeout()
public MongoClientOptions.Builder heartbeatSocketTimeout(int socketTimeout)
socketTimeout
- the socket timeout, in millisecondsthis
MongoClientOptions.getHeartbeatSocketTimeout()
public MongoClientOptions.Builder localThreshold(int localThreshold)
localThreshold
- the acceptable latency difference, in milliseconds, which must be >= 0this
IllegalArgumentException
- if localThreshold < 0
MongoClientOptions.getLocalThreshold()
public MongoClientOptions.Builder requiredReplicaSetName(String requiredReplicaSetName)
requiredReplicaSetName
- the required replica set name for the replica set.MongoClientOptions.getRequiredReplicaSetName()
public MongoClientOptions.Builder legacyDefaults()
MongoOptions
.this
MongoOptions
public MongoClientOptions build()