コード例 #1
0
        /// <summary>
        /// 连接到服务器(线程安全)
        /// </summary>
        private void Connect()
        {
            _logger.Info("Connect to zookeeper server");
            var newConnection = new ZooKeeperNet.ZooKeeper(_connectionString, TimeSpan.FromMilliseconds(_sessionTimeoutMs), this);

            if (_connection.CompareAndSet(null, newConnection) == false)
            {
                newConnection.Dispose();
            }

            if (this.WaitUntilConnected() == false)
            {
                this.Dispose();
                _logger.Error("Unable to connect to zookeeper server within timout: " + _connectTimeoutMs);
                throw new Exception("Unable to connect to zookeeper server within timout: " + _connectTimeoutMs);
            }
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: lazy111/test
        public static void StartConfig()
        {
            ZooKeeperNet.ZooKeeper zk = new ZooKeeperNet.ZooKeeper("127.0.0.1:2181", new TimeSpan(1, 0, 0), new Watch());

            zk.AddAuthInfo(auth_type, auth_passwd.GetBytes());

            if (zk.Exists(config_root, true) == null)
            {
                //设置Auth后,创建Node需要使用acl访问控制列表
                zk.Create(config_root, "config".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
            if (zk.Exists(config_user, true) == null)
            {
                zk.Create(config_user, "admin".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
            if (zk.Exists(config_passwd, true) == null)
            {
                zk.Create(config_passwd, "admin".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientConnection"/> class.
 /// </summary>
 /// <param name="hosts">The hosts.</param>
 /// <param name="sessionTimeout">The session timeout.</param>
 /// <param name="zooKeeper">The zoo keeper.</param>
 /// <param name="watcher">The watch manager.</param>
 /// <param name="sessionId">The session id.</param>
 /// <param name="sessionPasswd">The session passwd.</param>
 public ClientConnection(string hosts, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, long sessionId, byte[] sessionPasswd)
     : this(hosts, sessionTimeout, zooKeeper, watcher, 0, new byte[16], DefaultConnectTimeout)
 {
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientConnection"/> class.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="sessionTimeout">The session timeout.</param>
 /// <param name="zooKeeper">The zoo keeper.</param>
 /// <param name="watcher">The watch manager.</param>
 /// <param name="connectTimeout">Connection Timeout.</param>
 public ClientConnection(string connectionString, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, TimeSpan connectTimeout) :
     this(connectionString, sessionTimeout, zooKeeper, watcher, 0, new byte[16], connectTimeout)
 {
 }
コード例 #5
0
ファイル: ZKPaths.cs プロジェクト: qwe19930823/zookeeper
 /**
  * Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish
  * between directories and files. So, every node in the path is created. The data for each node is an empty blob
  *
  * @param zookeeper the client
  * @param path      path to ensure
  * @throws InterruptedException thread interruption
  * @throws org.apache.zookeeper.KeeperException
  *                              Zookeeper errors
  */
 public static void Mkdirs(ZooKeeper zookeeper, String path)
 {
     Mkdirs(zookeeper, path, true);
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: lazy111/test
 public Client()
 {
     zk = new ZooKeeperNet.ZooKeeper("127.0.0.1:2181", new TimeSpan(1, 0, 0, 0), this);
     InitValue();
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientConnection"/> class.
 /// </summary>
 /// <param name="hosts">The hosts.</param>
 /// <param name="sessionTimeout">The session timeout.</param>
 /// <param name="zooKeeper">The zoo keeper.</param>
 /// <param name="watcher">The watch manager.</param>
 /// <param name="sessionId">The session id.</param>
 /// <param name="sessionPasswd">The session passwd.</param>
 /// <param name="connectTimeout">Connection Timeout.</param>
 public ClientConnection(string hosts, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, long sessionId, byte[] sessionPasswd, TimeSpan connectTimeout) :
     this(hosts, sessionTimeout, zooKeeper, watcher, null, sessionId, sessionPasswd, connectTimeout)
 {
 }
コード例 #8
0
ファイル: Lock.cs プロジェクト: lazy111/test
 public Lock(string serverHost)
 {
     this.serverHost = serverHost;
     zk = new ZooKeeperNet.ZooKeeper(serverHost, new TimeSpan(1, 0, 0), new LockWatcher());
 }
コード例 #9
0
ファイル: ConsumerWatcher.cs プロジェクト: hsdotnet/rpc
 public ConsumerWatcher(ZooKeeperNet.ZooKeeper zooKeeper, ClientCacheContainer clientCacheContainer, ISerializer serializer)
     : base(zooKeeper, clientCacheContainer, serializer)
 {
 }