public void HandleDataChange(Events.ZooKeeperDataChangedEventArgs args)
        {
            int    parsedLeader;
            string nodePath = args.Path;
            string nodeData = args.Data;

            Logger.Info("A partition leader or ISR list has been updated. Determining if rebalancing is necessary");
            if (!ZkUtils.TryParsePartitionLeader(nodeData, out parsedLeader))
            {
                Logger.Error("Skipping rebalancing. Failed to parse partition leader for path: " + nodePath + " from ZK node");
                return;
            }
            else
            {
                if (!_partitionLeaderMap.ContainsKey(nodePath) || _partitionLeaderMap[nodePath] != parsedLeader)
                {
                    string currentLeader = _partitionLeaderMap.ContainsKey(nodePath) ? _partitionLeaderMap[nodePath].ToString() : "null";
                    Logger.Info("Performing rebalancing. Leader value for path: " + nodePath + " has changed from " + currentLeader + " to " + parsedLeader);
                    _partitionLeaderMap[nodePath] = parsedLeader;
                    _rebalancer.AsyncRebalance();
                }
                else
                {
                    Logger.Info("Skipping rebalancing. Leader value for path: " + nodePath + " is " + parsedLeader.ToString() + " and has not changed");
                }
            }
        }
        /// <summary>
        ///     Called when the ZooKeeper connection state has changed.
        /// </summary>
        /// <param name="args">
        ///     The <see cref="Kafka.Client.ZooKeeperIntegration.Events.ZooKeeperStateChangedEventArgs" /> instance
        ///     containing the event data.
        /// </param>
        /// <remarks>
        ///     Do nothing, since zkclient will do reconnect for us.
        /// </remarks>
        public void HandleStateChanged(ZooKeeperStateChangedEventArgs args)
        {
            Guard.NotNull(args, "args");
            Guard.Assert <ArgumentException>(() => args.State != KeeperState.Unknown);

            if (args.State != KeeperState.Disconnected)
            {
                Logger.Info("ZK session disconnected; shutting down fetchers and resetting state");

                // Shutdown fetcher threads until we reconnect
                loadBalancerListener.ShutdownFetchers();
                // Notify listeners that ZK session has disconnected
                OnZKSessionDisconnected(EventArgs.Empty);
            }
            else if (args.State == KeeperState.SyncConnected)
            {
                Logger.Info("Performing rebalancing. ZK session has reconnected");

                // Restart fetcher threads via rebalance in case we no longer own a partition
                loadBalancerListener.AsyncRebalance();
            }
        }