public void Add(ZooKeeperEvent @event) { if (_shutdown.Value == false) { try { _eventQueue.TryAdd(@event); } catch { } } }
private void FireNewSessionEvent() { foreach (var listener in _stateListeners) { Action <ZooKeeperEvent> handler = e => listener.OnNewSession(); var description = string.Format("New session event send to {0}", listener); var @event = new ZooKeeperEvent(description, handler); _eventExecutor.Add(@event); } }
private void FireStateChangedEvent(KeeperState state) { foreach (var listener in _stateListeners) { Action <ZooKeeperEvent> handler = e => listener.OnStateChanged(state); var description = string.Format("KeeperState changed to {0}, send to {1}", state, listener); var @event = new ZooKeeperEvent(description, handler); _eventExecutor.Add(@event); } }
private void FireDataChangedEvent(string path, IEnumerable <IDataListener> listeners) { var bytes = _connection.Value.GetData(path, true, null); foreach (var listener in listeners) { Action <ZooKeeperEvent> handler = e => { Console.WriteLine(e.Description); listener.OnDataChanged(path, bytes); }; var description = string.Format("data of node {0} changed, send to {1}", path, listener); var @event = new ZooKeeperEvent(description, handler); _eventExecutor.Add(@event); } }
private void FireChildrenChangedEvent(string dir, IEnumerable <IChildListener> listeners) { var children = _connection.Value.GetChildren(dir, true).Select(child => dir + "/" + child).ToList(); foreach (var listener in listeners) { Action <ZooKeeperEvent> handler = e => { Console.WriteLine(e.Description); listener.OnChildrenChanged(children); }; var description = string.Format("Children of path {0} changed, send to {1}", dir, listener); var @event = new ZooKeeperEvent(description, handler); _eventExecutor.Add(@event); } }