private static void seedNodesViaDnsSrv ( ConnectionString connectionString , CouchbaseEnvironment environment , List < String > seedNodes ) { if ( connectionString . allHosts ( ) . size ( ) == 1 ) { InetSocketAddress lookupNode = connectionString . allHosts ( ) . get ( 0 ) ; LOGGER . debug ( "Attempting to load DNS SRV records from {}." , connectionString . allHosts ( ) . get ( 0 ) ) ; try { List < String > foundNodes = Bootstrap . fromDnsSrv ( lookupNode . getHostName ( ) , false , environment . sslEnabled ( ) ) ; if ( foundNodes . isEmpty ( ) ) { throw new IllegalStateException ( "DNS SRV list is empty." ) ; } seedNodes . addAll ( foundNodes ) ; LOGGER . info ( "Loaded seed nodes from DNS SRV {}." , system ( foundNodes ) ) ; } catch ( Exception ex ) { LOGGER . warn ( "DNS SRV lookup failed, proceeding with normal bootstrap." , ex ) ; seedNodes . add ( ALLOW_HOSTNAMES_AS_SEED_NODES ? lookupNode . getHostName ( ) : lookupNode . getAddress ( ) . getHostAddress ( ) ) ; } } else { LOGGER . info ( "DNS SRV enabled, but less or more than one seed node given. " + "Proceeding with normal bootstrap." ) ; for ( InetSocketAddress node : connectionString . hosts ( ) ) { seedNodes . add ( ALLOW_HOSTNAMES_AS_SEED_NODES ? node . getHostName ( ) : node . getAddress ( ) . getHostAddress ( ) ) ; } } }
Helper method to assemble the list of seed nodes via DNS SRV .