19
19
package org .neo4j .driver .internal ;
20
20
21
21
import io .netty .bootstrap .Bootstrap ;
22
+ import io .netty .channel .EventLoopGroup ;
23
+ import io .netty .util .concurrent .EventExecutorGroup ;
22
24
23
25
import java .io .IOException ;
24
26
import java .net .URI ;
@@ -72,14 +74,18 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
72
74
RoutingSettings newRoutingSettings = routingSettings .withRoutingContext ( new RoutingContext ( uri ) );
73
75
SecurityPlan securityPlan = createSecurityPlan ( address , config );
74
76
ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , config );
75
- RetryLogic retryLogic = createRetryLogic ( retrySettings , config .logging () );
76
77
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 );
78
84
79
85
try
80
86
{
81
87
return createDriver ( uri , address , connectionPool , config , newRoutingSettings , securityPlan , retryLogic ,
82
- asyncConnectionPool );
88
+ asyncConnectionPool , eventLoopGroup );
83
89
}
84
90
catch ( Throwable driverError )
85
91
{
@@ -98,14 +104,13 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
98
104
}
99
105
100
106
private AsyncConnectionPool createAsyncConnectionPool ( AuthToken authToken , SecurityPlan securityPlan ,
101
- Config config )
107
+ Bootstrap bootstrap , Config config )
102
108
{
103
109
Clock clock = createClock ();
104
110
ConnectionSettings connectionSettings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
105
111
ActiveChannelTracker activeChannelTracker = new ActiveChannelTracker ( config .logging () );
106
112
AsyncConnectorImpl connector = new AsyncConnectorImpl ( connectionSettings , securityPlan ,
107
113
activeChannelTracker , config .logging (), clock );
108
- Bootstrap bootstrap = BootstrapFactory .newBootstrap ();
109
114
PoolSettings poolSettings = new PoolSettings ( config .maxIdleConnectionPoolSize (),
110
115
config .idleTimeBeforeConnectionTest (), config .maxConnectionLifetimeMillis (),
111
116
config .maxConnectionPoolSize (),
@@ -116,16 +121,18 @@ private AsyncConnectionPool createAsyncConnectionPool( AuthToken authToken, Secu
116
121
117
122
private Driver createDriver ( URI uri , BoltServerAddress address , ConnectionPool connectionPool ,
118
123
Config config , RoutingSettings routingSettings , SecurityPlan securityPlan ,
119
- RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool )
124
+ RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool , EventExecutorGroup eventExecutorGroup )
120
125
{
121
126
String scheme = uri .getScheme ().toLowerCase ();
122
127
switch ( scheme )
123
128
{
124
129
case BOLT_URI_SCHEME :
125
130
assertNoRoutingContext ( uri , routingSettings );
126
- return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool );
131
+ return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool ,
132
+ eventExecutorGroup );
127
133
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 );
129
136
default :
130
137
throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
131
138
}
@@ -137,11 +144,13 @@ private Driver createDriver( URI uri, BoltServerAddress address, ConnectionPool
137
144
* <b>This method is protected only for testing</b>
138
145
*/
139
146
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 )
141
149
{
142
150
ConnectionProvider connectionProvider =
143
151
new DirectConnectionProvider ( address , connectionPool , asyncConnectionPool );
144
- SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
152
+ SessionFactory sessionFactory =
153
+ createSessionFactory ( connectionProvider , retryLogic , eventExecutorGroup , config );
145
154
return createDriver ( config , securityPlan , sessionFactory );
146
155
}
147
156
@@ -151,14 +160,16 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
151
160
* <b>This method is protected only for testing</b>
152
161
*/
153
162
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 )
155
165
{
156
166
if ( !securityPlan .isRoutingCompatible () )
157
167
{
158
168
throw new IllegalArgumentException ( "The chosen security plan is not compatible with a routing driver" );
159
169
}
160
170
ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , config , routingSettings );
161
- SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
171
+ SessionFactory sessionFactory =
172
+ createSessionFactory ( connectionProvider , retryLogic , eventExecutorGroup , config );
162
173
return createDriver ( config , securityPlan , sessionFactory );
163
174
}
164
175
@@ -239,20 +250,21 @@ protected Connector createConnector( final ConnectionSettings connectionSettings
239
250
* <p>
240
251
* <b>This method is protected only for testing</b>
241
252
*/
242
- protected SessionFactory createSessionFactory ( ConnectionProvider connectionProvider ,
243
- RetryLogic retryLogic , Config config )
253
+ protected SessionFactory createSessionFactory ( ConnectionProvider connectionProvider , RetryLogic retryLogic ,
254
+ EventExecutorGroup eventExecutorGroup , Config config )
244
255
{
245
- return new SessionFactoryImpl ( connectionProvider , retryLogic , config );
256
+ return new SessionFactoryImpl ( connectionProvider , retryLogic , eventExecutorGroup , config );
246
257
}
247
258
248
259
/**
249
260
* Creates new {@link RetryLogic >}.
250
261
* <p>
251
262
* <b>This method is protected only for testing</b>
252
263
*/
253
- protected RetryLogic createRetryLogic ( RetrySettings settings , Logging logging )
264
+ protected RetryLogic createRetryLogic ( RetrySettings settings , EventExecutorGroup eventExecutorGroup ,
265
+ Logging logging )
254
266
{
255
- return new ExponentialBackoffRetryLogic ( settings , createClock (), logging );
267
+ return new ExponentialBackoffRetryLogic ( settings , eventExecutorGroup , createClock (), logging );
256
268
}
257
269
258
270
private static SecurityPlan createSecurityPlan ( BoltServerAddress address , Config config )
0 commit comments