Пример #1
0
        private void ProcessEvents(WatchResponse response)
        {
            WatcherImpl watcher = null;

            this.watchers.TryGetValue(response.GetWatchId(), out watcher);
            if (watcher == null)
            {
                // cancel server side watcher.
                this.CancelWatcher(response.GetWatchId());
                return;
            }

            if (response.GetCompactRevision() != 0)
            {
                watcher.Enqueue(new WatchResponseWithError(
                                    new EtcdException(response.GetCompactRevision())));
                return;
            }

            if (response.GetEventsCount() == 0)
            {
                watcher.SetRevision(response.GetHeader().GetRevision());
                return;
            }
            watcher.Enqueue(new WatchResponseWithError(response));
            //watcher.SetRevision(
            //    response.GetEvents(response.GetEventsCount() - 1)
            //        .GetKv().getModRevision() + 1);
        }
Пример #2
0
        private void ProcessCreate(WatchResponse response)
        {
            WatcherImpl watcher = null;

            this.pendingWatchers.TryDequeue(out watcher);

            this.SendNextWatchCreateRequest();

            if (watcher == null)
            {
                // shouldn't happen
                // may happen due to duplicate watch create responses.
                // LOG.warn("Watch client receives watch create response but find no corresponding watcher");
                return;
            }

            if (watcher.IsClosed())
            {
                return;
            }

            if (response.GetWatchId() == -1)
            {
                watcher.Enqueue(new WatchResponseWithError(
                                    new EtcdException(ErrorCode.INTERNAL, "etcd server failed to create watch id")));
                return;
            }

            if (watcher.GetRevision() == 0)
            {
                watcher.SetRevision(response.GetHeader().GetRevision());
            }

            watcher.SetWatchID(response.GetWatchId());
            this.watchers[watcher.GetWatchID()] = watcher;
        }