示例#1
0
        /// <summary>
        /// 触发,执行事件
        /// </summary>
        /// <param name="event"></param>
        public void Process(ZookeeperEvent @event)
        {
            try
            {
                switch (@event.Type)
                {
                case ZookeeperEvent.EventType.NodeChildrenChanged:
                    NodeChildrenChanged?.Invoke(@event);
                    break;

                case ZookeeperEvent.EventType.NodeCreated:
                    NodeCreated?.Invoke(@event);
                    break;

                case ZookeeperEvent.EventType.NodeDeleted:
                    NodeDeleted?.Invoke(@event);
                    break;

                case ZookeeperEvent.EventType.NodeDataChanged:
                    NodeDataChanged?.Invoke(@event);
                    break;
                }

                AllTypeChanged?.Invoke(@event);
            }
            catch { }
        }
示例#2
0
        /// <summary>
        /// 监控回调
        /// </summary>
        /// <param name="event">回调事件</param>
        /// <returns>异步</returns>
        public async override Task process(WatchedEvent @event)
        {
            ZookeeperEvent ze = new ZookeeperEvent(@event);

            if (!string.IsNullOrEmpty(ze.Path))
            {
                NodeWatcher watcher;
                if (nodeWatchers.TryGetValue(ze.Path, out watcher))
                {
                    if (watcher != null)
                    {
                        try
                        {
                            watcher.Process(ze);
                        }
                        catch { }
                        await WatchAsync(ze.Path, watcher, true);//重新监控
                    }
                }
            }
        }