public static class MultiDbConfig.DatabaseConfig.Builder
extends java.lang.Object
The Builder provides a convenient way to configure database settings including connection pooling, weight-based priority, and health check strategies. All configuration methods return the builder instance for method chaining.
Default Values:
PingStrategy.DEFAULT| Constructor and Description |
|---|
Builder(Endpoint endpoint,
JedisClientConfig clientConfig)
Constructs a new Builder with required endpoint and client configuration.
|
| Modifier and Type | Method and Description |
|---|---|
MultiDbConfig.DatabaseConfig |
build()
Builds and returns a new DatabaseConfig instance with the configured settings.
|
MultiDbConfig.DatabaseConfig.Builder |
connectionPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> connectionPoolConfig)
Sets the connection pool configuration for this database.
|
MultiDbConfig.DatabaseConfig.Builder |
healthCheckEnabled(boolean healthCheckEnabled)
Enables or disables health checks for this database.
|
MultiDbConfig.DatabaseConfig.Builder |
healthCheckStrategy(HealthCheckStrategy healthCheckStrategy)
Sets a specific health check strategy instance for this database.
|
MultiDbConfig.DatabaseConfig.Builder |
healthCheckStrategySupplier(MultiDbConfig.StrategySupplier healthCheckStrategySupplier)
Sets a custom health check strategy supplier for this database.
|
MultiDbConfig.DatabaseConfig.Builder |
weight(float weight)
Sets the weight value for database selection priority.
|
public Builder(Endpoint endpoint, JedisClientConfig clientConfig)
endpoint - the Redis endpoint (host and port)clientConfig - the Jedis client configurationjava.lang.IllegalArgumentException - if endpoint or clientConfig is nullpublic MultiDbConfig.DatabaseConfig.Builder connectionPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig<Connection> connectionPoolConfig)
Connection pooling helps manage connections efficiently and provides better performance under load. If not specified, default pooling behavior will be used.
connectionPoolConfig - the connection pool configurationpublic MultiDbConfig.DatabaseConfig.Builder weight(float weight)
Weight determines the priority order for database selection during failover. Databases with higher weights are preferred over those with lower weights. The system will attempt to use the highest-weight healthy database available.
Examples:
weight - the weight value for priority-based selectionpublic MultiDbConfig.DatabaseConfig.Builder healthCheckStrategySupplier(MultiDbConfig.StrategySupplier healthCheckStrategySupplier)
The strategy supplier creates health check instances that monitor this database's availability. Different databases can use different health check strategies based on their specific requirements.
healthCheckStrategySupplier - the health check strategy supplierjava.lang.IllegalArgumentException - if healthCheckStrategySupplier is nullMultiDbConfig.StrategySupplier,
HealthCheckStrategypublic MultiDbConfig.DatabaseConfig.Builder healthCheckStrategy(HealthCheckStrategy healthCheckStrategy)
This is a convenience method that wraps the provided strategy in a supplier that always returns the same instance. Use this when you have a pre-configured strategy instance.
Note: The same strategy instance will be reused, so ensure it's thread-safe if multiple databases might use it.
healthCheckStrategy - the health check strategy instancejava.lang.IllegalArgumentException - if healthCheckStrategy is null#healthCheckStrategySupplier(StrategySupplier)public MultiDbConfig.DatabaseConfig.Builder healthCheckEnabled(boolean healthCheckEnabled)
When health checks are disabled (false), the database will not be proactively monitored for availability. This means:
When health checks are enabled (true) and no strategy supplier was previously set, the
default PingStrategy.DEFAULT will be used.
healthCheckEnabled - true to enable health checks, false to disablepublic MultiDbConfig.DatabaseConfig build()
Copyright © 2025. All rights reserved.