Class ClusterSettings

  • @Immutable
    public final class ClusterSettings
    extends Object
    Settings for the cluster.
    • Method Detail

      • builder

        public static ClusterSettings.Builder builder()
        Get a builder for this class.
        a new Builder for creating ClusterSettings.
      • builder

        public static ClusterSettings.Builder builder​(ClusterSettings clusterSettings)
        Creates a builder instance.
        clusterSettings - existing ClusterSettings to default the builder settings on.
        a builder
      • getSrvHost

        public String getSrvHost()
        Gets the host name from which to lookup SRV record for the seed list
        the SRV host, or null if none specified
      • getHosts

        public List<ServerAddress> getHosts()
        Gets the seed list of hosts for the cluster.
        the seed list of hosts
      • getRequiredClusterType

        public ClusterType getRequiredClusterType()
        Gets the required cluster type
        the required cluster type
      • getRequiredReplicaSetName

        public String getRequiredReplicaSetName()
        Gets the required replica set name.
        the required replica set name
      • getServerSelector

        public ServerSelector getServerSelector()
        Gets the server selector.

        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:

        • select from within the latency window
        • select a random server from those remaining

        To skip the latency window selector, an application can:

        • configure the local threshold to a sufficiently high value so that it doesn't exclude any servers
        • return a list containing a single server from this selector (which will also make the random member selector a no-op)
        the server selector, which may be null
        See Also:
      • getServerSelectionTimeout

        public long getServerSelectionTimeout​(TimeUnit timeUnit)
        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.

        timeUnit - the time unit
        the timeout in the given time unit
      • getLocalThreshold

        public long getLocalThreshold​(TimeUnit timeUnit)
        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.

        timeUnit - the time unit
        the local threshold in the given timeunit.
        MongoDB documentation
        Local Threshold
      • getMaxWaitQueueSize

        public int getMaxWaitQueueSize()

        This is 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 immediately.

        Default is 500.

        the number of threads that are allowed to be waiting for a connection.
      • getClusterListeners

        public List<ClusterListener> getClusterListeners()
        Gets the cluster listeners. The default value is an empty list.
        the cluster listeners
      • hashCode

        public int hashCode()
        hashCode in class Object
      • getShortDescription

        public String getShortDescription()
        Returns a short, pretty description for these ClusterSettings.
        a String description of the relevant settings.