private ZooKeeper CreateZooKeeper()

in client/Apache.ShenYu.Client/Utils/Zookeeper/ZookeeperClient.cs [356:381]


        private ZooKeeper CreateZooKeeper()
        {
            //log write to file switch
            ZooKeeper.LogToFile = _options.LogToFile;
            var zkClient = new ZooKeeper(_options.ConnectionString, (int)_options.SessionSpanTimeout.TotalMilliseconds, this, _options.ReadOnly);
            if (!string.IsNullOrEmpty(_options.Digest)) {
                zkClient.addAuthInfo("digest",Encoding.UTF8.GetBytes(_options.Digest));
            }
            var operationStartTime = DateTime.Now;
            while (true)
            {
                if (zkClient.getState() == ZooKeeper.States.CONNECTING)
                {
                    Thread.Sleep(100);
                }else if(zkClient.getState() == ZooKeeper.States.CONNECTED
                    ||zkClient.getState() == ZooKeeper.States.CONNECTEDREADONLY)
                {
                    return zkClient;
                }
                if (DateTime.Now - operationStartTime > _options.OperatingSpanTimeout)
                {
                    throw new TimeoutException(
                        $"connect cannot be retried because of retry timeout ({_options.OperatingSpanTimeout.TotalMilliseconds} milli seconds)");
                }
            }
        }