@Immutable public class MongoClientOptions extends java.lang.Object
Various settings to control the behavior of a MongoClient
.
Note: This class is a replacement for MongoOptions
, to be used with MongoClient
. The main difference in behavior is
that the default write concern is WriteConcern.ACKNOWLEDGED
.
MongoClient
Modifier and Type | Class and Description |
---|---|
static class |
MongoClientOptions.Builder
A builder for MongoClientOptions so that MongoClientOptions can be immutable, and to support easier construction through chaining.
|
Modifier | Constructor and Description |
---|---|
private |
MongoClientOptions(MongoClientOptions.Builder builder) |
Modifier and Type | Method and Description |
---|---|
static MongoClientOptions.Builder |
builder()
Creates a builder instance.
|
static MongoClientOptions.Builder |
builder(MongoClientOptions options)
Creates a builder instance.
|
boolean |
equals(java.lang.Object o) |
java.lang.String |
getApplicationName()
Gets the logical name of the application using this MongoClient.
|
java.util.List<ClusterListener> |
getClusterListeners()
Gets the list of added
ClusterListener . |
CodecRegistry |
getCodecRegistry()
The codec registry to use.
|
java.util.List<CommandListener> |
getCommandListeners()
Gets the list of added
CommandListener . |
(package private) ConnectionPoolSettings |
getConnectionPoolSettings() |
int |
getConnectionsPerHost()
The maximum number of connections allowed per host for this MongoClient instance.
|
int |
getConnectTimeout()
The connection timeout in milliseconds.
|
DBDecoderFactory |
getDbDecoderFactory()
Override the decoder factory.
|
DBEncoderFactory |
getDbEncoderFactory()
Override the encoder factory.
|
java.lang.String |
getDescription()
Gets the description for this MongoClient, which is used in various places like logging and JMX.
|
int |
getHeartbeatConnectTimeout()
Gets the connect timeout for connections used for the cluster heartbeat.
|
int |
getHeartbeatFrequency()
Gets the heartbeat frequency.
|
(package private) SocketSettings |
getHeartbeatSocketSettings() |
int |
getHeartbeatSocketTimeout()
Gets the socket timeout for connections used for the cluster heartbeat.
|
int |
getLocalThreshold()
Gets the local threshold.
|
int |
getMaxConnectionIdleTime()
The maximum idle time of a pooled connection.
|
int |
getMaxConnectionLifeTime()
The maximum life time of a pooled connection.
|
int |
getMaxWaitTime()
The maximum wait time in milliseconds that a thread may wait for a connection to become available.
|
int |
getMinConnectionsPerHost()
The minimum number of connections per host for this MongoClient instance.
|
int |
getMinHeartbeatFrequency()
Gets the minimum heartbeat frequency.
|
ReadConcern |
getReadConcern()
The read concern to use.
|
ReadPreference |
getReadPreference()
The read preference to use for queries, map-reduce, aggregation, and count.
|
java.lang.String |
getRequiredReplicaSetName()
Gets the required replica set name.
|
java.util.List<ServerListener> |
getServerListeners()
Gets the list of added
ServerListener . |
java.util.List<ServerMonitorListener> |
getServerMonitorListeners()
Gets the list of added
ServerMonitorListener . |
int |
getServerSelectionTimeout()
Gets the server selection timeout in milliseconds, which defines how long the driver will wait for server selection to
succeed before throwing an exception.
|
(package private) ServerSettings |
getServerSettings() |
javax.net.SocketFactory |
getSocketFactory()
The socket factory for creating sockets to the mongo server.
|
(package private) SocketSettings |
getSocketSettings() |
int |
getSocketTimeout()
The socket timeout in milliseconds.
|
(package private) SslSettings |
getSslSettings() |
int |
getThreadsAllowedToBlockForConnectionMultiplier()
This multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a
connection to become available from the pool.
|
WriteConcern |
getWriteConcern()
The write concern to use.
|
int |
hashCode() |
boolean |
isAlwaysUseMBeans()
Gets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is Java 6 or greater.
|
boolean |
isCursorFinalizerEnabled()
Gets whether there is a a finalize method created that cleans up instances of DBCursor that the client does not close.
|
boolean |
isSocketKeepAlive()
This flag controls the socket keep alive feature that keeps a connection alive through firewalls
Socket.setKeepAlive(boolean) |
boolean |
isSslEnabled()
Whether to use SSL.
|
boolean |
isSslInvalidHostNameAllowed()
Returns whether invalid host names should be allowed if SSL is enabled.
|
java.lang.String |
toString() |
private static final javax.net.SocketFactory DEFAULT_SSL_SOCKET_FACTORY
private static final javax.net.SocketFactory DEFAULT_SOCKET_FACTORY
private final java.lang.String description
private final java.lang.String applicationName
private final ReadPreference readPreference
private final WriteConcern writeConcern
private final ReadConcern readConcern
private final CodecRegistry codecRegistry
private final int minConnectionsPerHost
private final int maxConnectionsPerHost
private final int threadsAllowedToBlockForConnectionMultiplier
private final int serverSelectionTimeout
private final int maxWaitTime
private final int maxConnectionIdleTime
private final int maxConnectionLifeTime
private final int connectTimeout
private final int socketTimeout
private final boolean socketKeepAlive
private final boolean sslEnabled
private final boolean sslInvalidHostNameAllowed
private final boolean alwaysUseMBeans
private final int heartbeatFrequency
private final int minHeartbeatFrequency
private final int heartbeatConnectTimeout
private final int heartbeatSocketTimeout
private final int localThreshold
private final java.lang.String requiredReplicaSetName
private final DBDecoderFactory dbDecoderFactory
private final DBEncoderFactory dbEncoderFactory
private final javax.net.SocketFactory socketFactory
private final boolean cursorFinalizerEnabled
private final ConnectionPoolSettings connectionPoolSettings
private final SocketSettings socketSettings
private final ServerSettings serverSettings
private final SocketSettings heartbeatSocketSettings
private final SslSettings sslSettings
private final java.util.List<CommandListener> commandListeners
private final java.util.List<ClusterListener> clusterListeners
private final java.util.List<ServerListener> serverListeners
private final java.util.List<ServerMonitorListener> serverMonitorListeners
private MongoClientOptions(MongoClientOptions.Builder builder)
public static MongoClientOptions.Builder builder()
public static MongoClientOptions.Builder builder(MongoClientOptions options)
options
- existing MongoClientOptions to default the builder settings on.public java.lang.String getDescription()
Gets the description for this MongoClient, which is used in various places like logging and JMX.
Default is null.
public java.lang.String getApplicationName()
Default is null.
public int getConnectionsPerHost()
The maximum number of connections allowed per host for this MongoClient instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.
Default is 100.
getThreadsAllowedToBlockForConnectionMultiplier()
public int getMinConnectionsPerHost()
The minimum number of connections per host for this MongoClient instance. Those connections will be kept in a pool when idle, and the pool will ensure over time that it contains at least this minimum number.
Default is 0.
public int getThreadsAllowedToBlockForConnectionMultiplier()
This multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool. All further threads will get an exception right away. For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50 threads can wait for a connection.
Default is 5.
public int getServerSelectionTimeout()
Gets the server selection timeout in milliseconds, which defines how long the driver will wait for server selection to succeed before throwing an exception.
Default is 30,000. A value of 0 means that it will timeout immediately if no server is available. A negative value means to wait indefinitely.
public int getMaxWaitTime()
The maximum wait time in milliseconds that a thread may wait for a connection to become available.
Default is 120,000. A value of 0 means that it will not wait. A negative value means to wait indefinitely.
public int getMaxConnectionIdleTime()
public int getMaxConnectionLifeTime()
public int getConnectTimeout()
The connection timeout in milliseconds. A value of 0 means no timeout. It is used solely when establishing a new connection
Socket.connect(java.net.SocketAddress, int)
Default is 10,000.
public int getSocketTimeout()
The socket timeout in milliseconds. It is used for I/O socket read and write operations Socket.setSoTimeout(int)
Default is 0 and means no timeout.
public boolean isSocketKeepAlive()
This flag controls the socket keep alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean)
Default is false.
public int getHeartbeatFrequency()
public int getMinHeartbeatFrequency()
public int getHeartbeatConnectTimeout()
Gets the connect timeout for connections used for the cluster heartbeat.
The default value is 20,000 milliseconds.
public int getHeartbeatSocketTimeout()
public int getLocalThreshold()
Gets the local threshold. When choosing among multiple MongoDB servers to send a request, the MongoClient will only send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the local threshold.
For example, let's say that the client is choosing a server to send a query when the read preference is ReadPreference.secondary()
, and that there are three secondaries, server1, server2, and server3, whose ping times are 10, 15, and 16
milliseconds, respectively. With a local threshold of 5 milliseconds, the client will send the query to either
server1 or server2 (randomly selecting between the two).
The default value is 15 milliseconds.
public java.lang.String getRequiredReplicaSetName()
Gets the required replica set name. With this option set, the MongoClient instance will
public boolean isSslEnabled()
false
.public boolean isSslInvalidHostNameAllowed()
true
.public ReadPreference getReadPreference()
The read preference to use for queries, map-reduce, aggregation, and count.
Default is ReadPreference.primary()
.
ReadPreference.primary()
public WriteConcern getWriteConcern()
The write concern to use.
Default is WriteConcern.ACKNOWLEDGED
.
WriteConcern.ACKNOWLEDGED
public ReadConcern getReadConcern()
The read concern to use.
public CodecRegistry getCodecRegistry()
The codec registry to use. By default, a MongoClient
will be able to encode and decode instances of Document
.
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.
MongoClient.getDatabase(java.lang.String)
public java.util.List<CommandListener> getCommandListeners()
CommandListener
. The default is an empty list.public java.util.List<ClusterListener> getClusterListeners()
ClusterListener
. The default is an empty list.public java.util.List<ServerListener> getServerListeners()
ServerListener
. The default is an empty list.public java.util.List<ServerMonitorListener> getServerMonitorListeners()
ServerMonitorListener
. The default is an empty list.public DBDecoderFactory getDbDecoderFactory()
public DBEncoderFactory getDbEncoderFactory()
public boolean isAlwaysUseMBeans()
Gets 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.
Default is false.
public javax.net.SocketFactory getSocketFactory()
The socket factory for creating sockets to the mongo server.
Default is SocketFactory.getDefault()
public boolean isCursorFinalizerEnabled()
Gets whether there is a a finalize method created that cleans up instances of DBCursor that the client does not close. If you are careful to always call the close method of DBCursor, then this can safely be set to false.
Default is true.
DBCursor
,
DBCursor.close()
ConnectionPoolSettings getConnectionPoolSettings()
SocketSettings getSocketSettings()
ServerSettings getServerSettings()
SocketSettings getHeartbeatSocketSettings()
SslSettings getSslSettings()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object