1919package org .neo4j .driver .internal ;
2020
2121import io .netty .bootstrap .Bootstrap ;
22- import io .netty .channel .EventLoopGroup ;
2322import io .netty .util .concurrent .EventExecutorGroup ;
2423
2524import java .io .IOException ;
@@ -76,17 +75,17 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
7675 SecurityPlan securityPlan = createSecurityPlan ( address , config );
7776 ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , config );
7877
79- Bootstrap bootstrap = BootstrapFactory . newBootstrap ();
80- EventLoopGroup eventLoopGroup = bootstrap .config ().group ();
81- RetryLogic retryLogic = createRetryLogic ( retrySettings , eventLoopGroup , config .logging () );
78+ Bootstrap bootstrap = createBootstrap ();
79+ EventExecutorGroup eventExecutorGroup = bootstrap .config ().group ();
80+ RetryLogic retryLogic = createRetryLogic ( retrySettings , eventExecutorGroup , config .logging () );
8281
8382 AsyncConnectionPool asyncConnectionPool = createAsyncConnectionPool ( authToken , securityPlan , bootstrap ,
8483 config );
8584
8685 try
8786 {
88- return createDriver ( uri , address , connectionPool , config , newRoutingSettings , securityPlan , retryLogic ,
89- asyncConnectionPool );
87+ return createDriver ( uri , address , connectionPool , asyncConnectionPool , config , newRoutingSettings ,
88+ eventExecutorGroup , securityPlan , retryLogic );
9089 }
9190 catch ( Throwable driverError )
9291 {
@@ -121,8 +120,8 @@ private AsyncConnectionPool createAsyncConnectionPool( AuthToken authToken, Secu
121120 }
122121
123122 private Driver createDriver ( URI uri , BoltServerAddress address , ConnectionPool connectionPool ,
124- Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic ,
125- AsyncConnectionPool asyncConnectionPool )
123+ AsyncConnectionPool asyncConnectionPool , Config config , RoutingSettings routingSettings ,
124+ EventExecutorGroup eventExecutorGroup , SecurityPlan securityPlan , RetryLogic retryLogic )
126125 {
127126 String scheme = uri .getScheme ().toLowerCase ();
128127 switch ( scheme )
@@ -131,7 +130,8 @@ private Driver createDriver( URI uri, BoltServerAddress address, ConnectionPool
131130 assertNoRoutingContext ( uri , routingSettings );
132131 return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool );
133132 case BOLT_ROUTING_URI_SCHEME :
134- return createRoutingDriver ( address , connectionPool , config , routingSettings , securityPlan , retryLogic );
133+ return createRoutingDriver ( address , connectionPool , asyncConnectionPool , config , routingSettings ,
134+ securityPlan , retryLogic , eventExecutorGroup );
135135 default :
136136 throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
137137 }
@@ -158,13 +158,15 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
158158 * <b>This method is protected only for testing</b>
159159 */
160160 protected Driver createRoutingDriver ( BoltServerAddress address , ConnectionPool connectionPool ,
161- Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic )
161+ AsyncConnectionPool asyncConnectionPool , Config config , RoutingSettings routingSettings ,
162+ SecurityPlan securityPlan , RetryLogic retryLogic , EventExecutorGroup eventExecutorGroup )
162163 {
163164 if ( !securityPlan .isRoutingCompatible () )
164165 {
165166 throw new IllegalArgumentException ( "The chosen security plan is not compatible with a routing driver" );
166167 }
167- ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , config , routingSettings );
168+ ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , asyncConnectionPool ,
169+ eventExecutorGroup , config , routingSettings );
168170 SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
169171 return createDriver ( config , securityPlan , sessionFactory );
170172 }
@@ -184,21 +186,25 @@ protected InternalDriver createDriver( Config config, SecurityPlan securityPlan,
184186 * <p>
185187 * <b>This method is protected only for testing</b>
186188 */
187- protected LoadBalancer createLoadBalancer ( BoltServerAddress address , ConnectionPool connectionPool , Config config ,
188- RoutingSettings routingSettings )
189+ protected LoadBalancer createLoadBalancer ( BoltServerAddress address , ConnectionPool connectionPool ,
190+ AsyncConnectionPool asyncConnectionPool , EventExecutorGroup eventExecutorGroup ,
191+ Config config , RoutingSettings routingSettings )
189192 {
190- return new LoadBalancer ( address , routingSettings , connectionPool , createClock (), config .logging (),
191- createLoadBalancingStrategy ( config , connectionPool ) );
193+ LoadBalancingStrategy loadBalancingStrategy =
194+ createLoadBalancingStrategy ( config , connectionPool , asyncConnectionPool );
195+ return new LoadBalancer ( address , routingSettings , connectionPool , asyncConnectionPool , eventExecutorGroup ,
196+ createClock (), config .logging (), loadBalancingStrategy );
192197 }
193198
194- private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config , ConnectionPool connectionPool )
199+ private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config , ConnectionPool connectionPool ,
200+ AsyncConnectionPool asyncConnectionPool )
195201 {
196202 switch ( config .loadBalancingStrategy () )
197203 {
198204 case ROUND_ROBIN :
199205 return new RoundRobinLoadBalancingStrategy ( config .logging () );
200206 case LEAST_CONNECTED :
201- return new LeastConnectedLoadBalancingStrategy ( connectionPool , config .logging () );
207+ return new LeastConnectedLoadBalancingStrategy ( connectionPool , asyncConnectionPool , config .logging () );
202208 default :
203209 throw new IllegalArgumentException ( "Unknown load balancing strategy: " + config .loadBalancingStrategy () );
204210 }
@@ -253,7 +259,7 @@ protected SessionFactory createSessionFactory( ConnectionProvider connectionProv
253259 }
254260
255261 /**
256- * Creates new {@link RetryLogic > }.
262+ * Creates new {@link RetryLogic}.
257263 * <p>
258264 * <b>This method is protected only for testing</b>
259265 */
@@ -263,6 +269,16 @@ protected RetryLogic createRetryLogic( RetrySettings settings, EventExecutorGrou
263269 return new ExponentialBackoffRetryLogic ( settings , eventExecutorGroup , createClock (), logging );
264270 }
265271
272+ /**
273+ * Creates new {@link Bootstrap}.
274+ * <p>
275+ * <b>This method is protected only for testing</b>
276+ */
277+ protected Bootstrap createBootstrap ()
278+ {
279+ return BootstrapFactory .newBootstrap ();
280+ }
281+
266282 private static SecurityPlan createSecurityPlan ( BoltServerAddress address , Config config )
267283 {
268284 try
0 commit comments