1919package org .neo4j .driver .internal ;
2020
2121import io .netty .bootstrap .Bootstrap ;
22+ import io .netty .channel .EventLoopGroup ;
23+ import io .netty .util .concurrent .EventExecutorGroup ;
2224
2325import java .io .IOException ;
2426import java .net .URI ;
@@ -72,14 +74,18 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
7274 RoutingSettings newRoutingSettings = routingSettings .withRoutingContext ( new RoutingContext ( uri ) );
7375 SecurityPlan securityPlan = createSecurityPlan ( address , config );
7476 ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , config );
75- RetryLogic retryLogic = createRetryLogic ( retrySettings , config .logging () );
7677
77- AsyncConnectionPool asyncConnectionPool = createAsyncConnectionPool ( authToken , securityPlan , config );
78+ Bootstrap bootstrap = BootstrapFactory .newBootstrap ();
79+ EventLoopGroup eventLoopGroup = bootstrap .config ().group ();
80+ RetryLogic retryLogic = createRetryLogic ( retrySettings , eventLoopGroup , config .logging () );
81+
82+ AsyncConnectionPool asyncConnectionPool = createAsyncConnectionPool ( authToken , securityPlan , bootstrap ,
83+ config );
7884
7985 try
8086 {
8187 return createDriver ( uri , address , connectionPool , config , newRoutingSettings , securityPlan , retryLogic ,
82- asyncConnectionPool );
88+ asyncConnectionPool , eventLoopGroup );
8389 }
8490 catch ( Throwable driverError )
8591 {
@@ -98,14 +104,13 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
98104 }
99105
100106 private AsyncConnectionPool createAsyncConnectionPool ( AuthToken authToken , SecurityPlan securityPlan ,
101- Config config )
107+ Bootstrap bootstrap , Config config )
102108 {
103109 Clock clock = createClock ();
104110 ConnectionSettings connectionSettings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
105111 ActiveChannelTracker activeChannelTracker = new ActiveChannelTracker ( config .logging () );
106112 AsyncConnectorImpl connector = new AsyncConnectorImpl ( connectionSettings , securityPlan ,
107113 activeChannelTracker , config .logging (), clock );
108- Bootstrap bootstrap = BootstrapFactory .newBootstrap ();
109114 PoolSettings poolSettings = new PoolSettings ( config .maxIdleConnectionPoolSize (),
110115 config .idleTimeBeforeConnectionTest (), config .maxConnectionLifetimeMillis (),
111116 config .maxConnectionPoolSize (),
@@ -116,16 +121,18 @@ private AsyncConnectionPool createAsyncConnectionPool( AuthToken authToken, Secu
116121
117122 private Driver createDriver ( URI uri , BoltServerAddress address , ConnectionPool connectionPool ,
118123 Config config , RoutingSettings routingSettings , SecurityPlan securityPlan ,
119- RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool )
124+ RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool , EventExecutorGroup eventExecutorGroup )
120125 {
121126 String scheme = uri .getScheme ().toLowerCase ();
122127 switch ( scheme )
123128 {
124129 case BOLT_URI_SCHEME :
125130 assertNoRoutingContext ( uri , routingSettings );
126- return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool );
131+ return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool ,
132+ eventExecutorGroup );
127133 case BOLT_ROUTING_URI_SCHEME :
128- return createRoutingDriver ( address , connectionPool , config , routingSettings , securityPlan , retryLogic );
134+ return createRoutingDriver ( address , connectionPool , config , routingSettings , securityPlan , retryLogic ,
135+ eventExecutorGroup );
129136 default :
130137 throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
131138 }
@@ -137,11 +144,13 @@ private Driver createDriver( URI uri, BoltServerAddress address, ConnectionPool
137144 * <b>This method is protected only for testing</b>
138145 */
139146 protected Driver createDirectDriver ( BoltServerAddress address , ConnectionPool connectionPool , Config config ,
140- SecurityPlan securityPlan , RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool )
147+ SecurityPlan securityPlan , RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool ,
148+ EventExecutorGroup eventExecutorGroup )
141149 {
142150 ConnectionProvider connectionProvider =
143151 new DirectConnectionProvider ( address , connectionPool , asyncConnectionPool );
144- SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
152+ SessionFactory sessionFactory =
153+ createSessionFactory ( connectionProvider , retryLogic , eventExecutorGroup , config );
145154 return createDriver ( config , securityPlan , sessionFactory );
146155 }
147156
@@ -151,14 +160,16 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
151160 * <b>This method is protected only for testing</b>
152161 */
153162 protected Driver createRoutingDriver ( BoltServerAddress address , ConnectionPool connectionPool ,
154- Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic )
163+ Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic ,
164+ EventExecutorGroup eventExecutorGroup )
155165 {
156166 if ( !securityPlan .isRoutingCompatible () )
157167 {
158168 throw new IllegalArgumentException ( "The chosen security plan is not compatible with a routing driver" );
159169 }
160170 ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , config , routingSettings );
161- SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
171+ SessionFactory sessionFactory =
172+ createSessionFactory ( connectionProvider , retryLogic , eventExecutorGroup , config );
162173 return createDriver ( config , securityPlan , sessionFactory );
163174 }
164175
@@ -239,20 +250,21 @@ protected Connector createConnector( final ConnectionSettings connectionSettings
239250 * <p>
240251 * <b>This method is protected only for testing</b>
241252 */
242- protected SessionFactory createSessionFactory ( ConnectionProvider connectionProvider ,
243- RetryLogic retryLogic , Config config )
253+ protected SessionFactory createSessionFactory ( ConnectionProvider connectionProvider , RetryLogic retryLogic ,
254+ EventExecutorGroup eventExecutorGroup , Config config )
244255 {
245- return new SessionFactoryImpl ( connectionProvider , retryLogic , config );
256+ return new SessionFactoryImpl ( connectionProvider , retryLogic , eventExecutorGroup , config );
246257 }
247258
248259 /**
249260 * Creates new {@link RetryLogic >}.
250261 * <p>
251262 * <b>This method is protected only for testing</b>
252263 */
253- protected RetryLogic createRetryLogic ( RetrySettings settings , Logging logging )
264+ protected RetryLogic createRetryLogic ( RetrySettings settings , EventExecutorGroup eventExecutorGroup ,
265+ Logging logging )
254266 {
255- return new ExponentialBackoffRetryLogic ( settings , createClock (), logging );
267+ return new ExponentialBackoffRetryLogic ( settings , eventExecutorGroup , createClock (), logging );
256268 }
257269
258270 private static SecurityPlan createSecurityPlan ( BoltServerAddress address , Config config )
0 commit comments