Esempio n. 1
0
        public async Task <EtcdWatcher> Watch(string key)
        {
            var watchRequest = new WatchRequest()
            {
                CreateRequest = new WatchCreateRequest()
                {
                    Key = ByteString.CopyFromUtf8(key)
                }
            };
            var watcher = watchClient.Watch();
            await watcher.RequestStream.WriteAsync(watchRequest);

            return(new EtcdWatcher(watcher));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
            public void Resume()
            {
                if (closed)
                {
                    return;
                }

                if (stream == null)
                {
                    // id is not really useful today but it may be in etcd 3.4
                    watchID = -1;
                    Etcdserverpb.WatchCreateRequest createRequest = new Etcdserverpb.WatchCreateRequest
                    {
                        Key            = key.GetByteString(),
                        PrevKv         = watchOption.IsPrevKV,
                        ProgressNotify = watchOption.IsProgressNotify,
                        RangeEnd       = watchOption.EndKey.GetByteString(),
                        StartRevision  = watchOption.Revision
                    };
                    if (watchOption.EndKey.IsPresent)
                    {
                        createRequest.RangeEnd = watchOption.EndKey.GetByteString();
                    }
                    if (watchOption.IsNoDelete)
                    {
                        createRequest.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Nodelete);
                    }
                    if (watchOption.IsNoPut)
                    {
                        createRequest.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Noput);
                    }
                    Grpc.Core.CallOptions     callOptions = new Grpc.Core.CallOptions();
                    Etcdserverpb.WatchRequest request     = new Etcdserverpb.WatchRequest
                    {
                        CreateRequest = createRequest
                    };
                    var rsp = watchClient.Watch(callOptions);
                    rsp.RequestStream.WriteAsync(request);
                    stream       = rsp;
                    this.watchID = rsp.ResponseStream.Current.WatchId;
                }
            }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Channel     c   = new Channel("localhost", 2379, ChannelCredentials.Insecure);
            WatchClient cli = new WatchClient(c);

            var x = cli.Watch();

            Console.WriteLine("input key....");
            var key = Console.ReadLine();

            var watchAction = new Action(async() =>
            {
                await x.RequestStream.WriteAsync(new WatchRequest()
                {
                    CreateRequest = new WatchCreateRequest()
                    {
                        ProgressNotify = false, Key = Google.Protobuf.ByteString.CopyFromUtf8(key), PrevKv = true
                    }
                });
                await x.RequestStream.CompleteAsync();
            });

            watchAction();

            var eventOn = new Action(async() =>
            {
                while (await x.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
                {
                    Console.WriteLine(x.ResponseStream.Current.ToString());
                    foreach (var item in x.ResponseStream.Current.Events)
                    {
                        Console.WriteLine(item.Kv.ToString());
                    }
                }
            });

            eventOn();

            Console.WriteLine("...");
            Console.ReadLine();
        }