Example #1
0
        public async Task <bool> StartSessionAsync(TimeSpan sessionTimeout, TimeSpan connectTimeout,
                                                   CancellationToken token)
        {
            this.token = token;
            Stopwatch sw = new();

            sw.Start();

            if (zookeeper != null)
            {
                await zookeeper.closeAsync();
            }

            zookeeper = new org.apache.zookeeper.ZooKeeper(
                zookeeperHosts,
                (int)sessionTimeout.TotalMilliseconds,
                this);

            while (keeperState != Event.KeeperState.SyncConnected && sw.Elapsed <= connectTimeout)
            {
                await Task.Delay(50);
            }

            bool connected = keeperState == Event.KeeperState.SyncConnected;

            sessionExpired = !connected;

            return(connected);
        }
Example #2
0
        public async Task DeleteValue(string path)
        {
            var zk = new org.apache.zookeeper.ZooKeeper("127.0.0.1:2181", 60000, null);
            await zk.deleteAsync(path);

            await zk.closeAsync();
        }
Example #3
0
        public async Task ChangeValue(string path, string value)
        {
            var zk = new org.apache.zookeeper.ZooKeeper("127.0.0.1:2181", 60000, null);
            await zk.setDataAsync(path, Encoding.UTF8.GetBytes(value));

            await zk.closeAsync();
        }
Example #4
0
 public async Task CloseAsync()
 {
     if (zookeeper != null)
     {
         await zookeeper.closeAsync();
     }
 }
Example #5
0
        public async Task AddValue(string path, string value)
        {
            var zk = new org.apache.zookeeper.ZooKeeper("127.0.0.1:2181", 60000, null);
            await zk.createAsync(path, Encoding.UTF8.GetBytes(value), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                                 CreateMode.PERSISTENT);

            await zk.closeAsync();
        }
Example #6
0
        public async Task Setup()
        {
            StartZooKeeper();
            var zk = new org.apache.zookeeper.ZooKeeper("127.0.0.1:2181", 100000, null);

            await DeleteRecursive(zk, "/FeatureFlags", "features");
            await CreateIfNotExist(zk, "/FeatureFlags/features/featureA", "true");
            await CreateIfNotExist(zk, "/FeatureFlags/features/featureB", "false");
            await CreateIfNotExist(zk, "/FeatureFlags/features/featureC", "true");
            await CreateIfNotExist(zk, "/FeatureFlags/features/featureD", "true");

            await zk.closeAsync();

            dynamicFeatureStore = new ZooKeeperFeatureStore("127.0.0.1:2181/FeatureFlags");
            featureStore        = new CachingFeatureStore(dynamicFeatureStore);
        }
Example #7
0
        public void Close()
        {
            lock (_connectLock)
            {
                if (_zooKeeper == null)
                {
                    return;
                }
                this.LogInfo($"Closing ZooKeeper connected to {this._address}");


                Task.Run(async() =>
                {
                    await _zooKeeper.closeAsync().ConfigureAwait(false);
                }).ConfigureAwait(false).GetAwaiter().GetResult();

                _zooKeeper = null;
            }
        }