/** * @return list of all configured bolt connectors which are enabled */ @Nonnull public List<BoltConnector> enabledBoltConnectors() { return enabledBoltConnectors( params ); }
private Map<BoltConnector,ProtocolInitializer> createConnectors( BoltProtocolFactory boltProtocolFactory, TransportThrottleGroup throttleGroup, Log log ) { return config.enabledBoltConnectors() .stream() .collect( toMap( identity(), connector -> createProtocolInitializer( connector, boltProtocolFactory, throttleGroup, log ) ) ); }
@Override public URI boltURI() { List<BoltConnector> connectors = server.getConfig().enabledBoltConnectors(); BoltConnector defaultConnector = null; BoltConnector firstConnector = null; for ( BoltConnector connector : connectors ) { if ( DEFAULT_BOLT_CONNECTOR_KEY.equals( connector.key() ) ) { defaultConnector = connector; } if ( firstConnector == null ) { firstConnector = connector; } } if ( defaultConnector != null ) { // bolt connector with default key is configured, return its address return connectorUri( "bolt", defaultConnector ); } if ( firstConnector != null ) { // some bolt connector is configured, return its address return connectorUri( "bolt", firstConnector ); } throw new IllegalStateException( "Bolt connector is not configured" ); }
@Test void shouldBeAbleToDisableBoltConnectorWithJustOneParameter() { // given Config config = Config.defaults( new BoltConnector( "bolt" ).enabled, "false" ); // then assertThat( config.boltConnectors().size(), is( 1 ) ); assertThat( config.enabledBoltConnectors(), empty() ); }
@Override public void start() { forkJoinThreadPool = new ForkJoinPool(); config.enabledBoltConnectors().forEach( connector -> { BoltScheduler boltScheduler = new ExecutorBoltScheduler( connector.key(), executorFactory, scheduler, logService, config.get( connector.thread_pool_min_size ), config.get( connector.thread_pool_max_size ), config.get( connector.thread_pool_keep_alive ), config.get( connector.unsupported_thread_pool_queue_size ), forkJoinThreadPool ); boltScheduler.start(); boltSchedulers.put( connector.key(), boltScheduler ); } ); }
public Builder addBoltConnectorFromConfig( String key, String scheme, Config config, Setting<URI> override, ConnectorPortRegister portRegister ) { // If an override is configured, add it with the HIGHEST precedence if ( config.isConfigured( override ) ) { add( key, config.get( override ), HIGHEST ); } config.enabledBoltConnectors().stream().findFirst().ifPresent( c -> { AdvertisedSocketAddress address = config.get( c.advertised_address ); int port = address.getPort(); if ( port == 0 ) { port = portRegister.getLocalAddress( c.key() ).getPort(); } // If advertised address is explicitly set, set the precedence to HIGH - eitherwise set it as LOWEST (default) add( key, scheme, address.getHostname(), port, config.isConfigured( c.advertised_address ) ? HIGH : LOWEST ); } ); return this; }
@Override public void start() throws Throwable { Log log = logService.getInternalLog( BoltServer.class ); Log userLog = logService.getUserLog( BoltServer.class ); InternalLoggerFactory.setDefaultFactory( new Netty4LoggerFactory( logService.getInternalLogProvider() ) ); Authentication authentication = createAuthentication(); TransportThrottleGroup throttleGroup = new TransportThrottleGroup( config, clock ); BoltSchedulerProvider boltSchedulerProvider = life.add( new ExecutorBoltSchedulerProvider( config, new CachedThreadPoolExecutorFactory( log ), jobScheduler, logService ) ); BoltConnectionFactory boltConnectionFactory = createConnectionFactory( config, boltSchedulerProvider, throttleGroup, logService, clock ); BoltStateMachineFactory boltStateMachineFactory = createBoltFactory( authentication, clock ); BoltProtocolFactory boltProtocolFactory = createBoltProtocolFactory( boltConnectionFactory, boltStateMachineFactory ); if ( !config.enabledBoltConnectors().isEmpty() && !config.get( GraphDatabaseSettings.disconnected ) ) { NettyServer server = new NettyServer( jobScheduler.threadFactory( Group.BOLT_NETWORK_IO ), createConnectors( boltProtocolFactory, throttleGroup, log ), connectorPortRegister, userLog ); life.add( server ); log.info( "Bolt server loaded" ); } life.start(); // init and start the nested lifecycle }
private Optional<String> getBoltConnector() { Config config = api.getDependencyResolver().resolveDependency( Config.class ); final Optional<BoltConnector> boltConnector = config.enabledBoltConnectors().stream().findFirst(); if ( boltConnector.isPresent() ) { AdvertisedSocketAddress from = boltConnector.get().advertised_address.from( config ); return Optional.of( "bolt://" + from ); } return Optional.empty(); }
/** * @return list of all configured bolt connectors which are enabled */ @Nonnull public List<BoltConnector> enabledBoltConnectors() { return enabledBoltConnectors( params ); }
private Map<BoltConnector,ProtocolInitializer> createConnectors( BoltProtocolFactory boltProtocolFactory, TransportThrottleGroup throttleGroup, Log log ) { return config.enabledBoltConnectors() .stream() .collect( toMap( identity(), connector -> createProtocolInitializer( connector, boltProtocolFactory, throttleGroup, log ) ) ); }
private void validateBoltConnector( Config config ) { if ( config.enabledBoltConnectors().isEmpty() ) { throw new InvalidSettingException( "A Bolt connector must be configured to run a cluster" ); } }
static ClientConnectorAddresses extractFromConfig( Config config ) { List<ConnectorUri> connectorUris = new ArrayList<>(); List<BoltConnector> boltConnectors = config.enabledBoltConnectors(); if ( boltConnectors.isEmpty() ) { throw new IllegalArgumentException( "A Bolt connector must be configured to run a cluster" ); } boltConnectors .forEach( c -> connectorUris.add( new ConnectorUri( bolt, config.get( c.advertised_address ) ) ) ); config.enabledHttpConnectors() .forEach( c -> connectorUris.add( new ConnectorUri( Encryption.NONE.equals(c.encryptionLevel() ) ? http : https, config.get( c.advertised_address ) ) ) ); return new ClientConnectorAddresses( connectorUris ); }
@Override public URI boltURI() { List<BoltConnector> connectors = server.getConfig().enabledBoltConnectors(); BoltConnector defaultConnector = null; BoltConnector firstConnector = null; for ( BoltConnector connector : connectors ) { if ( DEFAULT_BOLT_CONNECTOR_KEY.equals( connector.key() ) ) { defaultConnector = connector; } if ( firstConnector == null ) { firstConnector = connector; } } if ( defaultConnector != null ) { // bolt connector with default key is configured, return its address return connectorUri( "bolt", defaultConnector ); } if ( firstConnector != null ) { // some bolt connector is configured, return its address return connectorUri( "bolt", firstConnector ); } throw new IllegalStateException( "Bolt connector is not configured" ); }
@Override public void start() { forkJoinThreadPool = new ForkJoinPool(); config.enabledBoltConnectors().forEach( connector -> { BoltScheduler boltScheduler = new ExecutorBoltScheduler( connector.key(), executorFactory, scheduler, logService, config.get( connector.thread_pool_min_size ), config.get( connector.thread_pool_max_size ), config.get( connector.thread_pool_keep_alive ), config.get( connector.unsupported_thread_pool_queue_size ), forkJoinThreadPool ); boltScheduler.start(); boltSchedulers.put( connector.key(), boltScheduler ); } ); }
public Builder addBoltConnectorFromConfig( String key, String scheme, Config config, Setting<URI> override, ConnectorPortRegister portRegister ) { // If an override is configured, add it with the HIGHEST precedence if ( config.isConfigured( override ) ) { add( key, config.get( override ), HIGHEST ); } config.enabledBoltConnectors().stream().findFirst().ifPresent( c -> { AdvertisedSocketAddress address = config.get( c.advertised_address ); int port = address.getPort(); if ( port == 0 ) { port = portRegister.getLocalAddress( c.key() ).getPort(); } // If advertised address is explicitly set, set the precedence to HIGH - eitherwise set it as LOWEST (default) add( key, scheme, address.getHostname(), port, config.isConfigured( c.advertised_address ) ? HIGH : LOWEST ); } ); return this; }
@Override public void start() throws Throwable { Log log = logService.getInternalLog( BoltServer.class ); Log userLog = logService.getUserLog( BoltServer.class ); InternalLoggerFactory.setDefaultFactory( new Netty4LoggerFactory( logService.getInternalLogProvider() ) ); Authentication authentication = createAuthentication(); TransportThrottleGroup throttleGroup = new TransportThrottleGroup( config, clock ); BoltSchedulerProvider boltSchedulerProvider = life.add( new ExecutorBoltSchedulerProvider( config, new CachedThreadPoolExecutorFactory( log ), jobScheduler, logService ) ); BoltConnectionFactory boltConnectionFactory = createConnectionFactory( config, boltSchedulerProvider, throttleGroup, logService, clock ); BoltStateMachineFactory boltStateMachineFactory = createBoltFactory( authentication, clock ); BoltProtocolFactory boltProtocolFactory = createBoltProtocolFactory( boltConnectionFactory, boltStateMachineFactory ); if ( !config.enabledBoltConnectors().isEmpty() && !config.get( GraphDatabaseSettings.disconnected ) ) { NettyServer server = new NettyServer( jobScheduler.threadFactory( Group.BOLT_NETWORK_IO ), createConnectors( boltProtocolFactory, throttleGroup, log ), connectorPortRegister, userLog ); life.add( server ); log.info( "Bolt server loaded" ); } life.start(); // init and start the nested lifecycle }