Package com.mongodb
Class MongoClientSettings
- java.lang.Object
-
- com.mongodb.MongoClientSettings
-
@Immutable public final class MongoClientSettings extends Object
Various settings to control the behavior of aMongoClient
.- Since:
- 3.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MongoClientSettings.Builder
A builder forMongoClientSettings
so thatMongoClientSettings
can be immutable, and to support easier construction through chaining.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MongoClientSettings.Builder
builder()
Convenience method to create a Builder.static MongoClientSettings.Builder
builder(MongoClientSettings settings)
Convenience method to create a from an existingMongoClientSettings
.String
getApplicationName()
Gets the logical name of the application using this MongoClient.ClusterSettings
getClusterSettings()
Gets the cluster settings.CodecRegistry
getCodecRegistry()
The codec registry to use, or null if not set.List<CommandListener>
getCommandListeners()
Gets the list of addedCommandListener
.List<MongoCompressor>
getCompressorList()
Gets the compressors to use for compressing messages to the server.ConnectionPoolSettings
getConnectionPoolSettings()
Gets the settings for the connection provider in a settings object.MongoCredential
getCredential()
Gets the credential.static CodecRegistry
getDefaultCodecRegistry()
Gets the default codec registry.SocketSettings
getHeartbeatSocketSettings()
Gets the connection settings for the heartbeat thread (the background task that checks the state of the cluster) wrapped in a settings object.ReadConcern
getReadConcern()
The read concern to use.ReadPreference
getReadPreference()
The read preference to use for queries, map-reduce, aggregation, and count.boolean
getRetryWrites()
Returns true if writes should be retried if they fail due to a network error.ServerSettings
getServerSettings()
Gets the server-specific settings wrapped in a settings object.SocketSettings
getSocketSettings()
Gets the connection-specific settings wrapped in a settings object.SslSettings
getSslSettings()
Gets the SSL settings.StreamFactoryFactory
getStreamFactoryFactory()
Gets the factory to use to create aStreamFactory
.WriteConcern
getWriteConcern()
The write concern to use.
-
-
-
Method Detail
-
getDefaultCodecRegistry
public static CodecRegistry getDefaultCodecRegistry()
Gets the default codec registry. It includes the following providers:- Returns:
- the default codec registry
-
builder
public static MongoClientSettings.Builder builder()
Convenience method to create a Builder.- Returns:
- a builder
-
builder
public static MongoClientSettings.Builder builder(MongoClientSettings settings)
Convenience method to create a from an existingMongoClientSettings
.- Parameters:
settings
- create a builder from existing settings- Returns:
- a builder
-
getReadPreference
public ReadPreference getReadPreference()
The read preference to use for queries, map-reduce, aggregation, and count.Default is
ReadPreference.primary()
.- Returns:
- the read preference
- See Also:
ReadPreference.primary()
-
getCredential
@Nullable public MongoCredential getCredential()
Gets the credential.- Returns:
- the credential, which may be null
-
getWriteConcern
public WriteConcern getWriteConcern()
The write concern to use.Default is
WriteConcern.ACKNOWLEDGED
.- Returns:
- the write concern
- See Also:
WriteConcern.ACKNOWLEDGED
-
getRetryWrites
public boolean getRetryWrites()
Returns true if writes should be retried if they fail due to a network error. The default is false.- Returns:
- the retryWrites value
- Since server release
- 3.6
-
getReadConcern
public ReadConcern getReadConcern()
The read concern to use.- Returns:
- the read concern
- MongoDB documentation
- Read Concern
- Since server release
- 3.2
-
getCodecRegistry
public CodecRegistry getCodecRegistry()
The codec registry to use, or null if not set.- Returns:
- the codec registry
-
getStreamFactoryFactory
@Nullable public StreamFactoryFactory getStreamFactoryFactory()
Gets the factory to use to create aStreamFactory
.- Returns:
- the stream factory factory
-
getCommandListeners
public List<CommandListener> getCommandListeners()
Gets the list of addedCommandListener
.The default is an empty list.
- Returns:
- the unmodifiable list of command listeners
-
getApplicationName
@Nullable public String getApplicationName()
Gets the logical name of the application using this MongoClient. The application name may be used by the client to identify the application to the server, for use in server logs, slow query logs, and profile collection.Default is null.
- Returns:
- the application name, which may be null
- Since server release
- 3.4
-
getCompressorList
public List<MongoCompressor> getCompressorList()
Gets the compressors to use for compressing messages to the server. The driver will use the first compressor in the list that the server is configured to support.Default is the empty list.
- Returns:
- the compressors
- Since server release
- 3.4
-
getClusterSettings
public ClusterSettings getClusterSettings()
Gets the cluster settings.- Returns:
- the cluster settings
-
getSslSettings
public SslSettings getSslSettings()
Gets the SSL settings.- Returns:
- the SSL settings
-
getSocketSettings
public SocketSettings getSocketSettings()
Gets the connection-specific settings wrapped in a settings object. This settings object uses the values for connectTimeout, socketTimeout and socketKeepAlive.- Returns:
- a SocketSettings object populated with the connection settings from this
MongoClientSettings
instance. - See Also:
SocketSettings
-
getHeartbeatSocketSettings
public SocketSettings getHeartbeatSocketSettings()
Gets the connection settings for the heartbeat thread (the background task that checks the state of the cluster) wrapped in a settings object.- Returns:
- the SocketSettings for the heartbeat thread
- See Also:
SocketSettings
-
getConnectionPoolSettings
public ConnectionPoolSettings getConnectionPoolSettings()
Gets the settings for the connection provider in a settings object. This settings object wraps the values for minConnectionPoolSize, maxConnectionPoolSize, maxWaitTime, maxConnectionIdleTime and maxConnectionLifeTime, and uses maxConnectionPoolSize and threadsAllowedToBlockForConnectionMultiplier to calculate maxWaitQueueSize.- Returns:
- a ConnectionPoolSettings populated with the settings from this
MongoClientSettings
instance that relate to the connection provider. - See Also:
ConnectionPoolSettings
-
getServerSettings
public ServerSettings getServerSettings()
Gets the server-specific settings wrapped in a settings object. This settings object uses the heartbeatFrequency and minHeartbeatFrequency values from thisMongoClientSettings
instance.- Returns:
- a ServerSettings
- See Also:
ServerSettings
-
-