File confFile = getConfigFile();
Files.write(writer.toString().getBytes(Charsets.UTF_8), confFile);
}
void writeConfig(ClusterSnapshot snapshot, int myid, PrintWriter writer) {
ZookeeperClusterRegistration me = snapshot.servers.get(myid);
if (me == null) {
throw new IllegalStateException();
}
writer.println("peerType=" + me.type);
writer.println("dataDir=" + getDataDir().getAbsolutePath());
writer.println("dataLogDir=" + getLogsDir().getAbsolutePath());
writer.println("syncLimit=2");
writer.println("initLimit=2");
boolean newFormat = false;
if (!newFormat) {
writer.println("clientPort=2181");
}
for (Entry<Integer, ZookeeperClusterRegistration> entry : snapshot.servers.entrySet()) {
int serverId = entry.getKey();
ZookeeperClusterRegistration registration = entry.getValue();
String serverName = "zk_" + serverId;
if (!newFormat) {
writer.println(String.format("server.%s=%s:2182:2183", serverId, serverName));
} else {