public static ClusterConfigration parseConfiguration ( String line ) { String [ ] lines = line . trim ( ) . split ( "(?:\\r?\\n)" ) ; if ( lines . length < 2 ) { throw new IllegalArgumentException ( "Incorrect config response:" + line ) ; } String configversion = lines [ 0 ] ; String nodeListStr = lines [ 1 ] ; if ( ! ByteUtils . isNumber ( configversion ) ) { throw new IllegalArgumentException ( "Invalid configversion: " + configversion + ", it should be a number." ) ; } String [ ] nodeStrs = nodeListStr . split ( "(?:\\s)+" ) ; int version = Integer . parseInt ( configversion ) ; List < CacheNode > nodeList = new ArrayList < CacheNode > ( nodeStrs . length ) ; for ( String nodeStr : nodeStrs ) { if ( nodeStr . equals ( "" ) ) { continue ; } int firstDelimiter = nodeStr . indexOf ( DELIMITER ) ; int secondDelimiter = nodeStr . lastIndexOf ( DELIMITER ) ; if ( firstDelimiter < 1 || firstDelimiter == secondDelimiter ) { throw new IllegalArgumentException ( "Invalid server ''" + nodeStr + "'' in response: " + line ) ; } String hostName = nodeStr . substring ( 0 , firstDelimiter ) . trim ( ) ; String ipAddress = nodeStr . substring ( firstDelimiter + 1 , secondDelimiter ) . trim ( ) ; String portNum = nodeStr . substring ( secondDelimiter + 1 ) . trim ( ) ; int port = Integer . parseInt ( portNum ) ; nodeList . add ( new CacheNode ( hostName , ipAddress , port ) ) ; } return new ClusterConfigration ( version , nodeList ) ; }
Parse response string to ClusterConfiguration instance .