Class ClusterSettings.Builder
- Enclosing class:
- ClusterSettings
-
Method Summary
Modifier and TypeMethodDescriptionaddClusterListener
(ClusterListener clusterListener) Adds a cluster listener.applyConnectionString
(ConnectionString connectionString) Takes the settings from the givenConnectionString
and applies them to the builderapplySettings
(ClusterSettings clusterSettings) Applies the clusterSettings to the builderbuild()
Build the settings from the builder.clusterListenerList
(List<ClusterListener> clusterListeners) Sets the cluster listeners.hosts
(List<ServerAddress> hosts) Sets the hosts for the cluster.localThreshold
(long localThreshold, TimeUnit timeUnit) Sets the local threshold.mode
(ClusterConnectionMode mode) Sets the mode for this cluster.requiredClusterType
(ClusterType requiredClusterType) Sets the required cluster type for the cluster.requiredReplicaSetName
(String requiredReplicaSetName) Sets the required replica set name for the cluster.serverSelectionTimeout
(long serverSelectionTimeout, TimeUnit timeUnit) Sets the timeout to apply when selecting a server.serverSelector
(ServerSelector serverSelector) Adds a server selector for the cluster to apply before selecting a server.Sets the host name to use in order to look up an SRV DNS record to find the MongoDB hosts.srvMaxHosts
(Integer srvMaxHosts) Sets the maximum number of hosts to connect to when using SRV protocol.srvServiceName
(String srvServiceName) Sets the SRV service name.
-
Method Details
-
applySettings
Applies the clusterSettings to the builderNote: Overwrites all existing settings
- Parameters:
clusterSettings
- the clusterSettings- Returns:
- this
- Since:
- 3.7
-
srvHost
Sets the host name to use in order to look up an SRV DNS record to find the MongoDB hosts.Note that when setting srvHost via
ClusterSettings.Builder
, the driver will NOT process any associated TXT records associated with the host. In order to enable the processing of TXT records while still usingMongoClientSettings
, specify the SRV host via connection string and apply the connection string to the settings, e.g.MongoClientSettings.builder().applyConnectionString(new ConnectionString("mongodb+srv://host1.acme.com"))
.- Parameters:
srvHost
- the SRV host name- Returns:
- this
- See Also:
-
srvMaxHosts
Sets the maximum number of hosts to connect to when using SRV protocol.- Parameters:
srvMaxHosts
- the maximum number of hosts to connect to when using SRV protocol- Returns:
- this
- Since:
- 4.4
-
srvServiceName
Sets the SRV service name.The SRV resource record (RFC 2782) service name, which is limited to 15 characters (RFC 6335 section 5.1). If specified, it is combined with the single host name specified by
ClusterSettings.getHosts()
as follows:_srvServiceName._tcp.hostName
. The combined string is an SRV resource record name (RFC 1035 section 2.3.1), which is limited to 255 characters (RFC 1035 section 2.3.4).- Parameters:
srvServiceName
- the SRV service name- Returns:
- this
- Since:
- 4.5
-
hosts
Sets the hosts for the cluster. Any duplicate server addresses are removed from the list.- Parameters:
hosts
- the seed list of hosts- Returns:
- this
-
mode
Sets the mode for this cluster.- Parameters:
mode
- the cluster connection mode- Returns:
- this;
-
requiredReplicaSetName
Sets the required replica set name for the cluster.- Parameters:
requiredReplicaSetName
- the required replica set name.- Returns:
- this
- See Also:
-
requiredClusterType
Sets the required cluster type for the cluster.- Parameters:
requiredClusterType
- the required cluster type- Returns:
- this
-
localThreshold
Sets the local threshold.- Parameters:
localThreshold
- the acceptable latency difference, in milliseconds, which must be >= 0timeUnit
- the time unit- Returns:
- this
- Throws:
IllegalArgumentException
- iflocalThreshold < 0
- Since:
- 3.7
-
serverSelector
Adds a server selector for the cluster to apply before selecting a server.- Parameters:
serverSelector
- the server selector to apply as selector.- Returns:
- this
- See Also:
-
serverSelectionTimeout
public ClusterSettings.Builder serverSelectionTimeout(long serverSelectionTimeout, TimeUnit timeUnit) Sets the timeout to apply when selecting a server. If the timeout expires before a server is found to handle a request, aMongoTimeoutException
will be thrown. The default value is 30 seconds.A value of 0 means that it will timeout immediately if no server is available. A negative value means to wait indefinitely.
- Parameters:
serverSelectionTimeout
- the timeouttimeUnit
- the time unit- Returns:
- this
-
addClusterListener
Adds a cluster listener.- Parameters:
clusterListener
- the non-null cluster listener- Returns:
- this
- Since:
- 3.3
-
clusterListenerList
Sets the cluster listeners.- Parameters:
clusterListeners
- list of cluster listeners- Returns:
- this
- Since:
- 4.5
-
applyConnectionString
Takes the settings from the givenConnectionString
and applies them to the builder- Parameters:
connectionString
- the connection string containing details of how to connect to MongoDB- Returns:
- this
-
build
Build the settings from the builder.- Returns:
- the cluster settings
-