Package com.mongodb.connection
Class ClusterSettings.Builder
- java.lang.Object
-
- com.mongodb.connection.ClusterSettings.Builder
-
- Enclosing class:
- ClusterSettings
@NotThreadSafe public static final class ClusterSettings.Builder extends Object
A builder for the cluster settings.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClusterSettings.BuilderaddClusterListener(ClusterListener clusterListener)Adds a cluster listener.ClusterSettings.BuilderapplyConnectionString(ConnectionString connectionString)Takes the settings from the givenConnectionStringand applies them to the builderClusterSettings.BuilderapplySettings(ClusterSettings clusterSettings)Applies the clusterSettings to the builderClusterSettingsbuild()Build the settings from the builder.ClusterSettings.Builderdescription(String description)Deprecated.ClusterSettings.Builderhosts(List<ServerAddress> hosts)Sets the hosts for the cluster.ClusterSettings.BuilderlocalThreshold(long localThreshold, TimeUnit timeUnit)Sets the local threshold.ClusterSettings.BuildermaxWaitQueueSize(int maxWaitQueueSize)This is the maximum number of concurrent operations allowed to wait for a server to become available.ClusterSettings.Buildermode(ClusterConnectionMode mode)Sets the mode for this cluster.ClusterSettings.BuilderrequiredClusterType(ClusterType requiredClusterType)Sets the required cluster type for the cluster.ClusterSettings.BuilderrequiredReplicaSetName(String requiredReplicaSetName)Sets the required replica set name for the cluster.ClusterSettings.BuilderserverSelectionTimeout(long serverSelectionTimeout, TimeUnit timeUnit)Sets the timeout to apply when selecting a server.ClusterSettings.BuilderserverSelector(ServerSelector serverSelector)Adds a server selector for the cluster to apply before selecting a server.ClusterSettings.BuildersrvHost(String srvHost)Sets the host name to use in order to look up an SRV DNS record to find the MongoDB hosts.
-
-
-
Method Detail
-
applySettings
public ClusterSettings.Builder applySettings(ClusterSettings clusterSettings)
Applies the clusterSettings to the builderNote: Overwrites all existing settings
- Parameters:
clusterSettings- the clusterSettings- Returns:
- this
- Since:
- 3.7
-
description
@Deprecated public ClusterSettings.Builder description(String description)
Deprecated. PreferMongoClientSettings.Builder.applicationName(String)Sets the user defined description of the MongoClient.- Parameters:
description- the user defined description of the MongoClient- Returns:
- this
-
srvHost
public ClusterSettings.Builder srvHost(String srvHost)
Sets the host name to use in order to look up an SRV DNS record to find the MongoDB hosts.- Parameters:
srvHost- the SRV host name- Returns:
- this
-
hosts
public ClusterSettings.Builder hosts(List<ServerAddress> 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
public ClusterSettings.Builder mode(ClusterConnectionMode mode)
Sets the mode for this cluster.- Parameters:
mode- the cluster connection mode- Returns:
- this;
-
requiredReplicaSetName
public ClusterSettings.Builder requiredReplicaSetName(String requiredReplicaSetName)
Sets the required replica set name for the cluster.- Parameters:
requiredReplicaSetName- the required replica set name.- Returns:
- this
-
requiredClusterType
public ClusterSettings.Builder requiredClusterType(ClusterType requiredClusterType)
Sets the required cluster type for the cluster.- Parameters:
requiredClusterType- the required cluster type- Returns:
- this
-
localThreshold
public ClusterSettings.Builder localThreshold(long localThreshold, TimeUnit timeUnit)
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
public ClusterSettings.Builder serverSelector(ServerSelector 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:
ClusterSettings.getServerSelector()
-
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, aMongoTimeoutExceptionwill 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
-
maxWaitQueueSize
public ClusterSettings.Builder maxWaitQueueSize(int maxWaitQueueSize)
This is the maximum number of concurrent operations allowed to wait for a server to become available. All further operations will get an exception immediately.
Default is 500.
- Parameters:
maxWaitQueueSize- the number of threads that are allowed to be waiting for a connection.- Returns:
- this
-
addClusterListener
public ClusterSettings.Builder addClusterListener(ClusterListener clusterListener)
Adds a cluster listener.- Parameters:
clusterListener- the non-null cluster listener- Returns:
- this
- Since:
- 3.3
-
applyConnectionString
public ClusterSettings.Builder applyConnectionString(ConnectionString connectionString)
Takes the settings from the givenConnectionStringand applies them to the builder- Parameters:
connectionString- the connection string containing details of how to connect to MongoDB- Returns:
- this
-
build
public ClusterSettings build()
Build the settings from the builder.- Returns:
- the cluster settings
-
-