Package com.mongodb.connection
Class ConnectionPoolSettings.Builder
java.lang.Object
com.mongodb.connection.ConnectionPoolSettings.Builder
- Enclosing class:
- ConnectionPoolSettings
A builder for creating ConnectionPoolSettings.
-
Method Summary
Modifier and TypeMethodDescriptionaddConnectionPoolListener
(ConnectionPoolListener connectionPoolListener) Adds the given connection pool listener.applyConnectionString
(ConnectionString connectionString) Takes the settings from the givenConnectionString
and applies them to the builderapplySettings
(ConnectionPoolSettings connectionPoolSettings) Applies the connectionPoolSettings to the builderbuild()
Creates a new ConnectionPoolSettings object with the settings initialised on this builder.connectionPoolListenerList
(List<ConnectionPoolListener> connectionPoolListeners) Sets the connection pool listeners.maintenanceFrequency
(long maintenanceFrequency, TimeUnit timeUnit) The time period between runs of the maintenance job.maintenanceInitialDelay
(long maintenanceInitialDelay, TimeUnit timeUnit) The period of time to wait before running the first maintenance job on the connection pool.maxConnecting
(int maxConnecting) The maximum number of connections a pool may be establishing concurrently.maxConnectionIdleTime
(long maxConnectionIdleTime, TimeUnit timeUnit) The maximum idle time of a pooled connection.maxConnectionLifeTime
(long maxConnectionLifeTime, TimeUnit timeUnit) The maximum time a pooled connection can live for.maxSize
(int maxSize) The maximum number of connections allowed.maxWaitTime
(long maxWaitTime, TimeUnit timeUnit) The maximum time that a thread may wait for a connection to become available.minSize
(int minSize) The minimum number of connections.
-
Method Details
-
applySettings
Applies the connectionPoolSettings to the builderNote: Overwrites all existing settings
- Parameters:
connectionPoolSettings
- the connectionPoolSettings- Returns:
- this
- Since:
- 3.7
-
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; if 0, then there is no limit.- Returns:
- this
-
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
-
maxWaitTime
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 waittimeUnit
- 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 livetimeUnit
- 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 unusedtimeUnit
- 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 waittimeUnit
- 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 jobtimeUnit
- 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
-
connectionPoolListenerList
public ConnectionPoolSettings.Builder connectionPoolListenerList(List<ConnectionPoolListener> connectionPoolListeners) Sets the connection pool listeners.- Parameters:
connectionPoolListeners
- list of connection pool listeners- Returns:
- this
- Since:
- 4.5
-
maxConnecting
The maximum number of connections a pool may be establishing concurrently.- Parameters:
maxConnecting
- The maximum number of connections a pool may be establishing concurrently. Must be positive.- Returns:
this
.- Since:
- 4.4
- See Also:
-
build
Creates a new ConnectionPoolSettings object with the settings initialised on this builder.- Returns:
- a new ConnectionPoolSettings object
-
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
-