Example #1
0
        public ZKLock(ZKConfig config)
        {
            this.config = config;

            var tcs = new TaskCompletionSource <bool>();

            lock (lockObj)
            {
                if (zooKeeper == null)
                {
                    zooKeeper = new ZK.ZooKeeper(
                        this.config.ConnectionString,
                        this.config.SessionTimeout,
                        new WaitWatcher(string.Empty, tcs, e => e.getState() == KeeperState.SyncConnected));
                }
            }
            zooKeeper.Connect().Wait();
            if (zooKeeper.getState() != ZK.ZooKeeper.States.CONNECTED &&
                zooKeeper.getState() != ZK.ZooKeeper.States.CONNECTEDREADONLY)
            {
                throw new Exception("ZooKeeper Connected Failed");
            }
            CreatNodeIfNotExist(config.LockPath).Wait();

            Console.WriteLine($"{this.config.Name} Constructed");
        }
        public IFeatureFlag GetFeature(string featureKey)
        {
            var state = zooKeeper.getState();

            if ((state == Z.ZooKeeper.States.CONNECTING || state == Z.ZooKeeper.States.CONNECTED ||
                 state == Z.ZooKeeper.States.CONNECTEDREADONLY) && !localView.ContainsKey(featureKey))
            {
                SetupKey(featureKey).Wait(setupTimeout);
            }
            return(new DynamicFeatureFlag(featureKey, this));
        }
Example #3
0
 public static async Task Connect(this ZK.ZooKeeper zooKeeper)
 {
     while (zooKeeper.getState() == ZK.ZooKeeper.States.CONNECTING)
     {
         await Task.Delay(15);
     }
 }
Example #4
0
        public async Task <org.apache.zookeeper.ZooKeeper> Get(String connStr)
        {
            org.apache.zookeeper.ZooKeeper zk = null;
            bool isExists = MappedZooKeepers.ContainsKey(connStr);

            if (isExists)
            {
                zk = MappedZooKeepers[connStr];
                var zkState = zk.getState();
                if (zkState == org.apache.zookeeper.ZooKeeper.States.CLOSED
                    ||
                    zkState == org.apache.zookeeper.ZooKeeper.States.NOT_CONNECTED
                    )
                {
                    await Remove(connStr);

                    zk = new org.apache.zookeeper.ZooKeeper(connStr, SESSION_TIMEOUT, NoneWatcher.Instance);
                    MappedZooKeepers.Add(connStr, zk);
                }
                return(zk);
            }
            zk = new org.apache.zookeeper.ZooKeeper(connStr, SESSION_TIMEOUT, NoneWatcher.Instance);
            MappedZooKeepers.Add(connStr, zk);
            return(zk);
        }
 private void WaitConnect(org.apache.zookeeper.ZooKeeper zk)
 {
     while (zk.getState() != org.apache.zookeeper.ZooKeeper.States.CONNECTED)
     {
     }
 }
Example #6
0
 public org.apache.zookeeper.ZooKeeper.States GetZookeeperState()
 {
     return(_zooKeeper.getState());
 }