19
19
package org .neo4j .driver .internal ;
20
20
21
21
import io .netty .bootstrap .Bootstrap ;
22
- import io .netty .channel .EventLoopGroup ;
23
22
import io .netty .util .concurrent .EventExecutorGroup ;
24
23
25
24
import java .io .IOException ;
@@ -76,17 +75,17 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
76
75
SecurityPlan securityPlan = createSecurityPlan ( address , config );
77
76
ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , config );
78
77
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 () );
82
81
83
82
AsyncConnectionPool asyncConnectionPool = createAsyncConnectionPool ( authToken , securityPlan , bootstrap ,
84
83
config );
85
84
86
85
try
87
86
{
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 );
90
89
}
91
90
catch ( Throwable driverError )
92
91
{
@@ -121,8 +120,8 @@ private AsyncConnectionPool createAsyncConnectionPool( AuthToken authToken, Secu
121
120
}
122
121
123
122
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 )
126
125
{
127
126
String scheme = uri .getScheme ().toLowerCase ();
128
127
switch ( scheme )
@@ -131,7 +130,8 @@ private Driver createDriver( URI uri, BoltServerAddress address, ConnectionPool
131
130
assertNoRoutingContext ( uri , routingSettings );
132
131
return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool );
133
132
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 );
135
135
default :
136
136
throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
137
137
}
@@ -158,13 +158,15 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
158
158
* <b>This method is protected only for testing</b>
159
159
*/
160
160
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 )
162
163
{
163
164
if ( !securityPlan .isRoutingCompatible () )
164
165
{
165
166
throw new IllegalArgumentException ( "The chosen security plan is not compatible with a routing driver" );
166
167
}
167
- ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , config , routingSettings );
168
+ ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , asyncConnectionPool ,
169
+ eventExecutorGroup , config , routingSettings );
168
170
SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
169
171
return createDriver ( config , securityPlan , sessionFactory );
170
172
}
@@ -184,21 +186,25 @@ protected InternalDriver createDriver( Config config, SecurityPlan securityPlan,
184
186
* <p>
185
187
* <b>This method is protected only for testing</b>
186
188
*/
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 )
189
192
{
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 );
192
197
}
193
198
194
- private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config , ConnectionPool connectionPool )
199
+ private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config , ConnectionPool connectionPool ,
200
+ AsyncConnectionPool asyncConnectionPool )
195
201
{
196
202
switch ( config .loadBalancingStrategy () )
197
203
{
198
204
case ROUND_ROBIN :
199
205
return new RoundRobinLoadBalancingStrategy ( config .logging () );
200
206
case LEAST_CONNECTED :
201
- return new LeastConnectedLoadBalancingStrategy ( connectionPool , config .logging () );
207
+ return new LeastConnectedLoadBalancingStrategy ( connectionPool , asyncConnectionPool , config .logging () );
202
208
default :
203
209
throw new IllegalArgumentException ( "Unknown load balancing strategy: " + config .loadBalancingStrategy () );
204
210
}
@@ -253,7 +259,7 @@ protected SessionFactory createSessionFactory( ConnectionProvider connectionProv
253
259
}
254
260
255
261
/**
256
- * Creates new {@link RetryLogic > }.
262
+ * Creates new {@link RetryLogic}.
257
263
* <p>
258
264
* <b>This method is protected only for testing</b>
259
265
*/
@@ -263,6 +269,16 @@ protected RetryLogic createRetryLogic( RetrySettings settings, EventExecutorGrou
263
269
return new ExponentialBackoffRetryLogic ( settings , eventExecutorGroup , createClock (), logging );
264
270
}
265
271
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
+
266
282
private static SecurityPlan createSecurityPlan ( BoltServerAddress address , Config config )
267
283
{
268
284
try
0 commit comments