public void Process(WatchedEvent @event)
 {
     var path = @event.Path;
     if (@event.Type == EventType.None)
     {
         // We are are being told that the state of the
         // connection has changed
         switch (@event.State)
         {
             case KeeperState.SyncConnected:
                 // In this particular example we don't need to do anything
                 // here - watches are automatically re-registered with
                 // server and any watches triggered while the client was
                 // disconnected will be delivered (in order of course)
                 break;
             case KeeperState.Expired:
                 // It's all over
                 Dead = true;
                 _listener.Closing(KeeperException.Code.SESSIONEXPIRED);
                 break;
         }
     }
     else
     {
         if (path != null && path.Equals(_znode))
         {
             _zk.Exists(_znode, this);
         }
     }
     if (_chainedWatcher != null)
     {
         _chainedWatcher.Process(@event);
     }
 }
예제 #2
0
 public void Process(WatchedEvent @event)
 {
     //if (@event.Type == EventType.NodeDataChanged)
     //{
     Console.WriteLine("已经触发了" + @event.Type + "事件!" + DateTime.Now);
     //}
 }
예제 #3
0
파일: Program.cs 프로젝트: Indifer/Test
 public void Process(WatchedEvent e)
 {
     if (e.Type == EventType.NodeDataChanged)
     {
         Console.WriteLine("Path:{0},State:{0},Type:{0},Wrapper:{0}", e.Path, e.State, e.Type, e.Wrapper);
         //Console.WriteLine(e.Path);
     }
 }
 void IWatcher.Process(WatchedEvent @event)
 {
     if (@event.Type == EventType.NodeDataChanged)
         lock (syncLock)
             try
             {
                 Update();
             }
             catch { }
 }
예제 #5
0
        public void Process(WatchedEvent @event)
        {
            //if (@event.Type == EventType.NodeDataChanged)
            //{
            Console.WriteLine("已经触发了" + @event.Type + @event.ToString() + "事件!Watcher2" + DateTime.Now);
            Console.Write(string.Join(",", zk.GetChildren("/root", this)));
            if (zk.Exists("/root/childone", true) != null) {
                zk.GetData("/root/childone", true, null);
            }

            Console.WriteLine();
            //}
        }
