private void AcquireEventLock()
 {
     try
     {
         EventLock.LockInterruptibly();
     }
     catch (ThreadInterruptedException e)
     {
         throw new ZkInterruptedException(e);
     }
 }
 public long GetCreationTime(String path)
 {
     try
     {
         EventLock.LockInterruptibly();
         return(_connection.GetCreateTime(path));
     }
     catch (KeeperException e)
     {
         throw ZkException.Create(e);
     }
     catch (ThreadInterruptedException e)
     {
         throw new ZkInterruptedException(e);
     }
     finally
     {
         EventLock.Unlock();
     }
 }
        public void Connect(long maxMsToWaitUntilConnected, IWatcher watcher)
        {
            bool started = false;

            try
            {
                EventLock.LockInterruptibly();
                ShutdownTrigger = false;
                _eventThread    = new ZkEventThread(_connection.Servers);
                _eventThread.Start();
                _connection.Connect(watcher);

                Logger.Debug("Awaiting connection to Zookeeper server");
                if (!WaitUntilConnected(TimeSpan.FromMilliseconds(maxMsToWaitUntilConnected)))
                {
                    throw new ZkTimeoutException("Unable to connect to zookeeper server within timeout: " + maxMsToWaitUntilConnected);
                }

                started = true;
            }
            catch (ThreadInterruptedException)
            {
                ZooKeeper.States state = _connection.ZookeeperState;
                throw new Exception("Not connected with zookeeper server yet. Current state is " + state);
            }
            finally
            {
                EventLock.Unlock();

                // we should close the zookeeper instance, otherwise it would keep
                // on trying to connect
                if (!started)
                {
                    this.Dispose();
                }
            }
        }