com.twitter.common.net.http.handlers
Class HealthHandler

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.twitter.common.net.http.handlers.HealthHandler
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class HealthHandler
extends javax.servlet.http.HttpServlet

A servlet that provides a crude mechanism for monitoring a service's health. If the servlet returns IS_HEALTHY then the containing service should be deemed healthy.

See Also:
Serialized Form

Field Summary
static String HEALTH_CHECKER_KEY
          A @Named binding key for the Healthz servlet health checker.
static String IS_HEALTHY
          The plain text response string this servlet returns in the body of its responses to health check requests when its containing service is healthy.
 
Constructor Summary
HealthHandler(ExceptionalSupplier<Boolean,?> healthChecker)
          Constructs a new Healthz that uses the given healthChecker to determine current health of the service for at the point in time of each GET request.
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEALTH_CHECKER_KEY

public static final String HEALTH_CHECKER_KEY
A @Named binding key for the Healthz servlet health checker.

See Also:
Constant Field Values

IS_HEALTHY

public static final String IS_HEALTHY
The plain text response string this servlet returns in the body of its responses to health check requests when its containing service is healthy.

See Also:
Constant Field Values
Constructor Detail

HealthHandler

@Inject
public HealthHandler(ExceptionalSupplier<Boolean,?> healthChecker)
Constructs a new Healthz that uses the given healthChecker to determine current health of the service for at the point in time of each GET request. The given healthChecker should return true if the service is healthy and false otherwise. If the healthChecker returns null or throws the service is considered unhealthy.

Parameters:
healthChecker - a supplier that is called to perform a health check
Method Detail

doGet

protected void doGet(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException