// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/HealthCheckAwareClient.java
// public interface HealthCheckAwareClient
// {
//    /**
//     * List of healthchecks to execute to determine overall health.
//     */
//    List<HealthCheck> checks = new ArrayList<>();
// 
//    //
//    // Interface methods
//    //
// 
//    /**
//     * Add a new {@link HealthCheck} to be executed as part of the overall
//     * client health. HealthChecks will be executed in the order in which they
//     * are registered.
//     * @param check
//     */
//    default void registerCheck(HealthCheck check)
//    {
//       checks.add(check);
//    }
// 
//    /**
//     * Main method for determining client health. Default implementation is to
//     * simply execute all registered handlers and combine them into a single
//     * list of results.
//     * @return List of individual results.
//     */
//    default Map<String, HealthCheckResult> doAllChecks()
//    {
//       Map<String, HealthCheckResult> results = new TreeMap<>();
// 
//       for(HealthCheck check : checks)
//       {
//          results.put(check.getClass().getSimpleName(), check.doCheck());
//       }
// 
//       return results;
//    }
// }
// 
// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/HealthCheckResult.java
// public class HealthCheckResult
// {
//    /**
//     * State of the health check.
//     */
//    public Status status = Status.HEALTHY;
// 
//    /**
//     * Optional description to elaborate on the status enum.
//     */
//    public String description;
// 
//    /**
//     * Convenience constructor to set all required fields.
//     * @param status Status of the check.
//     */
//    public HealthCheckResult(Status status)
//    {
//       this.status = status;
//    }
// 
//    /**
//     * Convenience constructor to set all fields.
//     * @param status Status of the check.
//     * @param description Optional descriptipn to elaborate on the status.
//     */
//    public HealthCheckResult(Status status, String description)
//    {
//       this.status = status;
//       this.description = description;
//    }
// }
// 
// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/Status.java
// public enum Status
// {
//    HEALTHY,
//    IMPAIRED,
//    UNHEALTHY,
//    UNKNOWN
// }


import com.codahale.metrics.health.HealthCheck;
import com.homeadvisor.robusto.health.HealthCheckAwareClient;
import com.homeadvisor.robusto.health.HealthCheckResult;
import com.homeadvisor.robusto.health.Status;
import java.util.Map;
/*
 * Copyright 2016 HomeAdvisor, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.homeadvisor.robusto.health.codahale;



/**
 * Implementation of {@link HealthCheckAwareClient} that reports health using
 * Codahale's {@link HealthCheck}.
 */
public class CodahaleClientHealthCheck extends HealthCheck implements HealthCheckAwareClient
{
   @Override
   protected Result check()
   {
      //
      // Get the parent results first
      //

      boolean isUnhealthy = false;

      StringBuilder msg = new StringBuilder();

      try
      {
         Map<String, HealthCheckResult> results = doAllChecks();

         //
         // Convert results into Codahale objects. Any result that isnt HEALTHY
         // gets converted into a Codahale UNHEALTHY object.
         //

         for(Map.Entry<String, HealthCheckResult> entry : results.entrySet())
         {
            msg.append(entry.getKey())
// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/HealthCheckAwareClient.java
// public interface HealthCheckAwareClient
// {
//    /**
//     * List of healthchecks to execute to determine overall health.
//     */
//    List<HealthCheck> checks = new ArrayList<>();
// 
//    //
//    // Interface methods
//    //
// 
//    /**
//     * Add a new {@link HealthCheck} to be executed as part of the overall
//     * client health. HealthChecks will be executed in the order in which they
//     * are registered.
//     * @param check
//     */
//    default void registerCheck(HealthCheck check)
//    {
//       checks.add(check);
//    }
// 
//    /**
//     * Main method for determining client health. Default implementation is to
//     * simply execute all registered handlers and combine them into a single
//     * list of results.
//     * @return List of individual results.
//     */
//    default Map<String, HealthCheckResult> doAllChecks()
//    {
//       Map<String, HealthCheckResult> results = new TreeMap<>();
// 
//       for(HealthCheck check : checks)
//       {
//          results.put(check.getClass().getSimpleName(), check.doCheck());
//       }
// 
//       return results;
//    }
// }
// 
// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/HealthCheckResult.java
// public class HealthCheckResult
// {
//    /**
//     * State of the health check.
//     */
//    public Status status = Status.HEALTHY;
// 
//    /**
//     * Optional description to elaborate on the status enum.
//     */
//    public String description;
// 
//    /**
//     * Convenience constructor to set all required fields.
//     * @param status Status of the check.
//     */
//    public HealthCheckResult(Status status)
//    {
//       this.status = status;
//    }
// 
//    /**
//     * Convenience constructor to set all fields.
//     * @param status Status of the check.
//     * @param description Optional descriptipn to elaborate on the status.
//     */
//    public HealthCheckResult(Status status, String description)
//    {
//       this.status = status;
//       this.description = description;
//    }
// }
// 
// Path: robusto-core/src/main/java/com/homeadvisor/robusto/health/Status.java
// public enum Status
// {
//    HEALTHY,
//    IMPAIRED,
//    UNHEALTHY,
//    UNKNOWN
// }


// Path: robusto-codahale/src/main/java/com/homeadvisor/robusto/health/codahale/CodahaleClientHealthCheck.java
import com.codahale.metrics.health.HealthCheck;
import com.homeadvisor.robusto.health.HealthCheckAwareClient;
import com.homeadvisor.robusto.health.HealthCheckResult;
import com.homeadvisor.robusto.health.Status;
import java.util.Map;

/*
 * Copyright 2016 HomeAdvisor, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.homeadvisor.robusto.health.codahale;



/**
 * Implementation of {@link HealthCheckAwareClient} that reports health using
 * Codahale's {@link HealthCheck}.
 */
public class CodahaleClientHealthCheck extends HealthCheck implements HealthCheckAwareClient
{
   @Override
   protected Result check()
   {
      //
      // Get the parent results first
      //

      boolean isUnhealthy = false;

      StringBuilder msg = new StringBuilder();

      try
      {
         Map<String, HealthCheckResult> results = doAllChecks();

         //
         // Convert results into Codahale objects. Any result that isnt HEALTHY
         // gets converted into a Codahale UNHEALTHY object.
         //

         for(Map.Entry<String, HealthCheckResult> entry : results.entrySet())
         {
            msg.append(entry.getKey())
                  .append(" [").append(entry.getValue().status).append("]")