Package com.mongodb.connection
Class ConnectionPoolSettings.Builder
- java.lang.Object
-
- com.mongodb.connection.ConnectionPoolSettings.Builder
-
- Enclosing class:
- ConnectionPoolSettings
@NotThreadSafe public static final class ConnectionPoolSettings.Builder extends Object
A builder for creating ConnectionPoolSettings.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectionPoolSettings.Builder
addConnectionPoolListener(ConnectionPoolListener connectionPoolListener)
Adds the given connection pool listener.ConnectionPoolSettings.Builder
applyConnectionString(ConnectionString connectionString)
Takes the settings from the givenConnectionString
and applies them to the builderConnectionPoolSettings.Builder
applySettings(ConnectionPoolSettings connectionPoolSettings)
Applies the connectionPoolSettings to the builderConnectionPoolSettings
build()
Creates a new ConnectionPoolSettings object with the settings initialised on this builder.ConnectionPoolSettings.Builder
maintenanceFrequency(long maintenanceFrequency, TimeUnit timeUnit)
The time period between runs of the maintenance job.ConnectionPoolSettings.Builder
maintenanceInitialDelay(long maintenanceInitialDelay, TimeUnit timeUnit)
The period of time to wait before running the first maintenance job on the connection pool.ConnectionPoolSettings.Builder
maxConnecting(int maxConnecting)
The maximum number of connections a pool may be establishing concurrently.ConnectionPoolSettings.Builder
maxConnectionIdleTime(long maxConnectionIdleTime, TimeUnit timeUnit)
The maximum idle time of a pooled connection.ConnectionPoolSettings.Builder
maxConnectionLifeTime(long maxConnectionLifeTime, TimeUnit timeUnit)
The maximum time a pooled connection can live for.ConnectionPoolSettings.Builder
maxSize(int maxSize)
The maximum number of connections allowed.ConnectionPoolSettings.Builder
maxWaitTime(long maxWaitTime, TimeUnit timeUnit)
The maximum time that a thread may wait for a connection to become available.ConnectionPoolSettings.Builder
minSize(int minSize)
The minimum number of connections.
-
-
-
Method Detail
-
applySettings
public ConnectionPoolSettings.Builder applySettings(ConnectionPoolSettings connectionPoolSettings)
Applies the connectionPoolSettings to the builderNote: 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; if 0, then there is no limit.- 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
-
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 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
-
maxConnecting
public ConnectionPoolSettings.Builder maxConnecting(int 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:
ConnectionPoolSettings.getMaxConnecting()
-
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 givenConnectionString
and applies them to the builder- Parameters:
connectionString
- the connection string containing details of how to connect to MongoDB- Returns:
- this
-
-