示例#1
0
 public WatcherImpl(ByteSequence key, WatchOption watchOption, WatchImpl owner)
 {
     this.key         = key;
     this.watchOption = watchOption;
     this.revision    = watchOption.Revision;
     this.owner       = owner;
     this.watchClient = owner.watchClient;
 }
        public EtcdClient(params Uri[] etcdUrls)
        {
            this.channel     = new Channel(etcdUrls[0].Host, etcdUrls[0].Port, ChannelCredentials.Insecure);
            this.kvClient    = new KV.KVClient(channel);
            this.watchClient = new WatchClient(this.channel);
            this.leaseClient = new LeaseClient(this.channel);
            var asyncDuplexStreamingCall = leaseClient.LeaseKeepAlive();

            this.leaseTTLRefresher = new EtcdLeaseTTLRefresher(asyncDuplexStreamingCall);
        }
示例#3
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();
        }
示例#4
0
        /// <summary>
        /// Configures the <see cref="KubernetesClient.WatchPodAsync(string, string, string, string, WatchEventDelegate{V1Pod}, CancellationToken)"/> method
        /// on the mock.
        /// </summary>
        /// <param name="client">
        /// The mock to configure.
        /// </param>
        /// <param name="labelSelector">
        /// The label selector used to watch the pods.
        /// </param>
        /// <returns>
        /// A <see cref="WatchClient{T}"/> which can be used to invoke the event handler (if set) and complete the watch operation.
        /// </returns>
        public static WatchClient <V1Pod> WithPodWatcher(this Mock <KubernetesClient> client, string labelSelector)
        {
            var watchClient = new WatchClient <V1Pod>();

            client
            .Setup(k => k.WatchPodAsync(
                       null /* fieldSelector */,
                       labelSelector /* labelSelector */,
                       null /* resourceVersion */,
                       null /* resourceVersionMatch */,
                       It.IsAny <WatchEventDelegate <V1Pod> >(),
                       It.IsAny <CancellationToken>()))
            .Callback <string, string, string, WatchEventDelegate <V1Pod>, CancellationToken>(
                (fieldSelector, labelSelector, resourceVersion, eventHandler, cancellationToken) =>
            {
                cancellationToken.Register(watchClient.TaskCompletionSource.SetCanceled);
                watchClient.ClientRegistered.SetResult(eventHandler);
            })
            .Returns(watchClient.TaskCompletionSource.Task);

            return(watchClient);
        }
示例#5
0
 WatchImpl(ClientConnectionManager connectionManager)
 {
     this.connectionManager = connectionManager;
     managedChannel         = connectionManager.NewChannel();
     watchClient            = new WatchClient(managedChannel.channel);
 }