Ejemplo n.º 1
0
 private static ZooKeeper CreateClient(ZkOption option)
 {
     if (_option == null)
     {
         throw new Exception("it is not initial");
     }
     _option = option;
     return(option.SessionId == long.MinValue
         ? new ZooKeeper(option.ConnectionsString, option.SessionTimeout, ZkWatcher.Default, option.CanBeReadOnly)
         : new ZooKeeper(option.ConnectionsString, option.SessionTimeout, ZkWatcher.Default, option.SessionId,
                         option.SessionPassword, option.CanBeReadOnly));
 }
Ejemplo n.º 2
0
 public static void Configure(ZkOption option)
 {
     lock (_lockObj)
     {
         if (Client == null)
         {
             _option = option;
             Client  = CreateClient(option);
             Client.existsAsync("/locks").Wait();
         }
     }
 }
Ejemplo n.º 3
0
 public ZkLocker(string lockName, ZkOption option, int lockTimeout = 5000)
 {
     _client = option.SessionId == long.MinValue
         ? new ZooKeeper(option.ConnectionsString, option.SessionTimeout, this, option.CanBeReadOnly)
         : new ZooKeeper(option.ConnectionsString, option.SessionTimeout, this, option.SessionId,
                         option.SessionPassword, option.CanBeReadOnly);
     if (_client.existsAsync("/locks").Result == null)
     {
         _client.createAsync("/locks", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT).Wait();
     }
     if (_client.existsAsync("/locks/" + lockName).Result == null)
     {
         _client.createAsync("/locks/" + lockName, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT).Wait();
     }
     _lockName    = lockName;
     _lockTimeout = lockTimeout;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 全局默认锁defaultLock
 /// </summary>
 /// <param name="option">配置选项</param>
 /// <param name="lockTimeout">设置锁超时时间</param>
 public ZkLocker(ZkOption option, int lockTimeout) : this("defaultLock", option, lockTimeout)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 全局默认锁defaultLock
 /// </summary>
 /// <param name="option">配置选项</param>
 public ZkLocker(ZkOption option) : this("defaultLock", option)
 {
 }