Skip to content

Commit

Permalink
Allow to prepare the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Dec 12, 2024
1 parent c83f5ac commit adb2b0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,26 @@ class DefaultLettucePoolingClientConfiguration implements LettucePoolingClientCo

private final LettuceClientConfiguration clientConfiguration;
private final GenericObjectPoolConfig poolConfig;
private final boolean preparePool;

DefaultLettucePoolingClientConfiguration(LettuceClientConfiguration clientConfiguration,
GenericObjectPoolConfig poolConfig) {

this.clientConfiguration = clientConfiguration;
this.poolConfig = poolConfig;
this.preparePool = false;
}

DefaultLettucePoolingClientConfiguration(LettuceClientConfiguration clientConfiguration,
GenericObjectPoolConfig poolConfig, boolean preparePool) {
this.clientConfiguration = clientConfiguration;
this.poolConfig = poolConfig;
this.preparePool = preparePool;
}

@Override
public boolean preparePool() {
return preparePool;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
public interface LettucePoolingClientConfiguration extends LettuceClientConfiguration {

boolean preparePool();
/**
* @return the {@link GenericObjectPoolConfig}. Never {@literal null}.
*/
Expand Down Expand Up @@ -92,6 +93,7 @@ static LettucePoolingClientConfiguration defaultConfiguration() {
class LettucePoolingClientConfigurationBuilder extends LettuceClientConfigurationBuilder {

GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
boolean preparePool = false;

LettucePoolingClientConfigurationBuilder() {
super();
Expand Down Expand Up @@ -125,6 +127,12 @@ public LettucePoolingClientConfigurationBuilder commandTimeout(Duration timeout)
return this;
}

public LettucePoolingClientConfigurationBuilder preparePool(boolean preparePool) {

this.preparePool = preparePool;
return this;
}

@Override
public LettucePoolingClientConfigurationBuilder shutdownTimeout(Duration shutdownTimeout) {

Expand Down Expand Up @@ -173,7 +181,7 @@ public LettucePoolingClientConfigurationBuilder poolConfig(GenericObjectPoolConf

@Override
public LettucePoolingClientConfiguration build() {
return new DefaultLettucePoolingClientConfiguration(super.build(), poolConfig);
return new DefaultLettucePoolingClientConfiguration(super.build(), poolConfig, preparePool);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red
private static final Log log = LogFactory.getLog(LettucePoolingConnectionProvider.class);

private final LettuceConnectionProvider connectionProvider;
private final LettucePoolingClientConfiguration clientConfiguration;
private final GenericObjectPoolConfig poolConfig;
private final Map<StatefulConnection<?, ?>, GenericObjectPool<StatefulConnection<?, ?>>> poolRef = new ConcurrentHashMap<>(
32);
Expand All @@ -81,6 +82,7 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red
Assert.notNull(connectionProvider, "ConnectionProvider must not be null");
Assert.notNull(clientConfiguration, "ClientConfiguration must not be null");

this.clientConfiguration = clientConfiguration;
this.connectionProvider = connectionProvider;
this.poolConfig = clientConfiguration.getPoolConfig();
this.asyncPoolConfig = CommonsPool2ConfigConverter.bounded(this.poolConfig);
Expand All @@ -93,6 +95,14 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red
return ConnectionPoolSupport.createGenericObjectPool(() -> connectionProvider.getConnection(connectionType),
poolConfig, false);
});
if (clientConfiguration.preparePool()) {
try {
pool.preparePool();

} catch (Exception ex) {
throw new PoolException("Could not prepare the pool", ex);
}
}

try {

Expand Down

0 comments on commit adb2b0a

Please sign in to comment.