diff --git a/driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java b/driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java index 633abd2651..299b31ed82 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java +++ b/driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java @@ -103,10 +103,10 @@ protected ConnectionPool createConnectionPool( AuthToken authToken, SecurityPlan Clock clock = createClock(); ConnectionSettings settings = new ConnectionSettings( authToken, config.connectionTimeoutMillis() ); ChannelConnector connector = createConnector( settings, securityPlan, config, clock ); - PoolSettings poolSettings = new PoolSettings( config.maxIdleConnectionPoolSize(), - config.idleTimeBeforeConnectionTest(), config.maxConnectionLifetimeMillis(), - config.maxConnectionPoolSize(), - config.connectionAcquisitionTimeoutMillis() ); + PoolSettings poolSettings = new PoolSettings( config.maxConnectionPoolSize(), + config.connectionAcquisitionTimeoutMillis(), config.maxConnectionLifetimeMillis(), + config.idleTimeBeforeConnectionTest() + ); return new ConnectionPoolImpl( connector, bootstrap, poolSettings, config.logging(), clock ); } diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/pool/PoolSettings.java b/driver/src/main/java/org/neo4j/driver/internal/async/pool/PoolSettings.java index e551047ceb..a424aae8db 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/async/pool/PoolSettings.java +++ b/driver/src/main/java/org/neo4j/driver/internal/async/pool/PoolSettings.java @@ -25,30 +25,22 @@ public class PoolSettings public static final int NOT_CONFIGURED = -1; public static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 100; - public static final int DEFAULT_MAX_IDLE_CONNECTION_POOL_SIZE = DEFAULT_MAX_CONNECTION_POOL_SIZE; public static final long DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST = NOT_CONFIGURED; public static final long DEFAULT_MAX_CONNECTION_LIFETIME = TimeUnit.HOURS.toMillis( 1 ); public static final long DEFAULT_CONNECTION_ACQUISITION_TIMEOUT = TimeUnit.SECONDS.toMillis( 60 ); - private final int maxIdleConnectionPoolSize; - private final long idleTimeBeforeConnectionTest; - private final long maxConnectionLifetime; private final int maxConnectionPoolSize; private final long connectionAcquisitionTimeout; + private final long maxConnectionLifetime; + private final long idleTimeBeforeConnectionTest; - public PoolSettings( int maxIdleConnectionPoolSize, long idleTimeBeforeConnectionTest, long maxConnectionLifetime, - int maxConnectionPoolSize, long connectionAcquisitionTimeout ) + public PoolSettings( int maxConnectionPoolSize, long connectionAcquisitionTimeout, + long maxConnectionLifetime, long idleTimeBeforeConnectionTest ) { - this.maxIdleConnectionPoolSize = maxIdleConnectionPoolSize; - this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest; - this.maxConnectionLifetime = maxConnectionLifetime; this.maxConnectionPoolSize = maxConnectionPoolSize; this.connectionAcquisitionTimeout = connectionAcquisitionTimeout; - } - - public int maxIdleConnectionPoolSize() - { - return maxIdleConnectionPoolSize; + this.maxConnectionLifetime = maxConnectionLifetime; + this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest; } public long idleTimeBeforeConnectionTest() diff --git a/driver/src/main/java/org/neo4j/driver/v1/Config.java b/driver/src/main/java/org/neo4j/driver/v1/Config.java index 1d14d498b6..835a777bba 100644 --- a/driver/src/main/java/org/neo4j/driver/v1/Config.java +++ b/driver/src/main/java/org/neo4j/driver/v1/Config.java @@ -38,7 +38,7 @@ /** * A configuration class to config driver properties. *
- * To create a config: + * To build a simple config with custom logging implementation: *
* {@code * Config config = Config @@ -47,6 +47,20 @@ * .toConfig(); * } *+ *
+ * To build a more complicated config with tuned connection pool options: + *
+ * {@code + * Config config = Config.build() + * .withEncryption() + * .withConnectionTimeout(10, TimeUnit.SECONDS) + * .withMaxConnectionLifetime(30, TimeUnit.MINUTES) + * .withMaxConnectionPoolSize(10) + * .withConnectionAcquisitionTimeout(20, TimeUnit.SECONDS) + * .toConfig(); + * } + *+ * * @since 1.0 */ @Immutable @@ -56,7 +70,6 @@ public class Config private final Logging logging; private final boolean logLeakedSessions; - private final int maxIdleConnectionPoolSize; private final int maxConnectionPoolSize; private final long idleTimeBeforeConnectionTest; @@ -83,7 +96,6 @@ private Config( ConfigBuilder builder) this.idleTimeBeforeConnectionTest = builder.idleTimeBeforeConnectionTest; this.maxConnectionLifetimeMillis = builder.maxConnectionLifetimeMillis; - this.maxIdleConnectionPoolSize = builder.maxIdleConnectionPoolSize; this.maxConnectionPoolSize = builder.maxConnectionPoolSize; this.connectionAcquisitionTimeoutMillis = builder.connectionAcquisitionTimeoutMillis; @@ -117,21 +129,26 @@ public boolean logLeakedSessions() /** * Max number of connections per URL for this driver. + * * @return the max number of connections + * @deprecated please use {@link #maxConnectionPoolSize()} instead. */ @Deprecated public int connectionPoolSize() { - return maxIdleConnectionPoolSize; + return maxConnectionPoolSize; } /** * Max number of idle connections per URL for this driver. + * * @return the max number of connections + * @deprecated please use {@link #maxConnectionPoolSize()} instead. */ + @Deprecated public int maxIdleConnectionPoolSize() { - return maxIdleConnectionPoolSize; + return maxConnectionPoolSize; } /** @@ -243,7 +260,6 @@ public static class ConfigBuilder { private Logging logging = new JULogging( Level.INFO ); private boolean logLeakedSessions; - private int maxIdleConnectionPoolSize = PoolSettings.DEFAULT_MAX_IDLE_CONNECTION_POOL_SIZE; private int maxConnectionPoolSize = PoolSettings.DEFAULT_MAX_CONNECTION_POOL_SIZE; private long idleTimeBeforeConnectionTest = PoolSettings.DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST; private long maxConnectionLifetimeMillis = PoolSettings.DEFAULT_MAX_CONNECTION_LIFETIME; @@ -311,32 +327,38 @@ public ConfigBuilder withLeakedSessionsLogging() * The max number of sessions to keep open at once. Configure this * higher if you want more concurrent sessions, or lower if you want * to lower the pressure on the database instance. - * + *
* If the driver is asked to provide more sessions than this, it will * block waiting for another session to be closed, with a timeout. + *
+ * Method is deprecated and will forward the given argument to {@link #withMaxConnectionPoolSize(int)}. * * @param size the max number of sessions to keep open * @return this builder + * @deprecated please use a combination of {@link #withMaxConnectionPoolSize(int)} and + * {@link #withConnectionAcquisitionTimeout(long, TimeUnit)} instead. */ @Deprecated public ConfigBuilder withMaxSessions( int size ) { - return this; + return withMaxConnectionPoolSize( size ); } /** * The max number of idle sessions to keep open at once. Configure this * higher if you want more concurrent sessions, or lower if you want * to lower the pressure on the database instance. + *
+ * Method is deprecated and will not change the driver configuration. * * @param size the max number of idle sessions to keep open * @return this builder - * @deprecated please use {@link #withMaxIdleConnections(int)} instead. + * @deprecated please use a combination of {@link #withMaxConnectionPoolSize(int)} and + * {@link #withConnectionAcquisitionTimeout(long, TimeUnit)} instead. */ @Deprecated public ConfigBuilder withMaxIdleSessions( int size ) { - this.maxIdleConnectionPoolSize = size; return this; } @@ -344,13 +366,17 @@ public ConfigBuilder withMaxIdleSessions( int size ) * The max number of idle connections to keep open at once. Configure this * higher for greater concurrency, or lower to reduce the pressure on the * database instance. + *
+ * Method is deprecated and will not change the driver configuration.
*
* @param size the max number of idle connections to keep open
* @return this builder
+ * @deprecated please use a combination of {@link #withMaxConnectionPoolSize(int)} and
+ * {@link #withConnectionAcquisitionTimeout(long, TimeUnit)} instead.
*/
+ @Deprecated
public ConfigBuilder withMaxIdleConnections( int size )
{
- this.maxIdleConnectionPoolSize = size;
return this;
}
@@ -366,8 +392,7 @@ public ConfigBuilder withMaxIdleConnections( int size )
@Deprecated
public ConfigBuilder withSessionLivenessCheckTimeout( long timeout )
{
- withConnectionLivenessCheckTimeout( timeout, TimeUnit.MILLISECONDS );
- return this;
+ return withConnectionLivenessCheckTimeout( timeout, TimeUnit.MILLISECONDS );
}
/**
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java
index b58033c90b..ef74dc18dd 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImplTest.java
@@ -169,7 +169,7 @@ private ConnectionPoolImpl newPool() throws Exception
ChannelConnectorImpl connector =
new ChannelConnectorImpl( connectionSettings, SecurityPlan.forAllCertificates(),
DEV_NULL_LOGGING, clock );
- PoolSettings poolSettings = new PoolSettings( 5, -1, -1, 10, 5000 );
+ PoolSettings poolSettings = new PoolSettings( 10, 5000, -1, -1 );
Bootstrap bootstrap = BootstrapFactory.newBootstrap( 1 );
return new ConnectionPoolImpl( connector, bootstrap, poolSettings, DEV_NULL_LOGGING, clock );
}
diff --git a/driver/src/test/java/org/neo4j/driver/internal/async/pool/NettyChannelHealthCheckerTest.java b/driver/src/test/java/org/neo4j/driver/internal/async/pool/NettyChannelHealthCheckerTest.java
index c787c550cf..5d0c383eae 100644
--- a/driver/src/test/java/org/neo4j/driver/internal/async/pool/NettyChannelHealthCheckerTest.java
+++ b/driver/src/test/java/org/neo4j/driver/internal/async/pool/NettyChannelHealthCheckerTest.java
@@ -41,7 +41,6 @@
import static org.neo4j.driver.internal.async.pool.PoolSettings.DEFAULT_CONNECTION_ACQUISITION_TIMEOUT;
import static org.neo4j.driver.internal.async.pool.PoolSettings.DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST;
import static org.neo4j.driver.internal.async.pool.PoolSettings.DEFAULT_MAX_CONNECTION_POOL_SIZE;
-import static org.neo4j.driver.internal.async.pool.PoolSettings.DEFAULT_MAX_IDLE_CONNECTION_POOL_SIZE;
import static org.neo4j.driver.internal.async.pool.PoolSettings.NOT_CONFIGURED;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
import static org.neo4j.driver.internal.util.Iterables.single;
@@ -67,14 +66,13 @@ public void tearDown()
@Test
public void shouldDropTooOldChannelsWhenMaxLifetimeEnabled()
{
- int maxConnectionLifetime = 1000;
- PoolSettings settings = new PoolSettings( DEFAULT_MAX_IDLE_CONNECTION_POOL_SIZE,
- DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST, maxConnectionLifetime, DEFAULT_MAX_CONNECTION_POOL_SIZE,
- DEFAULT_CONNECTION_ACQUISITION_TIMEOUT );
+ int maxLifetime = 1000;
+ PoolSettings settings = new PoolSettings( DEFAULT_MAX_CONNECTION_POOL_SIZE,
+ DEFAULT_CONNECTION_ACQUISITION_TIMEOUT, maxLifetime, DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST );
Clock clock = Clock.SYSTEM;
NettyChannelHealthChecker healthChecker = newHealthChecker( settings, clock );
- setCreationTimestamp( channel, clock.millis() - maxConnectionLifetime * 2 );
+ setCreationTimestamp( channel, clock.millis() - maxLifetime * 2 );
Future