int brokerId = this.config.getBrokerId();
int slaveId = this.config.getSlaveId();
final String brokerTopicPath = this.metaZookeeper.brokerTopicsPathOf(topic, brokerId, slaveId);
final String topicPubPath = this.metaZookeeper.brokerTopicsPathOf(topic, true, brokerId, slaveId);
final String topicSubPath = this.metaZookeeper.brokerTopicsPathOf(topic, false, brokerId, slaveId);
final TopicConfig topicConfig = this.config.getTopicConfig(topic);
Integer numParts = topicConfig != null ? topicConfig.getNumPartitions() : this.config.getNumPartitions();
numParts = numParts == null ? this.config.getNumPartitions() : numParts;
log.info("Begin registering broker topic " + brokerTopicPath + " with " + numParts + " partitions");
final TopicBroker topicBroker = new TopicBroker(numParts, brokerId + (slaveId >= 0 ? "-s" + slaveId : "-m"));
log.info("Register broker for topic:" + topicBroker);
// Be compatible with the version before 1.4.3
ZkUtils.createEphemeralPath(this.zkClient, brokerTopicPath, String.valueOf(numParts));
// added by dennis,since 1.4.3
String topicBrokerJson = topicBroker.toJson();
if (topicConfig.isAcceptPublish()) {
ZkUtils.createEphemeralPath(this.zkClient, topicPubPath, topicBrokerJson);
}
else {
ZkUtils.deletePath(this.zkClient, topicPubPath);
}
if (topicConfig.isAcceptSubscribe()) {
ZkUtils.createEphemeralPath(this.zkClient, topicSubPath, topicBrokerJson);
}
else {
ZkUtils.deletePath(this.zkClient, topicSubPath);
}
this.cloneTopicConfigs.put(topic, topicConfig.clone());
log.info("End registering broker topic " + brokerTopicPath);
}