private void ConnectZk()
        {
            Logger.Info("Enter connectZk()");
            if (UseSharedStaticZookeeperClient)
            {
                Logger.Info("After check  UseSharedStaticZookeeperClient");
                if (zkClientStatic == null || (zkClientStatic != null && zkClientStatic.GetClientState() != ZooKeeperNet.KeeperState.SyncConnected))
                {
                    Logger.Info("After check  UseSharedStaticZookeeperClient, will lock");
                    lock (zkClientStaticLock)
                    {
                        Logger.Info("got lock ... ");
                        if (zkClientStatic == null || (zkClientStatic != null && zkClientStatic.GetClientState() != ZooKeeperNet.KeeperState.SyncConnected))
                        {
                            Logger.InfoFormat("zkClientStatic: {0}   will create one ...", zkClientStatic == null ? "null" : "not null");
                            Logger.InfoFormat("Connecting to zookeeper instance at {0}  STATIC", this.config.ZooKeeper.ZkConnect);
                            zkClientStatic = new ZooKeeperClient(this.config.ZooKeeper.ZkConnect, this.config.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer, this.config.ZooKeeper.ZkConnectionTimeoutMs);
                            zkClientStatic.Connect();
                            Logger.InfoFormat("Connecting to zookeeper instance at {0}  STATIC. Done", this.config.ZooKeeper.ZkConnect);
                        }

                        Logger.Info("release lock ... ");
                    }
                }

                Logger.InfoFormat("zkClientStatic: {0}", zkClientStatic == null ? "null" : "not null");
                if (zkClientStatic != null)
                {
                    Logger.InfoFormat("zkClientStatic.ClientState: {0}", zkClientStatic.GetClientState());
                }
            }
            else
            {
                Logger.InfoFormat("Connecting to zookeeper instance at {0}", this.config.ZooKeeper.ZkConnect);
                if (this.zkClientInternal != null)
                {
                    this.zkClientInternal.Dispose();
                    this.zkClientInternal = null;
                }
                this.zkClientInternal = new ZooKeeperClient(this.config.ZooKeeper.ZkConnect, this.config.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer, this.config.ZooKeeper.ZkConnectionTimeoutMs);
                this.zkClientInternal.Connect();
            }
        }
Example #2
0
 public async Task StartAsync(CancellationToken cancellationToken) =>
 await _zookeeperClient.Connect();