Esempio n. 1
0
        /// <summary>
        /// 处理未知response
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="response"></param>
        protected override void HandleUnknowResponse(IConnection connection, ZookResponse response)
        {
            if (response.HasError())
            {
                connection.BeginDisconnect(response.Error()); return;
            }
            if (response.XID != -1)
            {
                return;
            }

            Data.WatcherEvent wevent = null;
            try { wevent = Utils.Marshaller.Deserialize <Data.WatcherEvent>(response.Payload); }
            catch (Exception ex) { Sodao.FastSocket.SocketBase.Log.Trace.Error(ex.Message, ex); return; }

            var e = new Data.WatchedEvent(wevent.Type, wevent.State, Utils.PathUtils.RemoveChroot(this._chrootPath, wevent.Path));

            this._watcherManager.Invoke(e);
        }
Esempio n. 2
0
        /// <summary>
        /// invoke
        /// </summary>
        /// <param name="wevent"></param>
        /// <exception cref="ArgumentNullException">wevent is null.</exception>
        public void Invoke(Data.WatchedEvent wevent)
        {
            if (wevent == null)
            {
                throw new ArgumentNullException("wevent");
            }

            var watcherSet = new HashSet <IWatcher>();

            switch (wevent.Type)
            {
            case Data.EventType.NodeCreated:
            case Data.EventType.NodeDataChanged:
                this.CopyTo(this.TryRemoveDataWatcher(wevent.Path), watcherSet);
                this.CopyTo(this.TryRemoveExistWatcher(wevent.Path), watcherSet);
                break;

            case Data.EventType.NodeChildrenChanged:
                this.CopyTo(this.TryRemoveChildWatcher(wevent.Path), watcherSet);
                break;

            case Data.EventType.NodeDeleted:
                this.CopyTo(this.TryRemoveDataWatcher(wevent.Path), watcherSet);
                this.TryRemoveExistWatcher(wevent.Path);
                this.CopyTo(this.TryRemoveChildWatcher(wevent.Path), watcherSet);
                break;
            }

            if (watcherSet.Count > 0)
            {
                foreach (var childWatcher in watcherSet)
                {
                    var watcher = childWatcher;
                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        try { watcher.Process(wevent); }
                        catch (Exception ex) { Sodao.FastSocket.SocketBase.Log.Trace.Error(ex.Message, ex); }
                    });
                }
            }
        }
Esempio n. 3
0
 public void Process(WatchedEvent zevent)
 {
     Console.WriteLine("Log watche: {0}", zevent.Path);
 }
Esempio n. 4
0
 /// <summary>
 /// process
 /// </summary>
 /// <param name="zevent"></param>
 public void Process(Data.WatchedEvent zevent)
 {
     this._callback(zevent);
 }
Esempio n. 5
0
 /// <summary>
 /// invoke event.
 /// </summary>
 /// <param name="zevent"></param>
 public void Invoke(Data.WatchedEvent zevent)
 {
     this._callback(zevent);
 }