예제 #6
0
 private static void ProcessWatcher(IEnumerable <IWatcher> watchers, WatchedEvent watchedEvent)
 {
     foreach (IWatcher watcher in watchers)
     {
         try
         {
             watcher.Process(watchedEvent);
         }
         catch (Exception t)
         {
             LOG.Error("Error while calling watcher ", t);
         }
     }
 }
        public void QueueEvent(WatchedEvent @event)
        {
            if (@event.Type == EventType.None && sessionState == @event.State)
            {
                return;
            }

            sessionState = @event.State;

            // materialize the watchers based on the event
            var pair = new ClientConnection.WatcherSetEventPair(conn.watcher.Materialize(@event.State, @event.Type, @event.Path), @event);

            // queue the pair (watch set & event) for later processing
            AppendToQueue(pair);
        }
 private static void ProcessWatcher(IEnumerable<IWatcher> watchers,WatchedEvent watchedEvent)
 {
     foreach (IWatcher watcher in watchers)
     {
         try
         {
             if (null != watcher)
             {
                 watcher.Process(watchedEvent);
             }
         }
         catch (Exception t)
         {
             LOG.Error("Error while calling watcher ", t);
         }
     }
 }
 private static void ProcessWatcher(IEnumerable <IWatcher> watchers, WatchedEvent watchedEvent)
 {
     foreach (IWatcher watcher in watchers)
     {
         try
         {
             if (null != watcher)
             {
                 watcher.Process(watchedEvent);
             }
         }
         catch (Exception t)
         {
             //modified by Yang Li
             //LOG.Error("Error while calling watcher ", t);
             LOG.Error(string.Format("Error while calling watcher.{0} The error message is: {0}{1}", Environment.NewLine, t.ToString()), t);
         }
     }
 }
 private static void ProcessWatcher(IEnumerable <IWatcher> watchers, WatchedEvent watchedEvent)
 {
     foreach (IWatcher watcher in watchers)
     {
         try
         {
             if (null != watcher)
             {
                 watcher.Process(watchedEvent);
             }
         }
         catch (Exception t)
         {
             #if !NET_CORE
             LOG.Error("Error while calling watcher ", t);
             #endif
         }
     }
 }
        public void QueueEvent(WatchedEvent @event)
        {
            if (@event.Type == EventType.None && sessionState == @event.State)
            {
                return;
            }

            if (waitingEvents.IsAddingCompleted)
            {
                throw new InvalidOperationException("consumer has been disposed");
            }

            sessionState = @event.State;

            // materialize the watchers based on the event
            var pair = new ClientConnection.WatcherSetEventPair(conn.watcher.Materialize(@event.State, @event.Type, @event.Path), @event);

            // queue the pair (watch set & event) for later processing
            waitingEvents.Add(pair);
        }
        private void ReadResponse()
        {
            using (MemoryStream ms = new MemoryStream(incomingBuffer))
            using (var reader = new EndianBinaryReader(EndianBitConverter.Big, ms, Encoding.UTF8))
            {
                BinaryInputArchive bbia = BinaryInputArchive.GetArchive(reader);
                ReplyHeader replyHdr = new ReplyHeader();

                replyHdr.Deserialize(bbia, "header");
                if (replyHdr.Xid == -2)
                {
                    // -2 is the xid for pings
                    if (PingLog.IsDebugEnabled)
                    {
                        PingLog.Debug(string.Format("Got ping response for sessionid: 0x{0:X} after {1}ms", conn.SessionId, (DateTime.Now.Nanos() - lastPingSentNs) / 1000000));
                    }
                    return;
                }
                if (replyHdr.Xid == -4)
                {
                    // -4 is the xid for AuthPacket
                    // TODO: process AuthPacket here
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got auth sessionid:0x{0:X}", conn.SessionId));
                    }
                    return;
                }
                if (replyHdr.Xid == -1)
                {
                    // -1 means notification
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got notification sessionid:0x{0}", conn.SessionId));
                    }
                    WatcherEvent @event = new WatcherEvent();
                    @event.Deserialize(bbia, "response");

                    // convert from a server path to a client path
                    if (conn.ChrootPath != null)
                    {
                        string serverPath = @event.Path;
                        if (serverPath.CompareTo(conn.ChrootPath) == 0)
                            @event.Path = "/";
                        else
                            @event.Path = serverPath.Substring(conn.ChrootPath.Length);
                    }

                    WatchedEvent we = new WatchedEvent(@event);
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got {0} for sessionid 0x{1:X}", we, conn.SessionId));
                    }

                    conn.consumer.QueueEvent(we);
                    return;
                }
                if (pendingQueue.IsEmpty())
                {
                    throw new IOException(string.Format("Nothing in the queue, but got {0}", replyHdr.Xid));
                }

                Packet packet;
                lock (pendingQueueLock)
                {
                    packet = pendingQueue.First.Value;
                    pendingQueue.RemoveFirst();
                }
                /*
             * Since requests are processed in order, we better get a response
             * to the first request!
             */
                try
                {
                    if (packet.header.Xid != replyHdr.Xid)
                    {
                        packet.replyHeader.Err = (int)KeeperException.Code.CONNECTIONLOSS;
                        throw new IOException(string.Format("Xid out of order. Got {0} expected {1}", replyHdr.Xid, packet.header.Xid));
                    }

                    packet.replyHeader.Xid = replyHdr.Xid;
                    packet.replyHeader.Err = replyHdr.Err;
                    packet.replyHeader.Zxid = replyHdr.Zxid;
                    if (replyHdr.Zxid > 0)
                    {
                        lastZxid = replyHdr.Zxid;
                    }
                    if (packet.response != null && replyHdr.Err == 0)
                    {
                        packet.response.Deserialize(bbia, "response");
                    }

                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Reading reply sessionid:0x{0:X}, packet:: {1}", conn.SessionId, packet));
                    }
                }
                finally
                {
                    FinishPacket(packet);
                }
            }
        }
