Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void ProcessCanceled(WatchResponse response)
        {
            WatcherImpl watcher = null;

            this.watchers.TryGetValue(response.GetWatchId(), out watcher);
            this.cancelSet.Remove(response.GetWatchId());
            if (watcher == null)
            {
                return;
            }
            string reason = response.GetCancelReason();

            if (string.IsNullOrEmpty(reason))
            {
                watcher.Enqueue(new WatchResponseWithError(new EtcdException(
                                                               ErrorCode.OUT_OF_RANGE,
                                                               "etcdserver: mvcc: required revision is a future revision"))
                                );
            }
            else
            {
                watcher.Enqueue(
                    new WatchResponseWithError(new EtcdException(ErrorCode.FAILED_PRECONDITION, reason)));
            }
        }
Exemplo n.º 3
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;
        }