Created
September 26, 2012 10:26
-
-
Save Arbow/3787229 to your computer and use it in GitHub Desktop.
Start zookeeper cluster from program
This file contains hidden or 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
private static void startClusterServer(String name, int id, int port) { | |
String dataDir = "./zk/" + name; | |
File dataDirectory = new File(dataDir); | |
if (!dataDirectory.exists()) | |
dataDirectory.mkdirs(); | |
File myIdFile = new File(dataDirectory, "myid"); | |
if (!myIdFile.exists()) { | |
IO.write(String.valueOf(id).getBytes(), myIdFile); | |
} | |
Properties prop = new Properties(); | |
prop.put("tickTime", 2000); | |
prop.put("initLimit", 10); | |
prop.put("syncLimit", 5); | |
prop.put("dataDir", dataDir); | |
prop.put("dataLogDir", dataDir); | |
prop.put("clientPort", port); | |
prop.put("server.1", "localhost:2888:3888"); | |
prop.put("server.2", "localhost:2889:3889"); | |
try { | |
QuorumPeerConfig config = new QuorumPeerConfig(); | |
config.parseProperties(prop); | |
QuorumPeerMain main = new QuorumPeerMain(); | |
main.runFromConfig(config); | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment