Class ClusterSettings


  • public class ClusterSettings
    extends java.lang.Object
    • Constructor Detail

      • ClusterSettings

        public ClusterSettings()
      • ClusterSettings

        public ClusterSettings​(JsonObject json)
    • Method Detail

      • setSrvHost

        public ClusterSettings setSrvHost​(java.lang.String 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 using MongoClientSettings, 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:
        MongoClientSettings.Builder.applyConnectionString(ConnectionString), ClusterSettings.Builder.applyConnectionString(ConnectionString)
      • getSrvHost

        public java.lang.String getSrvHost()
        Gets the host name from which to lookup SRV record for the seed list
        Returns:
        the SRV host, or null if none specified
        Since:
        3.10
      • setHosts

        public ClusterSettings setHosts​(java.util.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
      • setRequiredReplicaSetName

        public ClusterSettings setRequiredReplicaSetName​(java.lang.String requiredReplicaSetName)
        Sets the required replica set name for the cluster.
        Parameters:
        requiredReplicaSetName - the required replica set name.
        Returns:
        this
      • getRequiredReplicaSetName

        public java.lang.String getRequiredReplicaSetName()
        Gets the required replica set name.
        Returns:
        the required replica set name
      • setRequiredClusterType

        public ClusterSettings setRequiredClusterType​(ClusterType requiredClusterType)
        Sets the required cluster type for the cluster.
        Parameters:
        requiredClusterType - the required cluster type
        Returns:
        this
      • getRequiredClusterType

        public ClusterType getRequiredClusterType()
        Gets the required cluster type
        Returns:
        the required cluster type
      • setLocalThreshold

        public ClusterSettings setLocalThreshold​(java.lang.Long localThreshold)
        Sets the local threshold.
        Parameters:
        localThreshold - the acceptable latency difference, in milliseconds, which must be >= 0 (in milliseconds)
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if localThreshold < 0
        Since:
        3.7
      • getLocalThreshold

        public java.lang.Long 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.

        Returns:
        the local threshold in the given timeunit.
        Since:
        3.7
        MongoDB documentation
        Local Threshold
      • setServerSelectionTimeout

        public ClusterSettings setServerSelectionTimeout​(java.lang.Long serverSelectionTimeout)
        Sets the timeout to apply when selecting a server. If the timeout expires before a server is found to handle a request, a MongoTimeoutException 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 timeout (in milliseconds)
        Returns:
        this
      • getServerSelectionTimeout

        public java.lang.Long getServerSelectionTimeout()
        Gets the timeout to apply when selecting a server. If the timeout expires before a server is found to handle a request, a MongoTimeoutException 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.

        Returns:
        the timeout (in milliseconds)