Ejemplo n.º 1
0
        private async Task UpdateChildrenAsync(ZkManager zk)
        {
            var childrenList = await zk.GetChlidrenListAsync(_routeCoordinatorOption.ParentName);

            lock (this)
            {
                _availableServerList = childrenList;
            }
            LogUtil.Info($"最新全部连接【{string.Join(",", _availableServerList)}】");
        }
Ejemplo n.º 2
0
 private async Task NodeChangedAsync(WatchedEvent @event, ZkManager zk)
 {
     LogUtil.InfoFormat("NodeChange:{0},{1},{2}", @event.getPath(), @event.getState(), @event.get_Type());
     if (@event.getState() == Watcher.Event.KeeperState.SyncConnected)
     {
         await UpdateChildrenAsync(zk);
     }
     else if (@event.getState() == Watcher.Event.KeeperState.Disconnected || @event.getState() == Watcher.Event.KeeperState.Expired)
     {
         await Retry(async() =>
         {
             //重新连接
             await zk.ReConnectAsync();
         }, retryCount : _routeCoordinatorOption.RetryCount, everyTryInterval : _routeCoordinatorOption.OperatingTimeout);
     }
     else if (@event.get_Type() == Watcher.Event.EventType.NodeChildrenChanged)
     {
         await UpdateChildrenAsync(zk);
     }
     else if (@event.get_Type() == Watcher.Event.EventType.NodeCreated || @event.get_Type() == Watcher.Event.EventType.NodeDeleted)
     {
         await UpdateChildrenAsync(zk);
     }
 }
Ejemplo n.º 3
0
 public ZkWatcher(Func <WatchedEvent, ZkManager, Task> changeEvent, ZkManager zkManager)
 {
     _changeEvent = changeEvent;
     _zkManager   = zkManager;
 }
Ejemplo n.º 4
0
 public ZkCoordinator(RouteCoordinatorOption routeCoordinatorOption)
 {
     _routeCoordinatorOption = routeCoordinatorOption;
     _zkManager = new ZkManager(routeCoordinatorOption, NodeChangedAsync);
 }