public void Run() { Logger.Info("Starting ZkClient event thread."); try { while (!this.tokenSource.IsCancellationRequested) { ZkEvent zkEvent = this._events.Take(); int eventId = this._eventId.GetAndIncrement(); Logger.Debug("Delivering event #" + eventId + " " + zkEvent); try { zkEvent.RunAction(); } catch (ThreadInterruptedException) { this.tokenSource.Cancel(); } catch (Exception e) { Logger.Error("Error handling event " + zkEvent, e); } Logger.Debug("Delivering event #" + eventId + " done"); } } catch (ThreadInterruptedException) { Logger.Info("Terminate ZkClient event thread."); } }
public void Send(ZkEvent zkEvent) { if (!this.tokenSource.IsCancellationRequested) { Logger.Debug("New event: " + zkEvent); this._events.Add(zkEvent); } }