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))); } }
public IWatcher Watch(ByteSequence key, WatchOption watchOption) { if (IsClosed()) { throw new ClosedWatchClientException(); } WatcherImpl watcher = new WatcherImpl(key, watchOption, this); // this.pendingWatchers.Enqueue(watcher); Etcdserverpb.WatchRequest request = new Etcdserverpb.WatchRequest(); Etcdserverpb.WatchCreateRequest createRequest = new Etcdserverpb.WatchCreateRequest(); createRequest.Key = key.GetByteString(); createRequest.PrevKv = watchOption.isPrevKV(); createRequest.ProgressNotify = watchOption.isProgressNotify(); createRequest.RangeEnd = watchOption.getEndKey().GetByteString(); createRequest.StartRevision = watchOption.getRevision(); request.CreateRequest = createRequest; Grpc.Core.CallOptions callOptions = new Grpc.Core.CallOptions(); watchClient.Watch(callOptions); // watchClient.Watch() // watchClient.Watch() // if (this.pendingWatchers.Count == 1) { // head of the queue send watchCreate request. // WatchRequest request = this.toWatchCreateRequest(watcher); // this.getGrpcWatchStreamObserver().onNext(request); // } return(watcher); }
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); }
public IWatcher Watch(ByteSequence key, WatchOption watchOption) { if (closed) { throw new ClosedWatchClientException(); } WatcherImpl watcher = null; lock (this) { watcher = new WatcherImpl(key, watchOption, this); watcher.Resume(); pendingWatchers.Enqueue(watcher); } return(watcher); }
public void Close() { lock (this) { if (closed) { return; } WatcherImpl watcherImpl = null; while (!pendingWatchers.IsEmpty) { if (pendingWatchers.TryDequeue(out watcherImpl)) { watcherImpl.Close(); } } } closed = true; }
private static Etcdserverpb.WatchRequest ToWatchCreateRequest(WatcherImpl watcher) { ByteString key = watcher.GetKey().GetByteString(); WatchOption option = watcher.GetWatchOption(); Etcdserverpb.WatchCreateRequest watchCreate = new Etcdserverpb.WatchCreateRequest(); watchCreate.Key = key; watchCreate.PrevKv = option.isPrevKV(); watchCreate.ProgressNotify = option.isProgressNotify(); watchCreate.StartRevision = watcher.GetRevision(); watchCreate.RangeEnd = option.getEndKey().GetByteString(); if (option.isNoDelete()) { watchCreate.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Nodelete); } if (option.isNoPut()) { watchCreate.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Noput); } Etcdserverpb.WatchRequest request = new Etcdserverpb.WatchRequest(); request.CreateRequest = watchCreate; return(request); }
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; }