コード例 #1
0
 /// <summary>
 /// 构建节点监视器
 /// </summary>
 /// <param name="zooKeeperClient"></param>
 /// <param name="nodeName">节点名称</param>
 /// <param name="nodeData">节点值</param>
 /// <param name="disconfNodeType">节点类型</param>
 /// <param name="monitorPath">监视路径</param>
 public NodeWatcher(ZooKeeperClient zooKeeperClient, string nodeName, string nodeData, DisconfNodeType disconfNodeType, string monitorPath)
 {
     _zooKeeperClient = zooKeeperClient;
     _monitorPath     = monitorPath;
     _nodeName        = nodeName;
     _nodeData        = nodeData;
     _disconfNodeType = disconfNodeType;
 }
コード例 #2
0
 public static void Init(string host, string rootNode)
 {
     lock (SyncRoot)
     {
         _host     = host;
         _rootNode = rootNode;
         _client   = new ZooKeeperClient();
         _client.Connect(host);
     }
 }
コード例 #3
0
        public static ZooKeeperClient GetZooKeeperClient(string host)
        {
            if (string.IsNullOrWhiteSpace(host))
            {
                throw new ArgumentNullException("host");
            }

            return(Clients.GetOrSet(host, () =>
            {
                ZooKeeperClient client = new ZooKeeperClient();
                client.Connect(host);
                return client;
            }));
        }
コード例 #4
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="disconfWebApi">配置中心接口服务</param>
        /// <param name="assemblies">配置类所在的程序集</param>
        public static void Init(IDisconfWebApi disconfWebApi = null, params Assembly[] assemblies)
        {
            if (disconfWebApi == null)
            {
                disconfWebApi = new DisconfWebApi();
            }
            _disconfWebApi = disconfWebApi;
            if (!DisconfClientSettings.DisableZooKeeper)
            {
                _zooKeeperClient = new ZooKeeperClient(_disconfWebApi);
                //向Zookeeper发送一个Watch,以便近快的拿到SyncConnected状态
                WatcherManager watcherManager = new WatcherManager(_zooKeeperClient);
                watcherManager.WatchPath("test", "test", DisconfNodeType.Item);
            }
            DisconfClientSettings.Verify();
            if (DisconfClientSettings.OnlyLoadLocalConfig)
            {
                LoadLocalConfig();
            }
            else
            {
                try
                {
                    LoadConfigItemsFromServer();
                }
                catch (Exception ex)
                {
                    string localConfigPath     = GetLocalConfigPath();
                    bool   isExistsLocalConfig = File.Exists(localConfigPath);
                    if (!isExistsLocalConfig)
                    {
                        throw;
                    }
                    LoadLocalConfig();
                    LogManager.GetLogger().Error(string.Format("从配置中心获取数据加载全量数据失败,已从本地副本中加载成功({0})!", localConfigPath), ex);
                }
            }

            AssemblyScan(assemblies);
            AutoRefresh();
            StartFileSystemWatcher();
        }
コード例 #5
0
 public WatcherManager(ZooKeeperClient zooKeeperClient)
 {
     _zooKeeperClient = zooKeeperClient;
 }