Skip to content

Commit

Permalink
Added reconnectAttempts, reconnectInterval and idleTimeout props to r…
Browse files Browse the repository at this point in the history
…eactive datasource config
  • Loading branch information
tsegismont authored and gsmet committed Aug 20, 2020
1 parent 0734b4f commit 238e305
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
@@ -1,5 +1,6 @@
package io.quarkus.reactive.datasource.runtime;

import java.time.Duration;
import java.util.Optional;
import java.util.OptionalInt;

Expand Down Expand Up @@ -94,4 +95,22 @@ public class DataSourceReactiveRuntimeConfig {
*/
@ConfigItem
public Optional<Boolean> threadLocal;

/**
* The number of reconnection attempts when a pooled connection cannot be established on first try.
*/
@ConfigItem(defaultValue = "0")
public int reconnectAttempts;

/**
* The interval between reconnection attempts when a pooled connection cannot be established on first try.
*/
@ConfigItem(defaultValue = "PT1S")
public Duration reconnectInterval;

/**
* The maximum time without data written to or read from a connection before it is removed from the pool.
*/
@ConfigItem(defaultValueDocumentation = "no timeout")
public Optional<Duration> idleTimeout;
}
Expand Up @@ -10,6 +10,7 @@
import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePfxTrustOptions;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -132,6 +133,15 @@ private DB2ConnectOptions toConnectOptions(DataSourceRuntimeConfig dataSourceRun
configureJksKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
configurePfxKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);

connectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);

connectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());

if (dataSourceReactiveRuntimeConfig.idleTimeout.isPresent()) {
int idleTimeout = Math.toIntExact(dataSourceReactiveRuntimeConfig.idleTimeout.get().toMillis());
connectOptions.setIdleTimeout(idleTimeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS);
}

return connectOptions;
}
}
Expand Up @@ -10,6 +10,7 @@
import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePfxTrustOptions;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -152,6 +153,15 @@ private MySQLConnectOptions toMySQLConnectOptions(DataSourceRuntimeConfig dataSo
configureJksKeyCertOptions(mysqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
configurePfxKeyCertOptions(mysqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);

mysqlConnectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);

mysqlConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());

if (dataSourceReactiveRuntimeConfig.idleTimeout.isPresent()) {
int idleTimeout = Math.toIntExact(dataSourceReactiveRuntimeConfig.idleTimeout.get().toMillis());
mysqlConnectOptions.setIdleTimeout(idleTimeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS);
}

return mysqlConnectOptions;
}

Expand Down
Expand Up @@ -10,6 +10,7 @@
import static io.quarkus.vertx.core.runtime.SSLConfigHelper.configurePfxTrustOptions;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -150,6 +151,15 @@ private PgConnectOptions toPgConnectOptions(DataSourceRuntimeConfig dataSourceRu
configureJksKeyCertOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
configurePfxKeyCertOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);

pgConnectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);

pgConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());

if (dataSourceReactiveRuntimeConfig.idleTimeout.isPresent()) {
int idleTimeout = Math.toIntExact(dataSourceReactiveRuntimeConfig.idleTimeout.get().toMillis());
pgConnectOptions.setIdleTimeout(idleTimeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS);
}

return pgConnectOptions;
}

Expand Down

0 comments on commit 238e305

Please sign in to comment.