Last active
December 13, 2015 21:59
-
-
Save ericacm/4981652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* hosts(i) corresponds to serversKey(i) and serversVal(i) | |
* | |
* hosts are "hostname:port" (same as cluster nodeId). | |
* Note: port is the server's client port. port+1 and port+2 are used for serversVal. | |
* | |
* serversKey are "server.1" (see Zookeeper Admin Guide) | |
* serversVal are "hostname:nnnn:nnnn" | |
*/ | |
case class ServerNames(hosts: IndexedSeq[String], | |
serversKey: IndexedSeq[String], serversVal: IndexedSeq[String]) { | |
def useReplicated = hosts.size > 1 | |
} | |
def genServerNames(hosts: String): ServerNames = { | |
val hostsArr = hosts.split(",") | |
val serversKeyArr = new Array[String](hostsArr.length) | |
val serversValArr = new Array[String](hostsArr.length) | |
for ((server, idx) <- hostsArr.zipWithIndex) { | |
val (host, port) = if (server.contains(":")) { | |
val parts = server.split(":") | |
(parts(0), parts(1).toInt) | |
} else { | |
(server, clientPort) | |
} | |
hostsArr(idx) = host + ":" + port | |
serversKeyArr(idx) = "server." + (idx+1) | |
serversValArr(idx) = host + ":" + (port+1) + ":" + (port+2) | |
} | |
ServerNames(hostsArr.toIndexedSeq, | |
serversKeyArr.toIndexedSeq, serversValArr.toIndexedSeq) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment