private void registerHttpsAddressAfterStartup() { if ( httpsConnector != null ) { InetSocketAddress localHttpsAddress = webServer.getLocalHttpsAddress(); connectorPortRegister.register( httpsConnector.key(), localHttpsAddress ); if ( httpsAdvertisedAddress.getPort() == 0 ) { httpsAdvertisedAddress = new AdvertisedSocketAddress( localHttpsAddress.getHostString(), localHttpsAddress.getPort() ); } } }
public URI buildURI( AdvertisedSocketAddress address, boolean isSsl ) { StringBuilder sb = new StringBuilder(); sb.append( "http" ); if ( isSsl ) { sb.append( "s" ); } sb.append( "://" ); sb.append( address.getHostname() ); int port = address.getPort(); if ( port != 80 && port != 443 ) { sb.append( ":" ); sb.append( port ); } sb.append( "/" ); try { return new URI( sb.toString() ); } catch ( URISyntaxException e ) { throw new RuntimeException( e ); } }
/** * Textual representation format for an advertised socket address. * @param hostname of the address. * @param port of the address. * @return a string representing the address. */ public static String advertisedAddress( String hostname, int port ) { return new AdvertisedSocketAddress( hostname, port ).toString(); } }
AdvertisedSocketAddress resolveCorrectCCAddress( Config config, OptionalHostnamePort userProvidedAddress ) { AdvertisedSocketAddress defaultValue = readDefaultConfigAddressCC( config ); return new AdvertisedSocketAddress( userProvidedAddress.getHostname().orElse( defaultValue.getHostname() ), userProvidedAddress.getPort().orElse( defaultValue.getPort() ) ); }
@Override public Collection<AdvertisedSocketAddress> resolve( AdvertisedSocketAddress initialAddress ) { try { Set<AdvertisedSocketAddress> addresses = srvRecordResolver .resolveSrvRecord( initialAddress.getHostname() ) .map( srvRecord -> new AdvertisedSocketAddress( srvRecord.host, srvRecord.port ) ) .collect( Collectors.toSet() ); userLog.info( "Resolved initial host '%s' to %s", initialAddress, addresses ); if ( addresses.isEmpty() ) { log.error( "Failed to resolve srv records for '%s'", initialAddress.getHostname() ); } return addresses; } catch ( NamingException e ) { log.error( "Failed to resolve srv records for '%s'", initialAddress.getHostname(), e ); return Collections.emptySet(); } } }
private static AdvertisedSocketAddress parseAddress( String address ) { String[] split = address.split( ":" ); return new AdvertisedSocketAddress( split[0], Integer.valueOf( split[1] ) ); } }
public String address() { return address.toString(); }
@Override public void connect() throws Exception { ChannelFuture channelFuture = bootstrap.connect( destination.socketAddress() ); nettyChannel = channelFuture.sync().channel(); nettyChannel.closeFuture().addListener( (ChannelFutureListener) future -> handler.onClose() ); }
private static Consumer<Config> overrideWithListenAddress( String host, int port ) { return config -> config.augment( new BoltConnector( "bolt" ).listen_address.name(), AdvertisedSocketAddress.advertisedAddress( host, port ) ); }
@Override public Collection<AdvertisedSocketAddress> resolve( AdvertisedSocketAddress initialAddress ) { Set<AdvertisedSocketAddress> addresses = new HashSet<>(); InetAddress[] ipAddresses = new InetAddress[0]; try { ipAddresses = domainNameResolver.resolveDomainName( initialAddress.getHostname() ); } catch ( UnknownHostException e ) { log.error( format("Failed to resolve host '%s'", initialAddress.getHostname()), e); } for ( InetAddress ipAddress : ipAddresses ) { addresses.add( new AdvertisedSocketAddress( ipAddress.getHostAddress(), initialAddress.getPort() ) ); } userLog.info( "Resolved initial host '%s' to %s", initialAddress, addresses ); return addresses; } }
new AdvertisedSocketAddress( boltAddress.getHost(), boltAddress.getPort() ); try
static Object[] build( MultiClusterRoutingResult result ) { Function<List<Endpoint>, Object[]> stringifyAddresses = es -> es.stream().map( e -> e.address().toString() ).toArray(); List<Map<String,Object>> response = result.routers().entrySet().stream().map( entry -> { String dbName = entry.getKey(); Object[] addresses = stringifyAddresses.apply( entry.getValue() ); Map<String,Object> responseRow = new TreeMap<>(); responseRow.put( DB_NAME_KEY, dbName ); responseRow.put( ADDRESSES_KEY, addresses ); return responseRow; } ).collect( Collectors.toList() ); long ttlSeconds = MILLISECONDS.toSeconds( result.ttlMillis() ); return new Object[]{ttlSeconds, response}; }
CatchUpChannel( AdvertisedSocketAddress destination ) { this.destination = destination; handler = new TrackingResponseHandler( new CatchUpResponseAdaptor(), clock ); Bootstrap bootstrap = new Bootstrap() .group( eventLoopGroup ) .channel( NioSocketChannel.class ) .handler( new ChannelInitializer<SocketChannel>() { @Override protected void initChannel( SocketChannel ch ) throws Exception { CatchUpClientChannelPipeline.initChannel( ch, handler, logProvider, monitors ); } } ); ChannelFuture channelFuture = bootstrap.connect( destination.socketAddress() ); nettyChannel = channelFuture.awaitUninterruptibly().channel(); }
private static Consumer<Config> overrideWithAdvertisedAddress( String host, int port ) { return config -> config.augment( new BoltConnector( "bolt" ).advertised_address.name(), AdvertisedSocketAddress.advertisedAddress( host, port ) ); }
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; }
private void registerHttpAddressAfterStartup() { if ( httpConnector != null ) { InetSocketAddress localHttpAddress = webServer.getLocalHttpAddress(); connectorPortRegister.register( httpConnector.key(), localHttpAddress ); if ( httpAdvertisedAddress.getPort() == 0 ) { httpAdvertisedAddress = new AdvertisedSocketAddress( localHttpAddress.getHostString(), localHttpAddress.getPort() ); } } }
@Override public void userEventTriggered( ChannelHandlerContext ctx, Object evt ) { if ( evt instanceof IdleStateEvent && evt == IdleStateEvent.ALL_IDLE_STATE_EVENT ) { final InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); final AdvertisedSocketAddress address = new AdvertisedSocketAddress( socketAddress.getHostName(), socketAddress.getPort() ); channels.remove( address ); } } }
/** * Textual representation format for an advertised socket address. * @param hostname of the address. * @param port of the address. * @return a string representing the address. */ public static String advertisedAddress( String hostname, int port ) { return new AdvertisedSocketAddress( hostname, port ).toString(); } }
static MemberAttributeConfig buildMemberAttributes( MemberId myself, Config config ) { MemberAttributeConfig memberAttributeConfig = new MemberAttributeConfig(); memberAttributeConfig.setStringAttribute( MEMBER_UUID, myself.getUuid().toString() ); AdvertisedSocketAddress discoveryAddress = config.get( CoreEdgeClusterSettings.discovery_advertised_address ); memberAttributeConfig.setStringAttribute( DISCOVERY_SERVER, discoveryAddress.toString() ); AdvertisedSocketAddress transactionSource = config.get( CoreEdgeClusterSettings.transaction_advertised_address ); memberAttributeConfig.setStringAttribute( TRANSACTION_SERVER, transactionSource.toString() ); AdvertisedSocketAddress raftAddress = config.get( CoreEdgeClusterSettings.raft_advertised_address ); memberAttributeConfig.setStringAttribute( RAFT_SERVER, raftAddress.toString() ); ClientConnectorAddresses clientConnectorAddresses = ClientConnectorAddresses.extractFromConfig( config ); memberAttributeConfig.setStringAttribute( CLIENT_CONNECTOR_ADDRESSES, clientConnectorAddresses.toString() ); return memberAttributeConfig; }
private NonBlockingChannel channel( AdvertisedSocketAddress to ) { MessageQueueMonitor monitor = monitors.newMonitor( MessageQueueMonitor.class, NonBlockingChannel.class ); NonBlockingChannel nonBlockingChannel = nonBlockingChannels.get( to ); if ( nonBlockingChannel == null ) { nonBlockingChannel = new NonBlockingChannel( bootstrap, to.socketAddress(), log, monitor, maxQueueSize ) ; NonBlockingChannel existingNonBlockingChannel = nonBlockingChannels.putIfAbsent( to, nonBlockingChannel ); if ( existingNonBlockingChannel != null ) { nonBlockingChannel.dispose(); nonBlockingChannel = existingNonBlockingChannel; } } monitor.register( to.socketAddress() ); return nonBlockingChannel; }