@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 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 . |
java.util.List<MongoCompressor> |
getCompressorList()
Gets the compressors to use for compressing messages to the server.
|
java.util.List<ConnectionPoolListener> |
getConnectionPoolListeners()
Gets the list of added
ConnectionPoolListener . |
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.
|
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.
|
boolean |
getRetryWrites()
Returns true if writes should be retried if they fail due to a network error.
|
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.
|
ServerSelector |
getServerSelector()
Gets the server selector.
|
javax.net.SocketFactory |
getSocketFactory()
The socket factory for creating sockets to the mongo server.
|
int |
getSocketTimeout()
The socket timeout in milliseconds.
|
javax.net.ssl.SSLContext |
getSslContext()
Returns the SSLContext.
|
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()
Deprecated.
configuring keep-alive has been deprecated. It now defaults to true and disabling it is not recommended.
|
boolean |
isSslEnabled()
Whether to use SSL.
|
boolean |
isSslInvalidHostNameAllowed()
Returns whether invalid host names should be allowed if SSL is enabled.
|
java.lang.String |
toString() |
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 java.util.List<MongoCompressor> getCompressorList()
Default is the empty list.
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 milliseconds. 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 milliseconds. A value of 0 means that it will not wait. A negative value means to wait indefinitely.
public int getMaxConnectionIdleTime()
Default is 0, indicating no limit to the idle time.
public int getMaxConnectionLifeTime()
Default is 0, indicating no limit to the life time.
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 milliseconds.
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.
@Deprecated public boolean isSocketKeepAlive()
This flag controls the socket keep-alive feature that keeps a connection alive through firewalls Socket.setKeepAlive(boolean)
Default is true
.
public int getHeartbeatFrequency()
Default is 10,000 milliseconds.
public int getMinHeartbeatFrequency()
Default is 500 milliseconds.
public int getHeartbeatConnectTimeout()
Gets the connect timeout for connections used for the cluster heartbeat.
Default is 20,000 milliseconds.
public int getHeartbeatSocketTimeout()
Default is 20,000 milliseconds.
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).
Default is 15 milliseconds.
@Nullable public java.lang.String getRequiredReplicaSetName()
Gets the required replica set name. With this option set, the MongoClient instance will
public boolean isSslEnabled()
Default is false
.
public boolean isSslInvalidHostNameAllowed()
true
.
Default is false
.
public javax.net.ssl.SSLContext getSslContext()
SSLContext.getDefault()
will be used when SSL is enabled.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 boolean getRetryWrites()
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 ServerSelector getServerSelector()
The server selector augments the normal server selection rules applied by the driver when determining
which server to send an operation to. At the point that it's called by the driver, the
ClusterDescription
which is passed to it contains a list of
ServerDescription
instances which satisfy either the configured ReadPreference
for any
read operation or ones that can take writes (e.g. a standalone, mongos, or replica set primary).
The server selector can then filter the ServerDescription
list using whatever criteria that is required by the
application.
After this selector executes, two additional selectors are applied by the driver:
To skip the latency window selector, an application can:
public java.util.List<ClusterListener> getClusterListeners()
ClusterListener
. The default is an empty list.public java.util.List<CommandListener> getCommandListeners()
CommandListener
.
Default is an empty list.
public java.util.List<ConnectionPoolListener> getConnectionPoolListeners()
ConnectionPoolListener
. 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()
Default is for the standard Mongo Java driver configuration.
public DBEncoderFactory getDbEncoderFactory()
Default is for the standard Mongo Java driver configuration.
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()
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
Copyright © 2010 - 2020 Adobe. All Rights Reserved