public ICloseableClient KeepAlive(long leaseId) { KeepAlive <Etcdserverpb.LeaseKeepAliveRequest, Etcdserverpb.LeaseKeepAliveResponse> item = null; if (!keepAlives.TryGetValue(leaseId, out item)) { item = new KeepAlive <Etcdserverpb.LeaseKeepAliveRequest, Etcdserverpb.LeaseKeepAliveResponse>(leaseId); } Grpc.Core.CallOptions callOptions = new Grpc.Core.CallOptions(); //callOptions. var rsp = leaseClient.LeaseKeepAlive(callOptions); item.AddObserver(rsp); return(item); }
private void ProcessKeepAliveResponse( Etcdserverpb.LeaseKeepAliveResponse leaseKeepAliveResponse) { if (this.closed) { return; } long leaseID = leaseKeepAliveResponse.ID; long ttl = leaseKeepAliveResponse.TTL; KeepAlive <Etcdserverpb.LeaseKeepAliveRequest, Etcdserverpb.LeaseKeepAliveResponse> ka = null; if (keepAlives.TryGetValue(leaseID, out ka)) { if (ttl > 0) { long nextKeepAlive = DateTime.Now.Ticks + ttl * 1000 / 3; ka.NextKeepAlive = nextKeepAlive; ka.DeadLine = DateTime.Now.Ticks + ttl * 1000; ka.List.ForEach(kv => { kv.RequestStream.WriteAsync(new Etcdserverpb.LeaseKeepAliveRequest() { ID = leaseID }); }); } else { this.RemoveKeepAlive(leaseID); // lease expired; close all keep alive //this.re(leaseID); //ka.onError( // newEtcdException( // ErrorCode.NOT_FOUND, // "etcdserver: requested lease not found" // ) //); } } }