SessionFactoryImpl( ConnectionProvider connectionProvider, RetryLogic retryLogic, Config config ) { this.connectionProvider = connectionProvider; this.leakedSessionsLoggingEnabled = config.logLeakedSessions(); this.retryLogic = retryLogic; this.logging = config.logging(); }
protected ChannelConnector createConnector( ConnectionSettings settings, SecurityPlan securityPlan, Config config, Clock clock ) { return new ChannelConnectorImpl( settings, securityPlan, config.logging(), clock ); }
/** * Creates new {@link Driver}. * <p> * <b>This method is protected only for testing</b> */ protected InternalDriver createDriver( SecurityPlan securityPlan, SessionFactory sessionFactory, Metrics metrics, Config config ) { return new InternalDriver( securityPlan, sessionFactory, metrics, config.logging() ); }
private static LoadBalancingStrategy createLoadBalancingStrategy( Config config, ConnectionPool connectionPool ) { switch ( config.loadBalancingStrategy() ) { case ROUND_ROBIN: return new RoundRobinLoadBalancingStrategy( config.logging() ); case LEAST_CONNECTED: return new LeastConnectedLoadBalancingStrategy( connectionPool, config.logging() ); default: throw new IllegalArgumentException( "Unknown load balancing strategy: " + config.loadBalancingStrategy() ); } }
private static Logger createLogger( Config config ) { Logging logging = getOrDefault( config ).logging(); return logging.getLog( LOGGER_NAME ); }
private static ServerAddressResolver createResolver( Config config ) { ServerAddressResolver configuredResolver = config.resolver(); return configuredResolver != null ? configuredResolver : new DnsResolver( config.logging() ); }
/** * Creates a new driver for "bolt" scheme. * <p> * <b>This method is protected only for testing</b> */ protected InternalDriver createDirectDriver( SecurityPlan securityPlan, BoltServerAddress address, ConnectionPool connectionPool, RetryLogic retryLogic, Metrics metrics, Config config ) { ConnectionProvider connectionProvider = new DirectConnectionProvider( address, connectionPool ); SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config ); InternalDriver driver = createDriver(securityPlan, sessionFactory, metrics, config); Logger log = config.logging().getLog( Driver.class.getSimpleName() ); log.info( "Direct driver instance %s created for server address %s", driver.hashCode(), address ); return driver; }
/** * Creates new a new driver for "bolt+routing" scheme. * <p> * <b>This method is protected only for testing</b> */ protected InternalDriver createRoutingDriver( SecurityPlan securityPlan, BoltServerAddress address, ConnectionPool connectionPool, EventExecutorGroup eventExecutorGroup, RoutingSettings routingSettings, RetryLogic retryLogic, Metrics metrics, Config config ) { if ( !securityPlan.isRoutingCompatible() ) { throw new IllegalArgumentException( "The chosen security plan is not compatible with a routing driver" ); } ConnectionProvider connectionProvider = createLoadBalancer( address, connectionPool, eventExecutorGroup, config, routingSettings ); SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config ); InternalDriver driver = createDriver(securityPlan, sessionFactory, metrics, config); Logger log = config.logging().getLog( Driver.class.getSimpleName() ); log.info( "Routing driver instance %s created for server address %s", driver.hashCode(), address ); return driver; }
/** * Creates new {@link LoadBalancer} for the routing driver. * <p> * <b>This method is protected only for testing</b> */ protected LoadBalancer createLoadBalancer( BoltServerAddress address, ConnectionPool connectionPool, EventExecutorGroup eventExecutorGroup, Config config, RoutingSettings routingSettings ) { LoadBalancingStrategy loadBalancingStrategy = createLoadBalancingStrategy( config, connectionPool ); ServerAddressResolver resolver = createResolver( config ); return new LoadBalancer( address, routingSettings, connectionPool, eventExecutorGroup, createClock(), config.logging(), loadBalancingStrategy, resolver ); }
private static void verifyConnectivity( InternalDriver driver, ConnectionPool connectionPool, Config config ) { try { // block to verify connectivity, close connection pool if thread gets interrupted Futures.blockingGet( driver.verifyConnectivity(), () -> closeConnectionPoolOnThreadInterrupt( connectionPool, config.logging() ) ); } catch ( Throwable connectionError ) { if ( Thread.currentThread().isInterrupted() ) { // current thread has been interrupted while verifying connectivity // connection pool should've been closed throw new ServiceUnavailableException( "Unable to create driver. Thread has been interrupted.", connectionError ); } // we need to close the connection pool if driver creation threw exception closeConnectionPoolAndSuppressError( connectionPool, connectionError ); throw connectionError; } }
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings, RetrySettings retrySettings, Config config ) { authToken = authToken == null ? AuthTokens.none() : authToken; BoltServerAddress address = new BoltServerAddress( uri ); RoutingSettings newRoutingSettings = routingSettings.withRoutingContext( new RoutingContext( uri ) ); SecurityPlan securityPlan = createSecurityPlan( address, config ); InternalLoggerFactory.setDefaultFactory( new NettyLogging( config.logging() ) ); Bootstrap bootstrap = createBootstrap(); EventExecutorGroup eventExecutorGroup = bootstrap.config().group(); RetryLogic retryLogic = createRetryLogic( retrySettings, eventExecutorGroup, config.logging() ); InternalAbstractMetrics metrics = createDriverMetrics( config ); ConnectionPool connectionPool = createConnectionPool( authToken, securityPlan, bootstrap, metrics, config ); InternalDriver driver = createDriver( uri, securityPlan, address, connectionPool, eventExecutorGroup, newRoutingSettings, retryLogic, metrics, config ); verifyConnectivity( driver, connectionPool, config ); return driver; }
protected ConnectionPool createConnectionPool( AuthToken authToken, SecurityPlan securityPlan, Bootstrap bootstrap, MetricsListener metrics, Config config ) { Clock clock = createClock(); ConnectionSettings settings = new ConnectionSettings( authToken, config.connectionTimeoutMillis() ); ChannelConnector connector = createConnector( settings, securityPlan, config, clock ); PoolSettings poolSettings = new PoolSettings( config.maxConnectionPoolSize(), config.connectionAcquisitionTimeoutMillis(), config.maxConnectionLifetimeMillis(), config.idleTimeBeforeConnectionTest() ); return new ConnectionPoolImpl( connector, bootstrap, poolSettings, metrics, config.logging(), clock ); }
Logger logger = config.logging().getLog( "SecurityPlan" ); Config.TrustStrategy trustStrategy = config.trustStrategy(); boolean hostnameVerificationEnabled = trustStrategy.isHostnameVerificationEnabled();