use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerConfig in project xian by happyyangyuan.
the class QuorumConfigBuilder method buildConfig.
public QuorumPeerConfig buildConfig(int instanceIndex) throws Exception {
boolean isCluster = (instanceSpecs.size() > 1);
InstanceSpec spec = instanceSpecs.get(instanceIndex);
if (isCluster) {
Files.write(Integer.toString(spec.getServerId()).getBytes(), new File(spec.getDataDirectory(), "myid"));
}
Properties properties = new Properties();
properties.setProperty("initLimit", "10");
properties.setProperty("syncLimit", "5");
properties.setProperty("dataDir", spec.getDataDirectory().getCanonicalPath());
properties.setProperty("clientPort", Integer.toString(spec.getPort()));
int tickTime = spec.getTickTime();
if (tickTime >= 0) {
properties.setProperty("tickTime", Integer.toString(tickTime));
}
int maxClientCnxns = spec.getMaxClientCnxns();
if (maxClientCnxns >= 0) {
properties.setProperty("maxClientCnxns", Integer.toString(maxClientCnxns));
}
if (isCluster) {
for (InstanceSpec thisSpec : instanceSpecs) {
properties.setProperty("server." + thisSpec.getServerId(), String.format("%s:%d:%d", thisSpec.getHostname(), thisSpec.getQuorumPort(), thisSpec.getElectionPort()));
}
}
Map<String, Object> customProperties = spec.getCustomProperties();
if (customProperties != null) {
for (Map.Entry<String, Object> property : customProperties.entrySet()) {
properties.put(property.getKey(), property.getValue());
}
}
QuorumPeerConfig config = new QuorumPeerConfig();
config.parseProperties(properties);
return config;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerConfig in project xian by happyyangyuan.
the class TestingZooKeeperServer method start.
public void start() throws Exception {
if (!state.compareAndSet(State.LATENT, State.STARTED)) {
return;
}
new Thread(new Runnable() {
public void run() {
try {
QuorumPeerConfig config = configBuilder.buildConfig(thisInstanceIndex);
main.runFromConfig(config);
} catch (Exception e) {
logger.error(String.format("From testing server (random state: %s) for instance: %s", String.valueOf(configBuilder.isFromRandom()), getInstanceSpec()), e);
}
}
}).start();
main.blockUntilStarted();
}
Aggregations