Class ConnectionPoolSettings.Builder

    • Method Detail

      • applySettings

        public ConnectionPoolSettings.Builder applySettings​(ConnectionPoolSettings connectionPoolSettings)
        Applies the connectionPoolSettings to the builder

        Note: Overwrites all existing settings

        Parameters:
        connectionPoolSettings - the connectionPoolSettings
        Returns:
        this
        Since:
        3.7
      • maxSize

        public ConnectionPoolSettings.Builder maxSize​(int maxSize)

        The maximum number of connections allowed. Those connections will be kept in the pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.

        Default is 100.

        Parameters:
        maxSize - the maximum number of connections in the pool.
        Returns:
        this
      • minSize

        public ConnectionPoolSettings.Builder minSize​(int minSize)

        The minimum number of connections. Those connections will be kept in the pool when idle, and the pool will ensure that it contains at least this minimum number.

        Default is 0.

        Parameters:
        minSize - the minimum number of connections to have in the pool at all times.
        Returns:
        this
      • maxWaitQueueSize

        public ConnectionPoolSettings.Builder maxWaitQueueSize​(int maxWaitQueueSize)

        This is the maximum number of waiters for a connection to become available from the pool. 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
      • maxWaitTime

        public ConnectionPoolSettings.Builder maxWaitTime​(long maxWaitTime,
                                                          TimeUnit timeUnit)

        The maximum time that a thread may wait for a connection to become available.

        Default is 2 minutes. A value of 0 means that it will not wait. A negative value means it will wait indefinitely.

        Parameters:
        maxWaitTime - the maximum amount of time to wait
        timeUnit - the TimeUnit for this wait period
        Returns:
        this
      • maxConnectionLifeTime

        public ConnectionPoolSettings.Builder maxConnectionLifeTime​(long maxConnectionLifeTime,
                                                                    TimeUnit timeUnit)
        The maximum time a pooled connection can live for. A zero value indicates no limit to the life time. A pooled connection that has exceeded its life time will be closed and replaced when necessary by a new connection.
        Parameters:
        maxConnectionLifeTime - the maximum length of time a connection can live
        timeUnit - the TimeUnit for this time period
        Returns:
        this
      • maxConnectionIdleTime

        public ConnectionPoolSettings.Builder maxConnectionIdleTime​(long maxConnectionIdleTime,
                                                                    TimeUnit timeUnit)
        The maximum idle time of a pooled connection. A zero value indicates no limit to the idle time. A pooled connection that has exceeded its idle time will be closed and replaced when necessary by a new connection.
        Parameters:
        maxConnectionIdleTime - the maximum time a connection can be unused
        timeUnit - the TimeUnit for this time period
        Returns:
        this
      • maintenanceInitialDelay

        public ConnectionPoolSettings.Builder maintenanceInitialDelay​(long maintenanceInitialDelay,
                                                                      TimeUnit timeUnit)
        The period of time to wait before running the first maintenance job on the connection pool.
        Parameters:
        maintenanceInitialDelay - the time period to wait
        timeUnit - the TimeUnit for this time period
        Returns:
        this
      • maintenanceFrequency

        public ConnectionPoolSettings.Builder maintenanceFrequency​(long maintenanceFrequency,
                                                                   TimeUnit timeUnit)
        The time period between runs of the maintenance job.
        Parameters:
        maintenanceFrequency - the time period between runs of the maintenance job
        timeUnit - the TimeUnit for this time period
        Returns:
        this
      • addConnectionPoolListener

        public ConnectionPoolSettings.Builder addConnectionPoolListener​(ConnectionPoolListener connectionPoolListener)
        Adds the given connection pool listener.
        Parameters:
        connectionPoolListener - the non-null connection pool listener
        Returns:
        this
        Since:
        3.5
      • build

        public ConnectionPoolSettings build()
        Creates a new ConnectionPoolSettings object with the settings initialised on this builder.
        Returns:
        a new ConnectionPoolSettings object
      • applyConnectionString

        public ConnectionPoolSettings.Builder applyConnectionString​(ConnectionString connectionString)
        Takes the settings from the given ConnectionString and applies them to the builder
        Parameters:
        connectionString - the connection string containing details of how to connect to MongoDB
        Returns:
        this