public ZooKeeperClient(ZooKeeperConfigSection configuration) { if (!ValidateHelper.IsPlumpString(configuration.Server)) { throw new ArgumentNullException("zookeeper server can not be empty"); } ConnectionLossTimeout = configuration.SessionTimeOut; var timeOut = TimeSpan.FromMilliseconds(configuration.SessionTimeOut); if (AppContext.IsRegistered <IWatcher>()) { _zookeeper = new ZooKeeper( configuration.Server, timeOut, AppContext.GetObject <IWatcher>()); } else { _zookeeper = new ZooKeeper( configuration.Server, timeOut, new DefaultWatcher()); } }
public ZooKeeperDistributedLock(string key, string configName) { var config = ZooKeeperConfigSection.FromSection(configName); _client = new ZooKeeperClient(config); _path = config.DistributedLockPath + "/" + key.ToMD5(); //抢锁 new Action(() => { _client.CreatePersistentPath(_path); _no = _client.CreateSequential(_path + "/", false); }).InvokeWithRetry(5); }
public ZooKeeperClient(ZooKeeperConfigSection configuration, IWatcher watcher = null) { if (!ValidateHelper.IsPlumpString(configuration.Server)) { throw new ArgumentNullException("zookeeper server can not be empty"); } ConnectionLossTimeout = configuration.SessionTimeOut; var timeOut = TimeSpan.FromMilliseconds(configuration.SessionTimeOut); _zookeeper = new ZooKeeper( configuration.Server, timeOut, watcher ?? new DefaultWatcher()); }
public ZooKeeperClient(string configurationName) : this(ZooKeeperConfigSection.FromSection(configurationName)) { }
public override ZooKeeperClient CreateNewClient(string key) { var config = ZooKeeperConfigSection.FromSection(key); return(new ZooKeeperClient(config)); }