/// <summary>
        /// Called when the children of the given path changed
        /// </summary>
        /// <param name="e">The <see cref="Kafka.Client.ZooKeeperIntegration.Events.ZooKeeperChildChangedEventArgs"/> instance containing the event data
        /// as parent path and children (null if parent was deleted).
        /// </param>
        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;
                    IEnumerable <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;
                            IEnumerable <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);
                }
            }
        }
        /// <summary>
        /// Invokes subscribed handlers for ZooKeeeper child changes event
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void OnChildChanged(ZooKeeperChildChangedEventArgs e)
        {
            ChildChangedEventItem handlers;

            this.childChangedHandlers.TryGetValue(e.Path, out handlers);
            if (handlers == null || handlers.Count == 0)
            {
                return;
            }

            this.Exists(e.Path);
            try
            {
                IEnumerable <string> children = this.GetChildren(e.Path);
                e.Children = children;
            }
            catch (KeeperException ex)// KeeperException.NoNodeException)
            {
                if (ex.ErrorCode == KeeperException.Code.NONODE)
                {
                }
                else
                {
                    throw;
                }
            }

            handlers.OnChildChanged(e);
        }
コード例 #3
0
 /// <summary>
 /// Called when the children of the given path changed
 /// </summary>
 /// <param name="args">The <see cref="Kafka.Client.ZooKeeperIntegration.Events.ZooKeeperChildChangedEventArgs"/> instance containing the event data
 /// as parent path and children (null if parent was deleted).
 /// </param>
 /// <remarks>
 /// http://zookeeper.wiki.sourceforge.net/ZooKeeperWatches
 /// </remarks>
 public void HandleChildChange(ZooKeeperChildChangedEventArgs args)
 {
     Guard.NotNull(args, "args");
     Guard.NotNullNorEmpty(args.Path, "args.Path");
     Guard.NotNull(args.Children, "args.Children");
     SyncedRebalance();
 }
コード例 #4
0
 /// <summary>
 /// Called when the children of the given path changed
 /// </summary>
 /// <param name="args">The <see cref="Kafka.Client.ZooKeeperIntegration.Events.ZooKeeperChildChangedEventArgs"/> instance containing the event data
 /// as parent path and children (null if parent was deleted).
 /// </param>
 /// <remarks>
 /// http://zookeeper.wiki.sourceforge.net/ZooKeeperWatches
 /// </remarks>
 public void HandleChildChange(ZooKeeperChildChangedEventArgs args)
 {
     Guard.NotNull(args, "args");
     Guard.NotNullNorEmpty(args.Path, "args.Path");
     Guard.NotNull(args.Children, "args.Children");
     Logger.Info("Performing rebalancing. Consumers have been added or removed from the consumer group: " + args.Path);
     AsyncRebalance();
 }
コード例 #5
0
        /// <summary>
        /// Invokes subscribed handlers for ZooKeeeper child changes event
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void OnChildChanged(ZooKeeperChildChangedEventArgs e)
        {
            ChildChangedEventItem handlers;

            this.childChangedHandlers.TryGetValue(e.Path, out handlers);
            if (handlers == null || handlers.Count == 0)
            {
                return;
            }

            this.Exists(e.Path);
            try
            {
                IList <string> children = this.GetChildren(e.Path);
                e.Children = children;
            }
            catch (KeeperException.NoNodeException)
            {
            }

            handlers.OnChildChanged(e);
        }
コード例 #6
0
 public void HandleChildChange(ZooKeeperChildChangedEventArgs args)
 {
     Logger.Debug(args + " reach test event handler");
     this.events.Add(args);
 }