38
38
import org .neo4j .driver .internal .cluster .loadbalancing .LoadBalancingStrategy ;
39
39
import org .neo4j .driver .internal .cluster .loadbalancing .RoundRobinLoadBalancingStrategy ;
40
40
import org .neo4j .driver .internal .logging .NettyLogging ;
41
+ import org .neo4j .driver .internal .metrics .MetricsListener ;
42
+ import org .neo4j .driver .internal .metrics .InternalAbstractMetrics ;
43
+ import org .neo4j .driver .internal .metrics .InternalMetrics ;
44
+ import org .neo4j .driver .internal .metrics .spi .Metrics ;
41
45
import org .neo4j .driver .internal .retry .ExponentialBackoffRetryLogic ;
42
46
import org .neo4j .driver .internal .retry .RetryLogic ;
43
47
import org .neo4j .driver .internal .retry .RetrySettings ;
56
60
import org .neo4j .driver .v1 .exceptions .ServiceUnavailableException ;
57
61
58
62
import static java .lang .String .format ;
63
+ import static org .neo4j .driver .internal .metrics .InternalAbstractMetrics .DEV_NULL_METRICS ;
64
+ import static org .neo4j .driver .internal .metrics .spi .Metrics .isMetricsEnabled ;
59
65
import static org .neo4j .driver .internal .security .SecurityPlan .insecure ;
60
66
61
67
public class DriverFactory
@@ -77,18 +83,17 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
77
83
EventExecutorGroup eventExecutorGroup = bootstrap .config ().group ();
78
84
RetryLogic retryLogic = createRetryLogic ( retrySettings , eventExecutorGroup , config .logging () );
79
85
80
- ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , bootstrap , config );
86
+ InternalAbstractMetrics metrics = createDriverMetrics ( config );
87
+ ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , bootstrap , metrics , config );
81
88
82
- InternalDriver driver = createDriver ( uri , address , connectionPool , config , newRoutingSettings ,
83
- eventExecutorGroup , securityPlan , retryLogic );
89
+ InternalDriver driver = createDriver ( uri , securityPlan , address , connectionPool , eventExecutorGroup , newRoutingSettings , retryLogic , metrics , config );
84
90
85
91
verifyConnectivity ( driver , connectionPool , config );
86
92
87
93
return driver ;
88
94
}
89
95
90
- protected ConnectionPool createConnectionPool ( AuthToken authToken , SecurityPlan securityPlan ,
91
- Bootstrap bootstrap , Config config )
96
+ protected ConnectionPool createConnectionPool ( AuthToken authToken , SecurityPlan securityPlan , Bootstrap bootstrap , MetricsListener metrics , Config config )
92
97
{
93
98
Clock clock = createClock ();
94
99
ConnectionSettings settings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
@@ -97,7 +102,19 @@ protected ConnectionPool createConnectionPool( AuthToken authToken, SecurityPlan
97
102
config .connectionAcquisitionTimeoutMillis (), config .maxConnectionLifetimeMillis (),
98
103
config .idleTimeBeforeConnectionTest ()
99
104
);
100
- return new ConnectionPoolImpl ( connector , bootstrap , poolSettings , config .logging (), clock );
105
+ return new ConnectionPoolImpl ( connector , bootstrap , poolSettings , metrics , config .logging (), clock );
106
+ }
107
+
108
+ protected static InternalAbstractMetrics createDriverMetrics ( Config config )
109
+ {
110
+ if ( isMetricsEnabled () )
111
+ {
112
+ return new InternalMetrics ( config );
113
+ }
114
+ else
115
+ {
116
+ return DEV_NULL_METRICS ;
117
+ }
101
118
}
102
119
103
120
protected ChannelConnector createConnector ( ConnectionSettings settings , SecurityPlan securityPlan ,
@@ -106,9 +123,8 @@ protected ChannelConnector createConnector( ConnectionSettings settings, Securit
106
123
return new ChannelConnectorImpl ( settings , securityPlan , config .logging (), clock );
107
124
}
108
125
109
- private InternalDriver createDriver ( URI uri , BoltServerAddress address ,
110
- ConnectionPool connectionPool , Config config , RoutingSettings routingSettings ,
111
- EventExecutorGroup eventExecutorGroup , SecurityPlan securityPlan , RetryLogic retryLogic )
126
+ private InternalDriver createDriver ( URI uri , SecurityPlan securityPlan , BoltServerAddress address , ConnectionPool connectionPool ,
127
+ EventExecutorGroup eventExecutorGroup , RoutingSettings routingSettings , RetryLogic retryLogic , Metrics metrics , Config config )
112
128
{
113
129
try
114
130
{
@@ -117,10 +133,9 @@ private InternalDriver createDriver( URI uri, BoltServerAddress address,
117
133
{
118
134
case BOLT_URI_SCHEME :
119
135
assertNoRoutingContext ( uri , routingSettings );
120
- return createDirectDriver ( address , config , securityPlan , retryLogic , connectionPool );
136
+ return createDirectDriver ( securityPlan , address , connectionPool , retryLogic , metrics , config );
121
137
case BOLT_ROUTING_URI_SCHEME :
122
- return createRoutingDriver ( address , connectionPool , config , routingSettings , securityPlan , retryLogic ,
123
- eventExecutorGroup );
138
+ return createRoutingDriver ( securityPlan , address , connectionPool , eventExecutorGroup , routingSettings , retryLogic , metrics , config );
124
139
default :
125
140
throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
126
141
}
@@ -138,22 +153,21 @@ private InternalDriver createDriver( URI uri, BoltServerAddress address,
138
153
* <p>
139
154
* <b>This method is protected only for testing</b>
140
155
*/
141
- protected InternalDriver createDirectDriver ( BoltServerAddress address , Config config ,
142
- SecurityPlan securityPlan , RetryLogic retryLogic , ConnectionPool connectionPool )
156
+ protected InternalDriver createDirectDriver ( SecurityPlan securityPlan , BoltServerAddress address , ConnectionPool connectionPool , RetryLogic retryLogic ,
157
+ Metrics metrics , Config config )
143
158
{
144
159
ConnectionProvider connectionProvider = new DirectConnectionProvider ( address , connectionPool );
145
160
SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
146
- return createDriver ( sessionFactory , securityPlan , config );
161
+ return createDriver ( securityPlan , sessionFactory , metrics , config );
147
162
}
148
163
149
164
/**
150
165
* Creates new a new driver for "bolt+routing" scheme.
151
166
* <p>
152
167
* <b>This method is protected only for testing</b>
153
168
*/
154
- protected InternalDriver createRoutingDriver ( BoltServerAddress address , ConnectionPool connectionPool ,
155
- Config config , RoutingSettings routingSettings , SecurityPlan securityPlan , RetryLogic retryLogic ,
156
- EventExecutorGroup eventExecutorGroup )
169
+ protected InternalDriver createRoutingDriver ( SecurityPlan securityPlan , BoltServerAddress address , ConnectionPool connectionPool ,
170
+ EventExecutorGroup eventExecutorGroup , RoutingSettings routingSettings , RetryLogic retryLogic , Metrics metrics , Config config )
157
171
{
158
172
if ( !securityPlan .isRoutingCompatible () )
159
173
{
@@ -162,17 +176,17 @@ protected InternalDriver createRoutingDriver( BoltServerAddress address, Connect
162
176
ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , eventExecutorGroup ,
163
177
config , routingSettings );
164
178
SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
165
- return createDriver ( sessionFactory , securityPlan , config );
179
+ return createDriver ( securityPlan , sessionFactory , metrics , config );
166
180
}
167
181
168
182
/**
169
183
* Creates new {@link Driver}.
170
184
* <p>
171
185
* <b>This method is protected only for testing</b>
172
186
*/
173
- protected InternalDriver createDriver ( SessionFactory sessionFactory , SecurityPlan securityPlan , Config config )
187
+ protected InternalDriver createDriver ( SecurityPlan securityPlan , SessionFactory sessionFactory , Metrics metrics , Config config )
174
188
{
175
- return new InternalDriver ( securityPlan , sessionFactory , config .logging () );
189
+ return new InternalDriver ( securityPlan , sessionFactory , metrics , config .logging () );
176
190
}
177
191
178
192
/**
0 commit comments