diff options
Diffstat (limited to 'src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs')
-rw-r--r-- | src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs index e93b9b96dc..21482b302b 100644 --- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs +++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs @@ -54,38 +54,36 @@ namespace Grpc.HealthCheck public class HealthServiceImpl : Grpc.Health.V1.Health.IHealth { private readonly object myLock = new object(); - private readonly Dictionary<Key, HealthCheckResponse.Types.ServingStatus> statusMap = - new Dictionary<Key, HealthCheckResponse.Types.ServingStatus>(); + private readonly Dictionary<string, HealthCheckResponse.Types.ServingStatus> statusMap = + new Dictionary<string, HealthCheckResponse.Types.ServingStatus>(); /// <summary> - /// Sets the health status for given host and service. + /// Sets the health status for given service. /// </summary> - /// <param name="host">The host. Cannot be null.</param> /// <param name="service">The service. Cannot be null.</param> /// <param name="status">the health status</param> - public void SetStatus(string host, string service, HealthCheckResponse.Types.ServingStatus status) + public void SetStatus(string service, HealthCheckResponse.Types.ServingStatus status) { lock (myLock) { - statusMap[CreateKey(host, service)] = status; + statusMap[service] = status; } } /// <summary> - /// Clears health status for given host and service. + /// Clears health status for given service. /// </summary> - /// <param name="host">The host. Cannot be null.</param> /// <param name="service">The service. Cannot be null.</param> - public void ClearStatus(string host, string service) + public void ClearStatus(string service) { lock (myLock) { - statusMap.Remove(CreateKey(host, service)); + statusMap.Remove(service); } } /// <summary> - /// Clears statuses for all hosts and services. + /// Clears statuses for all services. /// </summary> public void ClearAll() { @@ -105,11 +103,10 @@ namespace Grpc.HealthCheck { lock (myLock) { - var host = request.Host; var service = request.Service; HealthCheckResponse.Types.ServingStatus status; - if (!statusMap.TryGetValue(CreateKey(host, service), out status)) + if (!statusMap.TryGetValue(service, out status)) { // TODO(jtattermusch): returning specific status from server handler is not supported yet. throw new RpcException(new Status(StatusCode.NotFound, "")); @@ -117,22 +114,5 @@ namespace Grpc.HealthCheck return Task.FromResult(new HealthCheckResponse { Status = status }); } } - - private static Key CreateKey(string host, string service) - { - return new Key(host, service); - } - - private struct Key - { - public Key(string host, string service) - { - this.Host = GrpcPreconditions.CheckNotNull(host); - this.Service = GrpcPreconditions.CheckNotNull(service); - } - - readonly string Host; - readonly string Service; - } } } |