public void HandleChildChange(ZooKeeperChildChangedEventArgs e)
{
Guard.NotNull(e, "e");
Guard.NotNullNorEmpty(e.Path, "e.Path");
Guard.NotNull(e.Children, "e.Children");
lock (this.syncLock)
{
try
{
string path = e.Path;
IList<string> childs = e.Children;
Logger.Debug("Watcher fired for path: " + path);
switch (path)
{
case ZooKeeperClient.DefaultBrokerTopicsPath:
List<string> oldTopics = this.oldBrokerTopicsPartitionsMap.Keys.ToList();
List<string> newTopics = childs.Except(oldTopics).ToList();
Logger.Debug("List of topics was changed at " + e.Path);
Logger.Debug("Current topics -> " + e.Children.ToMultiString(","));
Logger.Debug("Old list of topics -> " + oldTopics.ToMultiString(","));
Logger.Debug("List of newly registered topics -> " + newTopics.ToMultiString(","));
foreach (var newTopic in newTopics)
{
string brokerTopicPath = ZooKeeperClient.DefaultBrokerTopicsPath + "/" + newTopic;
IList<string> brokerList = this.zkclient.GetChildrenParentMayNotExist(brokerTopicPath);
this.ProcessNewBrokerInExistingTopic(newTopic, brokerList);
this.zkclient.Subscribe(ZooKeeperClient.DefaultBrokerTopicsPath + "/" + newTopic, this);
}
break;
case ZooKeeperClient.DefaultBrokerIdsPath:
Logger.Debug("List of brokers changed in the Kafka cluster " + e.Path);
Logger.Debug("Currently registered list of brokers -> " + e.Children.ToMultiString(","));
this.ProcessBrokerChange(path, childs);
break;
default:
string[] parts = path.Split('/');
string topic = parts.Last();
if (parts.Length == 4 && parts[2] == "topics" && childs != null)
{
Logger.Debug("List of brokers changed at " + path);
Logger.Debug(
"Currently registered list of brokers for topic " + topic + " -> " +
childs.ToMultiString(","));
this.ProcessNewBrokerInExistingTopic(topic, childs);
}
break;
}
this.oldBrokerTopicsPartitionsMap = this.actualBrokerTopicsPartitionsMap;
this.oldBrokerIdMap = this.actualBrokerIdMap;
}
catch (Exception exc)
{
Logger.Debug("Error while handling " + e, exc);
}
}
}