예제 #13
0
 //updates remote region servers IP table.
 private void UpdateRegionServers(WatchedEvent @event)
 {
     //obtains a list of remote region server address. just likes: "gs-server-1003,60020,1433640602093"
     IEnumerable<string> children = _zkClient.GetChildren("/hbase/rs", new ZooKeeperWatcher(UpdateRegionServers));
     List<IPEndPoint> regionServers = new List<IPEndPoint>();
     foreach (string rs in children)
     {
         string[] args = rs.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
         regionServers.Add(new IPEndPoint(IPAddress.Parse(_hostMappingManager.GetIPAddressByHostName(args[0])), _tPort));
     }
     Interlocked.Exchange(ref _regionServers, regionServers);
 }
예제 #14
0
        private void ReadResponse(byte[] content)
        {
            using (var reader = new EndianBinaryReader(EndianBitConverter.Big, new MemoryStream(content), Encoding.UTF8))
            {
                BinaryInputArchive bbia     = BinaryInputArchive.GetArchive(reader);
                ReplyHeader        replyHdr = new ReplyHeader();

                replyHdr.Deserialize(bbia, "header");
                if (replyHdr.Xid == -2)
                {
                    // -2 is the xid for pings
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.DebugFormat("Got ping response for sessionid: 0x{0:X} after {1}ms", conn.SessionId, (DateTime.UtcNow.Nanos() - lastPingSentNs) / 1000000);
                    }
                    return;
                }
                if (replyHdr.Xid == -4)
                {
                    // -2 is the xid for AuthPacket
                    // TODO: process AuthPacket here
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.DebugFormat("Got auth sessionid:0x{0:X}", conn.SessionId);
                    }
                    return;
                }
                if (replyHdr.Xid == -1)
                {
                    // -1 means notification
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.DebugFormat("Got notification sessionid:0x{0}", conn.SessionId);
                    }

                    WatcherEvent @event = new WatcherEvent();
                    @event.Deserialize(bbia, "response");

                    // convert from a server path to a client path
                    if (conn.ChrootPath != null)
                    {
                        string serverPath = @event.Path;
                        if (serverPath.CompareTo(conn.ChrootPath) == 0)
                        {
                            @event.Path = PathUtils.PathSeparator;
                        }
                        else
                        {
                            @event.Path = serverPath.Substring(conn.ChrootPath.Length);
                        }
                    }

                    WatchedEvent we = new WatchedEvent(@event);
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.DebugFormat("Got {0} for sessionid 0x{1:X}", we, conn.SessionId);
                    }

                    conn.consumer.QueueEvent(we);
                    return;
                }
                Packet packet;

                /*
                 * Since requests are processed in order, we better get a response
                 * to the first request!
                 */
                if (pendingQueue.TryDequeue(out packet))
                {
                    try
                    {
                        if (packet.header.Xid != replyHdr.Xid)
                        {
                            packet.replyHeader.Err = (int)KeeperException.Code.CONNECTIONLOSS;
                            throw new IOException(new StringBuilder("Xid out of order. Got ").Append(replyHdr.Xid).Append(" expected ").Append(packet.header.Xid).ToString());
                        }

                        packet.replyHeader.Xid  = replyHdr.Xid;
                        packet.replyHeader.Err  = replyHdr.Err;
                        packet.replyHeader.Zxid = replyHdr.Zxid;
                        if (replyHdr.Zxid > 0)
                        {
                            lastZxid = replyHdr.Zxid;
                        }

                        if (packet.response != null && replyHdr.Err == 0)
                        {
                            packet.response.Deserialize(bbia, "response");
                        }

                        if (LOG.IsDebugEnabled)
                        {
                            LOG.DebugFormat("Reading reply sessionid:0x{0:X}, packet:: {1}", conn.SessionId, packet);
                        }
                    }
                    finally
                    {
                        FinishPacket(packet);
                    }
                }
                else
                {
                    throw new IOException(new StringBuilder("Nothing in the queue, but got ").Append(replyHdr.Xid).ToString());
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Processes ZooKeeper event
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        /// <remarks>
        /// Requires installed watcher
        /// </remarks>
        public void Process(WatchedEvent e)
        {
            this.EnsuresNotDisposed();
            Logger.Debug("Received event: " + e);
            this.zooKeeperEventWorker = Thread.CurrentThread;
            if (this.shutdownTriggered)
            {
                Logger.Debug("ignoring event '{" + e.Type + " | " + e.Path + "}' since shutdown triggered");
                return;
            }

            bool stateChanged = e.Path == null;
            bool znodeChanged = e.Path != null;
            bool dataChanged =
                e.Type == EventType.NodeDataChanged
                || e.Type == EventType.NodeDeleted
                || e.Type == EventType.NodeCreated
                || e.Type == EventType.NodeChildrenChanged;

            lock (this.somethingChanged)
            {
                try
                {
                    if (stateChanged)
                    {
                        this.ProcessStateChange(e);
                    }

                    if (dataChanged)
                    {
                        this.ProcessDataOrChildChange(e);
                    }
                }
                finally
                {
                    if (stateChanged)
                    {
                        lock (this.stateChangedLock)
                        {
                            Monitor.PulseAll(this.stateChangedLock);
                        }

                        if (e.State == KeeperState.Expired)
                        {
                            lock (this.znodeChangedLock)
                            {
                                Monitor.PulseAll(this.znodeChangedLock);
                            }

                            foreach (string path in this.childChangedHandlers.Keys)
                            {
                                this.Enqueue(new ZooKeeperChildChangedEventArgs(path));
                            }

                            foreach (string path in this.dataChangedHandlers.Keys)
                            {
                                this.Enqueue(new ZooKeeperDataChangedEventArgs(path));
                            }
                        }
                    }

                    if (znodeChanged)
                    {
                        lock (this.znodeChangedLock)
                        {
                            Monitor.PulseAll(this.znodeChangedLock);
                        }
                    }
                }

                Monitor.PulseAll(this.somethingChanged);
            }
        }
예제 #16
0
 public void Process(WatchedEvent watchedEvent)
 {
     if (watchedEvent.State != KeeperState.SyncConnected || watchedEvent.Path != Path)
         return;
     ProcessImpl(watchedEvent);
 }
        private void ReadResponse(byte[] content)
        {
            using (var reader = new EndianBinaryReader(EndianBitConverter.Big, new MemoryStream(content), Encoding.UTF8))
            {
                BinaryInputArchive bbia = BinaryInputArchive.GetArchive(reader);
                ReplyHeader replyHdr = new ReplyHeader();

                replyHdr.Deserialize(bbia, "header");
                if (replyHdr.Xid == -2)
                {
                    // -2 is the xid for pings
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got ping response for sessionid: 0x{0:X} after {1}ms", conn.SessionId, (DateTime.UtcNow.Nanos() - lastPingSentNs) / 1000000);
                    return;
                }
                if (replyHdr.Xid == -4)
                {
                    // -2 is the xid for AuthPacket
                    // TODO: process AuthPacket here
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got auth sessionid:0x{0:X}", conn.SessionId);
                    return;
                }
                if (replyHdr.Xid == -1)
                {
                    // -1 means notification
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got notification sessionid:0x{0}", conn.SessionId);

                    WatcherEvent @event = new WatcherEvent();
                    @event.Deserialize(bbia, "response");

                    // convert from a server path to a client path
                    if (conn.ChrootPath != null)
                    {
                        string serverPath = @event.Path;
                        if (serverPath.CompareTo(conn.ChrootPath) == 0)
                            @event.Path = PathUtils.PathSeparator;
                        else
                            @event.Path = serverPath.Substring(conn.ChrootPath.Length);
                    }

                    WatchedEvent we = new WatchedEvent(@event);
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got {0} for sessionid 0x{1:X}", we, conn.SessionId);

                    conn.consumer.QueueEvent(we);
                    return;
                }
                Packet packet;
                /*
             * Since requests are processed in order, we better get a response
             * to the first request!
             */
                if (pendingQueue.TryDequeue(out packet))
                {
                    try
                    {
                        if (packet.header.Xid != replyHdr.Xid)
                        {
                            packet.replyHeader.Err = (int)KeeperException.Code.CONNECTIONLOSS;
                            throw new IOException(new StringBuilder("Xid out of order. Got ").Append(replyHdr.Xid).Append(" expected ").Append(packet.header.Xid).ToString());
                        }

                        packet.replyHeader.Xid = replyHdr.Xid;
                        packet.replyHeader.Err = replyHdr.Err;
                        packet.replyHeader.Zxid = replyHdr.Zxid;
                        if (replyHdr.Zxid > 0)
                            lastZxid = replyHdr.Zxid;

                        if (packet.response != null && replyHdr.Err == 0)
                            packet.response.Deserialize(bbia, "response");

                        if (LOG.IsDebugEnabled)
                            LOG.DebugFormat("Reading reply sessionid:0x{0:X}, packet:: {1}", conn.SessionId, packet);
                    }
                    finally
                    {
                        FinishPacket(packet);
                    }
                }
                else
                {
                    throw new IOException(new StringBuilder("Nothing in the queue, but got ").Append(replyHdr.Xid).ToString());
                }
            }
        }        
예제 #18
0
 public WatcherSetEventPair(IEnumerable <IWatcher> watchers, WatchedEvent @event)
 {
     this.Watchers     = watchers;
     this.WatchedEvent = @event;
 }
예제 #19
0
            protected override void ProcessImpl(WatchedEvent watchedEvent)
            {
                var path = Path;
                switch (watchedEvent.Type)
                {
                    case EventType.NodeDataChanged:
                        var data = _zooKeeper.GetData(path, new NodeMonitorWatcher(_zooKeeper, path, _action), new Stat());
                        _action(data);
                        break;

                    case EventType.NodeDeleted:
                        _action(null);
                        break;
                }
            }
예제 #20
0
파일: Program.cs 프로젝트: ittray/LocalDemo
 public void Process(WatchedEvent @event)
 {
     Console.WriteLine(@event);
 }
        public void QueueEvent(WatchedEvent @event)
        {
            if (@event.Type == EventType.None && sessionState == @event.State) return;

            sessionState = @event.State;

            // materialize the watchers based on the event
            var pair = new ClientConnection.WatcherSetEventPair(conn.watcher.Materialize(@event.State, @event.Type,@event.Path), @event);
            // queue the pair (watch set & event) for later processing
            AppendToQueue(pair);
        }
예제 #22
0
 /// <summary>
 ///    通知
 /// </summary>
 /// <param name="watchedEvent">被观察的事件</param>
 public void Process(WatchedEvent watchedEvent)
 {
     _callback(watchedEvent);
 }
예제 #23
0
파일: TaskNode.cs 프로젝트: hwpayg/WildDogs
        public void Process(WatchedEvent @event)
        {
            if (@event.Path == GloabalConfig.CommandsRoot && @event.Type == EventType.NodeChildrenChanged)
            {
                var childres = Zk.GetChildren(GloabalConfig.CommandsRoot, this).ToList();

                // 做成异步
                var jobs =
                    childres.Where(j => j.StartsWith(Name)).ToList().Select(job => GloabalConfig.CommandsRoot + "/" + job).ToList();

                List<CommandInfo> jobInfos = new List<CommandInfo>();

                foreach (var job in jobs)
                {
                    string json = Encoding.UTF8.GetString(Zk.GetData(job, false, null));
                    CommandInfo jobInfo = JsonConvert.DeserializeObject<CommandInfo>(json);
                    jobInfos.Add(jobInfo);
                }
                AppRuntime.Run(jobInfos);

                foreach (var job in jobs)
                {
                    Zk.Delete(job, -1);
                }
            }

            if (@event.Path == GloabalConfig.Scheduler && @event.Type == EventType.NodeDataChanged)
            {
                List<JobInfo> jobInfos = JsonConvert.DeserializeObject<List<JobInfo>>(Encoding.UTF8.GetString(Zk.GetData(GloabalConfig.Scheduler, false, null)));
                _scheduler.UpdateScheduler(jobInfos);
            }
        }
예제 #24
0
        /// <summary>
        /// Processess ZooKeeper state changes events
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void ProcessStateChange(WatchedEvent e)
        {
            Logger.Info("zookeeper state changed (" + e.State + ")");
            lock (this.stateChangedLock)
            {
                this.currentState = e.State;
            }

            if (this.shutdownTriggered)
            {
                return;
            }

            this.Enqueue(new ZooKeeperStateChangedEventArgs(e.State));
            if (e.State == KeeperState.Expired)
            {
                this.Reconnect(this.connection.Servers, this.connection.SessionTimeout);
                this.Enqueue(ZooKeeperSessionCreatedEventArgs.Empty);
            }
        }
예제 #25
0
 //release control until we have made sure the remote ZooKeeper's state.
 private void WaitForZooKeeperInitialization(WatchedEvent @event)
 {
     if (@event.State == KeeperState.SyncConnected) _zooKeeperInitLock.Set();
 }
예제 #26
0
 public void Process(WatchedEvent @event)
 {
 }
예제 #27
0
            protected override void ProcessImpl(WatchedEvent watchedEvent)
            {
                var path = Path;
                var watcher = new ChildrenMonitorWatcher(_zooKeeper, path, _action);
                switch (watchedEvent.Type)
                {
                    case EventType.NodeCreated:
                    case EventType.NodeChildrenChanged:
                        if (_zooKeeper.Exists(path, watcher) != null)
                        {
                            var childrens = _zooKeeper.GetChildren(path, watcher, new Stat());
                            _action(childrens);
                        }
                        else
                        {
                            _action(null);
                        }
                        break;

                    case EventType.NodeDeleted:
                        _zooKeeper.Exists(path, watcher);
                        _action(null);
                        break;
                }
            }
예제 #28
0
 public void Process(WatchedEvent @event)
 {
     _event = @event;
     _connected.Set();
 }
예제 #29
0
 public void Process(WatchedEvent @event)
 {
     if (@event.State == KeeperState.SyncConnected)
     {
         _connectioned();
     }
     else
     {
         _disconnect();
     }
 }
        public void Process(WatchedEvent e)
        {
            Logger.DebugFormat("Process called by handler. Received event, e.EventType:{0}  e.State: {1} e.Path :{2} ", e.Type, e.State, e.Path);
            this.zooKeeperEventWorker = Thread.CurrentThread;
            if (this.shutdownTriggered)
            {
                Logger.DebugFormat("Shutdown triggered. Ignoring event. Type: {0}, Path: {1}, State: {2} ", e.Type, (e.Path ?? "null"), e.State);
                return;
            }

            try
            {
                this.EnsuresNotDisposed();
                bool stateChanged = string.IsNullOrEmpty(e.Path);
                bool znodeChanged = !string.IsNullOrEmpty(e.Path);
                bool dataChanged =
                    e.Type == EventType.NodeDataChanged
                    || e.Type == EventType.NodeDeleted
                    || e.Type == EventType.NodeCreated
                    || e.Type == EventType.NodeChildrenChanged;

                Logger.DebugFormat("Process called by handler. stateChanged:{0} znodeChanged:{1}  dataChanged:{2} ", stateChanged, znodeChanged, dataChanged);

                lock (this.somethingChanged)
                {
                    try
                    {
                        if (stateChanged)
                        {
                            this.ProcessStateChange(e);
                        }

                        if (dataChanged)
                        {
                            this.ProcessDataOrChildChange(e);
                        }
                    }
                    finally
                    {
                        if (stateChanged)
                        {
                            lock (this.stateChangedLock)
                            {
                                Monitor.PulseAll(this.stateChangedLock);
                            }

                            if (e.State == KeeperState.Expired)
                            {
                                lock (this.znodeChangedLock)
                                {
                                    Monitor.PulseAll(this.znodeChangedLock);
                                }

                                foreach (string path in this.childChangedHandlers.Keys)
                                {
                                    this.Enqueue(new ZooKeeperChildChangedEventArgs(path));
                                }

                                foreach (string path in this.dataChangedHandlers.Keys)
                                {
                                    this.Enqueue(new ZooKeeperDataChangedEventArgs(path));
                                }
                            }
                        }

                        if (znodeChanged)
                        {
                            lock (this.znodeChangedLock)
                            {
                                Monitor.PulseAll(this.znodeChangedLock);
                            }
                        }
                    }

                    Monitor.PulseAll(this.somethingChanged);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error occurred while processing event: " + ex.FormatException());
            }
        }
예제 #31
0
 protected abstract void ProcessImpl(WatchedEvent watchedEvent);
        /// <summary>
        /// Processess ZooKeeper childs or data changes events
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void ProcessDataOrChildChange(WatchedEvent e)
        {
            if (this.shutdownTriggered)
            {
                return;
            }

            if (e.Type == EventType.NodeChildrenChanged
                || e.Type == EventType.NodeCreated
                || e.Type == EventType.NodeDeleted)
            {
                this.Enqueue(new ZooKeeperChildChangedEventArgs(e.Path));
            }

            if (e.Type == EventType.NodeDataChanged
                || e.Type == EventType.NodeCreated
                || e.Type == EventType.NodeDeleted)
            {
                this.Enqueue(new ZooKeeperDataChangedEventArgs(e.Path));
            }
        }
 public WatcherSetEventPair(HashSet <IWatcher> watchers, WatchedEvent @event)
 {
     this.watchers = watchers;
     this.@event   = @event;
 }
        /// <summary>
        /// Processess ZooKeeper state changes events
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void ProcessStateChange(WatchedEvent e)
        {
            Logger.Info("ProcessStateChange==zookeeper state changed (" + e.State + ")");
            lock (this.stateChangedLock)
            {
                Logger.InfoFormat("Current state:{0} in the lib:{1}", this.currentState, this.connection.GetInternalZKClient().State);
                this.currentState = e.State;
            }

            if (this.shutdownTriggered)
            {
                return;
            }

            this.Enqueue(new ZooKeeperStateChangedEventArgs(e.State));
            if (e.State == KeeperState.Expired)
            {
                while (true)
                {
                    try
                    {
                        this.Reconnect(this.connection.Servers, this.connection.SessionTimeout);
                        this.Enqueue(ZooKeeperSessionCreatedEventArgs.Empty);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Exception occurred while trying to reconnect to ZooKeeper", ex);
                        Thread.Sleep(1000);
                        continue;
                    }
                }
            }
        }
예제 #35
0
파일: ZkAdaptor.cs 프로젝트: htlp/Phial
 public void Process(WatchedEvent @event)
 {
     if (@event.Type == EventType.NodeDeleted)
     {
         Log.Info("watching child {0} is deleted", @event.Path);
         AttempToBecomeLeader();
     }
 }
 public void Process(WatchedEvent @event)
 {
     Log.DebugFormat("Watcher fired on path: {0} state: {1} type {2}", @event.Path, @event.State, @event.Type);
     reset.Set();
 }
예제 #37
0
 public WatcherSetEventPair(IEnumerable<IWatcher> watchers, WatchedEvent @event)
 {
     this.Watchers = watchers;
     this.WatchedEvent = @event;
 }
예제 #38
0
파일: ZkAdaptor.cs 프로젝트: htlp/Phial
            public void Process(WatchedEvent @event)
            {
                if (@event.Type == EventType.NodeDataChanged)
                {
                    Log.Info("Process path:{0}", @event.Path);

                    var ret3 = Handle.GetData(@event.Path, this, null);

                    DataChangedHandler(@event.Path, ret3);
                }

            }