25
25
import java .net .URI ;
26
26
import java .security .GeneralSecurityException ;
27
27
28
- import org .neo4j .driver .internal .async .AsyncConnectorImpl ;
28
+ import org .neo4j .driver .internal .async .BoltServerAddress ;
29
29
import org .neo4j .driver .internal .async .BootstrapFactory ;
30
- import org .neo4j .driver .internal .async .Futures ;
31
- import org .neo4j .driver .internal .async .pool .AsyncConnectionPool ;
32
- import org .neo4j .driver .internal .async .pool .AsyncConnectionPoolImpl ;
30
+ import org .neo4j .driver .internal .async .ChannelConnector ;
31
+ import org .neo4j .driver .internal .async .ChannelConnectorImpl ;
32
+ import org .neo4j .driver .internal .async .pool .ConnectionPoolImpl ;
33
+ import org .neo4j .driver .internal .async .pool .PoolSettings ;
33
34
import org .neo4j .driver .internal .cluster .RoutingContext ;
34
35
import org .neo4j .driver .internal .cluster .RoutingSettings ;
35
36
import org .neo4j .driver .internal .cluster .loadbalancing .LeastConnectedLoadBalancingStrategy ;
36
37
import org .neo4j .driver .internal .cluster .loadbalancing .LoadBalancer ;
37
38
import org .neo4j .driver .internal .cluster .loadbalancing .LoadBalancingStrategy ;
38
39
import org .neo4j .driver .internal .cluster .loadbalancing .RoundRobinLoadBalancingStrategy ;
39
- import org .neo4j .driver .internal .net .BoltServerAddress ;
40
- import org .neo4j .driver .internal .net .SocketConnector ;
41
- import org .neo4j .driver .internal .net .pooling .PoolSettings ;
42
- import org .neo4j .driver .internal .net .pooling .SocketConnectionPool ;
43
40
import org .neo4j .driver .internal .retry .ExponentialBackoffRetryLogic ;
44
41
import org .neo4j .driver .internal .retry .RetryLogic ;
45
42
import org .neo4j .driver .internal .retry .RetrySettings ;
46
43
import org .neo4j .driver .internal .security .SecurityPlan ;
47
44
import org .neo4j .driver .internal .spi .ConnectionPool ;
48
45
import org .neo4j .driver .internal .spi .ConnectionProvider ;
49
- import org .neo4j .driver .internal .spi .Connector ;
50
46
import org .neo4j .driver .internal .util .Clock ;
47
+ import org .neo4j .driver .internal .util .Futures ;
51
48
import org .neo4j .driver .v1 .AuthToken ;
52
49
import org .neo4j .driver .v1 .AuthTokens ;
53
50
import org .neo4j .driver .v1 .Config ;
@@ -72,27 +69,26 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
72
69
BoltServerAddress address = new BoltServerAddress ( uri );
73
70
RoutingSettings newRoutingSettings = routingSettings .withRoutingContext ( new RoutingContext ( uri ) );
74
71
SecurityPlan securityPlan = createSecurityPlan ( address , config );
75
- ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , config );
76
72
77
73
Bootstrap bootstrap = createBootstrap ();
78
74
EventExecutorGroup eventExecutorGroup = bootstrap .config ().group ();
79
75
RetryLogic retryLogic = createRetryLogic ( retrySettings , eventExecutorGroup , config .logging () );
80
76
81
- AsyncConnectionPool asyncConnectionPool = createAsyncConnectionPool ( authToken , securityPlan , bootstrap ,
82
- config );
77
+ ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , bootstrap , config );
83
78
84
79
try
85
80
{
86
- return createDriver ( uri , address , connectionPool , asyncConnectionPool , config , newRoutingSettings ,
81
+ InternalDriver driver = createDriver ( uri , address , connectionPool , config , newRoutingSettings ,
87
82
eventExecutorGroup , securityPlan , retryLogic );
83
+ Futures .getBlocking ( driver .verifyConnectivity () );
84
+ return driver ;
88
85
}
89
86
catch ( Throwable driverError )
90
87
{
91
88
// we need to close the connection pool if driver creation threw exception
92
89
try
93
90
{
94
- connectionPool .close ();
95
- Futures .getBlocking ( asyncConnectionPool .close () );
91
+ Futures .getBlocking ( connectionPool .close () );
96
92
}
97
93
catch ( Throwable closeError )
98
94
{
@@ -102,32 +98,38 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
102
98
}
103
99
}
104
100
105
- private AsyncConnectionPool createAsyncConnectionPool ( AuthToken authToken , SecurityPlan securityPlan ,
101
+ protected ConnectionPool createConnectionPool ( AuthToken authToken , SecurityPlan securityPlan ,
106
102
Bootstrap bootstrap , Config config )
107
103
{
108
104
Clock clock = createClock ();
109
105
ConnectionSettings settings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
110
- AsyncConnectorImpl connector = new AsyncConnectorImpl ( settings , securityPlan , config . logging () , clock );
106
+ ChannelConnector connector = createConnector ( settings , securityPlan , config , clock );
111
107
PoolSettings poolSettings = new PoolSettings ( config .maxIdleConnectionPoolSize (),
112
108
config .idleTimeBeforeConnectionTest (), config .maxConnectionLifetimeMillis (),
113
109
config .maxConnectionPoolSize (),
114
110
config .connectionAcquisitionTimeoutMillis () );
115
- return new AsyncConnectionPoolImpl ( connector , bootstrap , poolSettings , config .logging (), clock );
111
+ return new ConnectionPoolImpl ( connector , bootstrap , poolSettings , config .logging (), clock );
116
112
}
117
113
118
- private Driver createDriver ( URI uri , BoltServerAddress address , ConnectionPool connectionPool ,
119
- AsyncConnectionPool asyncConnectionPool , Config config , RoutingSettings routingSettings ,
114
+ protected ChannelConnector createConnector ( ConnectionSettings settings , SecurityPlan securityPlan ,
115
+ Config config , Clock clock )
116
+ {
117
+ return new ChannelConnectorImpl ( settings , securityPlan , config .logging (), clock );
118
+ }
119
+
120
+ private InternalDriver createDriver ( URI uri , BoltServerAddress address ,
121
+ ConnectionPool connectionPool , Config config , RoutingSettings routingSettings ,
120
122
EventExecutorGroup eventExecutorGroup , SecurityPlan securityPlan , RetryLogic retryLogic )
121
123
{
122
124
String scheme = uri .getScheme ().toLowerCase ();
123
125
switch ( scheme )
124
126
{
125
127
case BOLT_URI_SCHEME :
126
128
assertNoRoutingContext ( uri , routingSettings );
127
- return createDirectDriver ( address , connectionPool , config , securityPlan , retryLogic , asyncConnectionPool );
129
+ return createDirectDriver ( address , config , securityPlan , retryLogic , connectionPool );
128
130
case BOLT_ROUTING_URI_SCHEME :
129
- return createRoutingDriver ( address , connectionPool , asyncConnectionPool , config , routingSettings ,
130
- securityPlan , retryLogic , eventExecutorGroup );
131
+ return createRoutingDriver ( address , connectionPool , config , routingSettings , securityPlan , retryLogic ,
132
+ eventExecutorGroup );
131
133
default :
132
134
throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
133
135
}
@@ -138,11 +140,11 @@ private Driver createDriver( URI uri, BoltServerAddress address, ConnectionPool
138
140
* <p>
139
141
* <b>This method is protected only for testing</b>
140
142
*/
141
- protected Driver createDirectDriver ( BoltServerAddress address , ConnectionPool connectionPool , Config config ,
142
- SecurityPlan securityPlan , RetryLogic retryLogic , AsyncConnectionPool asyncConnectionPool )
143
+ protected InternalDriver createDirectDriver ( BoltServerAddress address , Config config ,
144
+ SecurityPlan securityPlan , RetryLogic retryLogic , ConnectionPool connectionPool )
143
145
{
144
146
ConnectionProvider connectionProvider =
145
- new DirectConnectionProvider ( address , connectionPool , asyncConnectionPool );
147
+ new DirectConnectionProvider ( address , connectionPool );
146
148
SessionFactory sessionFactory =
147
149
createSessionFactory ( connectionProvider , retryLogic , config );
148
150
return createDriver ( config , securityPlan , sessionFactory );
@@ -153,16 +155,16 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
153
155
* <p>
154
156
* <b>This method is protected only for testing</b>
155
157
*/
156
- protected Driver createRoutingDriver ( BoltServerAddress address , ConnectionPool connectionPool ,
157
- AsyncConnectionPool asyncConnectionPool , Config config , RoutingSettings routingSettings ,
158
- SecurityPlan securityPlan , RetryLogic retryLogic , EventExecutorGroup eventExecutorGroup )
158
+ protected InternalDriver createRoutingDriver ( BoltServerAddress address , ConnectionPool connectionPool ,
159
+ Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic ,
160
+ EventExecutorGroup eventExecutorGroup )
159
161
{
160
162
if ( !securityPlan .isRoutingCompatible () )
161
163
{
162
164
throw new IllegalArgumentException ( "The chosen security plan is not compatible with a routing driver" );
163
165
}
164
- ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , asyncConnectionPool ,
165
- eventExecutorGroup , config , routingSettings );
166
+ ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , eventExecutorGroup ,
167
+ config , routingSettings );
166
168
SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
167
169
return createDriver ( config , securityPlan , sessionFactory );
168
170
}
@@ -174,7 +176,7 @@ protected Driver createRoutingDriver( BoltServerAddress address, ConnectionPool
174
176
*/
175
177
protected InternalDriver createDriver ( Config config , SecurityPlan securityPlan , SessionFactory sessionFactory )
176
178
{
177
- return new InternalDriver ( securityPlan , sessionFactory , config . logging () );
179
+ return new InternalDriver ( securityPlan , sessionFactory );
178
180
}
179
181
180
182
/**
@@ -183,45 +185,27 @@ protected InternalDriver createDriver( Config config, SecurityPlan securityPlan,
183
185
* <b>This method is protected only for testing</b>
184
186
*/
185
187
protected LoadBalancer createLoadBalancer ( BoltServerAddress address , ConnectionPool connectionPool ,
186
- AsyncConnectionPool asyncConnectionPool , EventExecutorGroup eventExecutorGroup ,
187
- Config config , RoutingSettings routingSettings )
188
+ EventExecutorGroup eventExecutorGroup , Config config , RoutingSettings routingSettings )
188
189
{
189
- LoadBalancingStrategy loadBalancingStrategy =
190
- createLoadBalancingStrategy ( config , connectionPool , asyncConnectionPool );
191
- return new LoadBalancer ( address , routingSettings , connectionPool , asyncConnectionPool , eventExecutorGroup ,
192
- createClock (), config .logging (), loadBalancingStrategy );
190
+ LoadBalancingStrategy loadBalancingStrategy = createLoadBalancingStrategy ( config , connectionPool );
191
+ return new LoadBalancer ( address , routingSettings , connectionPool , eventExecutorGroup , createClock (),
192
+ config .logging (), loadBalancingStrategy );
193
193
}
194
194
195
- private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config , ConnectionPool connectionPool ,
196
- AsyncConnectionPool asyncConnectionPool )
195
+ private static LoadBalancingStrategy createLoadBalancingStrategy ( Config config ,
196
+ ConnectionPool connectionPool )
197
197
{
198
198
switch ( config .loadBalancingStrategy () )
199
199
{
200
200
case ROUND_ROBIN :
201
201
return new RoundRobinLoadBalancingStrategy ( config .logging () );
202
202
case LEAST_CONNECTED :
203
- return new LeastConnectedLoadBalancingStrategy ( connectionPool , asyncConnectionPool , config .logging () );
203
+ return new LeastConnectedLoadBalancingStrategy ( connectionPool , config .logging () );
204
204
default :
205
205
throw new IllegalArgumentException ( "Unknown load balancing strategy: " + config .loadBalancingStrategy () );
206
206
}
207
207
}
208
208
209
- /**
210
- * Creates new {@link ConnectionPool}.
211
- * <p>
212
- * <b>This method is protected only for testing</b>
213
- */
214
- protected ConnectionPool createConnectionPool ( AuthToken authToken , SecurityPlan securityPlan , Config config )
215
- {
216
- ConnectionSettings connectionSettings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
217
- PoolSettings poolSettings = new PoolSettings ( config .maxIdleConnectionPoolSize (),
218
- config .idleTimeBeforeConnectionTest (), config .maxConnectionLifetimeMillis (),
219
- config .maxConnectionPoolSize (), config .connectionAcquisitionTimeoutMillis () );
220
- Connector connector = createConnector ( connectionSettings , securityPlan , config .logging () );
221
-
222
- return new SocketConnectionPool ( poolSettings , connector , createClock (), config .logging () );
223
- }
224
-
225
209
/**
226
210
* Creates new {@link Clock}.
227
211
* <p>
@@ -232,17 +216,6 @@ protected Clock createClock()
232
216
return Clock .SYSTEM ;
233
217
}
234
218
235
- /**
236
- * Creates new {@link Connector}.
237
- * <p>
238
- * <b>This method is protected only for testing</b>
239
- */
240
- protected Connector createConnector ( final ConnectionSettings connectionSettings , SecurityPlan securityPlan ,
241
- Logging logging )
242
- {
243
- return new SocketConnector ( connectionSettings , securityPlan , logging );
244
- }
245
-
246
219
/**
247
220
* Creates new {@link SessionFactory}.
248
221
* <p>
0 commit comments