Ejemplo n.º 1
0
        //public ZookeeperLockProvider(ZooKeeper zkClient)
        //{
        //    _zkClient = zkClient;
        //}

        //public ZookeeperLockProvider(string connectString, int sessionTimeout)
        //{
        //    _zkClient = new ZooKeeper(connectString, sessionTimeout, null);
        //}

        public IDistributedLock CreateMutexLock(string name)
        {
            var path  = ZKPaths.MakePath(BASE_LOCK_PATH, name);
            var mlock = new ZookeeperMutexLock(_zkClient, path, _options.DefaultLockTimeout);

            return(mlock);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// zk信号量
        /// </summary>
        /// <param name="zkClient"></param>
        /// <param name="path"></param>
        /// <param name="maxLeases"></param>
        public ZookeeperSemaphore(ZooKeeper zkClient, string path, int maxLeases, int lockTimeout)
        {
            ZKPaths.ValidatePath(path);

            _zkClient       = zkClient;
            _maxLeases      = maxLeases;
            _lockTimeout    = lockTimeout;
            _lock           = new ZookeeperMutexLock(zkClient, ZKPaths.MakePath(path, LOCK_PARENT), lockTimeout);
            _leasesPath     = ZKPaths.MakePath(path, LEASE_PARENT);
            _acquiredLeases = new List <string>(maxLeases);

            _signal  = new SemaphoreSlim(0);
            _watcher = new ReleaseLockWatcher(_signal);
        }
Ejemplo n.º 3
0
        public ZookeeperReadWriteLock(ZooKeeper zkClient, string path, int lockTimeout)
        {
            _writeMutex = new ZookeeperMutexLock
                          (
                zkClient,
                path,
                WRITE_LOCK_NAME,
                1,
                new WriteLockInternalsDriver(),
                lockTimeout
                          );

            _readMutex = new ZookeeperMutexLock
                         (
                zkClient,
                path,
                READ_LOCK_NAME,
                int.MaxValue,
                new ReadLockInternalsDriver(_writeMutex),
                lockTimeout
                         );
        }
Ejemplo n.º 4
0
 public ReadLockInternalsDriver(ZookeeperMutexLock writeLock)
 {
     _writeLock = writeLock;
 }