@NotThreadSafe public static class MongoClientOptions.Builder extends Object
Constructor | 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 | 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 |
compressorListâ(List<MongoCompressor> compressorList) |
Sets the compressors to use for compressing messages to the server.
|
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 |
retryWritesâ(boolean retryWrites) |
Sets whether writes should be retried if they fail due to a network error.
|
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 |
serverSelectorâ(ServerSelector serverSelector) |
Sets a server selector that augments the normal server selection rules applied by the driver when determining
which server to send an operation to.
|
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 compressorListâ(List<MongoCompressor> compressorList)
compressorList
- the list of compressors to requestthis
MongoClientOptions.getCompressorList()
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 retryWritesâ(boolean retryWrites)
retryWrites
- sets if writes should be retried if they fail due to a network error.this
MongoClientOptions.getRetryWrites()
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 serverSelectorâ(ServerSelector serverSelector)
MongoClientOptions.getServerSelector()
for further details.serverSelector
- the server selectorMongoClientOptions.getServerSelector()
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â()