3838import org .neo4j .driver .internal .cluster .loadbalancing .LoadBalancingStrategy ;
3939import org .neo4j .driver .internal .cluster .loadbalancing .RoundRobinLoadBalancingStrategy ;
4040import 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 ;
4145import org .neo4j .driver .internal .retry .ExponentialBackoffRetryLogic ;
4246import org .neo4j .driver .internal .retry .RetryLogic ;
4347import org .neo4j .driver .internal .retry .RetrySettings ;
5660import org .neo4j .driver .v1 .exceptions .ServiceUnavailableException ;
5761
5862import 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 ;
5965import static org .neo4j .driver .internal .security .SecurityPlan .insecure ;
6066
6167public class DriverFactory
@@ -77,18 +83,17 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
7783 EventExecutorGroup eventExecutorGroup = bootstrap .config ().group ();
7884 RetryLogic retryLogic = createRetryLogic ( retrySettings , eventExecutorGroup , config .logging () );
7985
80- ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , bootstrap , config );
86+ InternalAbstractMetrics metrics = createDriverMetrics ( config );
87+ ConnectionPool connectionPool = createConnectionPool ( authToken , securityPlan , bootstrap , metrics , config );
8188
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 );
8490
8591 verifyConnectivity ( driver , connectionPool , config );
8692
8793 return driver ;
8894 }
8995
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 )
9297 {
9398 Clock clock = createClock ();
9499 ConnectionSettings settings = new ConnectionSettings ( authToken , config .connectionTimeoutMillis () );
@@ -97,7 +102,19 @@ protected ConnectionPool createConnectionPool( AuthToken authToken, SecurityPlan
97102 config .connectionAcquisitionTimeoutMillis (), config .maxConnectionLifetimeMillis (),
98103 config .idleTimeBeforeConnectionTest ()
99104 );
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+ }
101118 }
102119
103120 protected ChannelConnector createConnector ( ConnectionSettings settings , SecurityPlan securityPlan ,
@@ -106,9 +123,8 @@ protected ChannelConnector createConnector( ConnectionSettings settings, Securit
106123 return new ChannelConnectorImpl ( settings , securityPlan , config .logging (), clock );
107124 }
108125
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 )
112128 {
113129 try
114130 {
@@ -117,10 +133,9 @@ private InternalDriver createDriver( URI uri, BoltServerAddress address,
117133 {
118134 case BOLT_URI_SCHEME :
119135 assertNoRoutingContext ( uri , routingSettings );
120- return createDirectDriver ( address , config , securityPlan , retryLogic , connectionPool );
136+ return createDirectDriver ( securityPlan , address , connectionPool , retryLogic , metrics , config );
121137 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 );
124139 default :
125140 throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
126141 }
@@ -138,22 +153,21 @@ private InternalDriver createDriver( URI uri, BoltServerAddress address,
138153 * <p>
139154 * <b>This method is protected only for testing</b>
140155 */
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 )
143158 {
144159 ConnectionProvider connectionProvider = new DirectConnectionProvider ( address , connectionPool );
145160 SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
146- return createDriver ( sessionFactory , securityPlan , config );
161+ return createDriver ( securityPlan , sessionFactory , metrics , config );
147162 }
148163
149164 /**
150165 * Creates new a new driver for "bolt+routing" scheme.
151166 * <p>
152167 * <b>This method is protected only for testing</b>
153168 */
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 )
157171 {
158172 if ( !securityPlan .isRoutingCompatible () )
159173 {
@@ -162,17 +176,17 @@ protected InternalDriver createRoutingDriver( BoltServerAddress address, Connect
162176 ConnectionProvider connectionProvider = createLoadBalancer ( address , connectionPool , eventExecutorGroup ,
163177 config , routingSettings );
164178 SessionFactory sessionFactory = createSessionFactory ( connectionProvider , retryLogic , config );
165- return createDriver ( sessionFactory , securityPlan , config );
179+ return createDriver ( securityPlan , sessionFactory , metrics , config );
166180 }
167181
168182 /**
169183 * Creates new {@link Driver}.
170184 * <p>
171185 * <b>This method is protected only for testing</b>
172186 */
173- protected InternalDriver createDriver ( SessionFactory sessionFactory , SecurityPlan securityPlan , Config config )
187+ protected InternalDriver createDriver ( SecurityPlan securityPlan , SessionFactory sessionFactory , Metrics metrics , Config config )
174188 {
175- return new InternalDriver ( securityPlan , sessionFactory , config .logging () );
189+ return new InternalDriver ( securityPlan , sessionFactory , metrics , config .logging () );
176190 }
177191
178192 /**
0 commit comments