Package com.codahale.metrics.health
Class HealthCheck.Result
- java.lang.Object
-
- com.codahale.metrics.health.HealthCheck.Result
-
- Enclosing class:
- HealthCheck
public static class HealthCheck.Result extends Object
The result of aHealthCheckbeing run. It can be healthy (with an optional message and optional details) or unhealthy (with either an error message or a thrown exception and optional details).
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HealthCheck.ResultBuilderbuilder()Returns a newHealthCheck.ResultBuilderbooleanequals(Object o)Map<String,Object>getDetails()longgetDuration()Returns the duration in milliseconds that the healthcheck took to runThrowablegetError()Returns any exception for the result, ornullif the result has no exception.StringgetMessage()Returns any additional message for the result, ornullif the result has no message.longgetTime()Returns the time when the result was created, in milliseconds since EpochStringgetTimestamp()Returns the timestamp when the result was created as a formatted String.inthashCode()static HealthCheck.Resulthealthy()Returns a healthyHealthCheck.Resultwith no additional message.static HealthCheck.Resulthealthy(String message)Returns a healthyHealthCheck.Resultwith an additional message.static HealthCheck.Resulthealthy(String message, Object... args)Returns a healthyHealthCheck.Resultwith a formatted message.booleanisHealthy()Returnstrueif the result indicates the component is healthy;falseotherwise.voidsetDuration(long duration)Sets the duration in milliseconds.StringtoString()static HealthCheck.Resultunhealthy(String message)Returns an unhealthyHealthCheck.Resultwith the given message.static HealthCheck.Resultunhealthy(String message, Object... args)Returns an unhealthyHealthCheck.Resultwith a formatted message.static HealthCheck.Resultunhealthy(Throwable error)Returns an unhealthyHealthCheck.Resultwith the given error.
-
-
-
Method Detail
-
healthy
public static HealthCheck.Result healthy()
Returns a healthyHealthCheck.Resultwith no additional message.- Returns:
- a healthy
HealthCheck.Resultwith no additional message
-
healthy
public static HealthCheck.Result healthy(String message)
Returns a healthyHealthCheck.Resultwith an additional message.- Parameters:
message- an informative message- Returns:
- a healthy
HealthCheck.Resultwith an additional message
-
healthy
public static HealthCheck.Result healthy(String message, Object... args)
Returns a healthyHealthCheck.Resultwith a formatted message.Message formatting follows the same rules as
String.format(String, Object...).- Parameters:
message- a message format\\args- the arguments apply to the message format- Returns:
- a healthy
HealthCheck.Resultwith an additional message - See Also:
String.format(String, Object...)
-
unhealthy
public static HealthCheck.Result unhealthy(String message)
Returns an unhealthyHealthCheck.Resultwith the given message.- Parameters:
message- an informative message describing how the health check failed- Returns:
- an unhealthy
HealthCheck.Resultwith the given message
-
unhealthy
public static HealthCheck.Result unhealthy(String message, Object... args)
Returns an unhealthyHealthCheck.Resultwith a formatted message.Message formatting follows the same rules as
String.format(String, Object...).- Parameters:
message- a message formatargs- the arguments apply to the message format- Returns:
- an unhealthy
HealthCheck.Resultwith an additional message - See Also:
String.format(String, Object...)
-
unhealthy
public static HealthCheck.Result unhealthy(Throwable error)
Returns an unhealthyHealthCheck.Resultwith the given error.- Parameters:
error- an exception thrown during the health check- Returns:
- an unhealthy
HealthCheck.Resultwith the givenerror
-
builder
public static HealthCheck.ResultBuilder builder()
Returns a newHealthCheck.ResultBuilder- Returns:
- the
HealthCheck.ResultBuilder
-
isHealthy
public boolean isHealthy()
Returnstrueif the result indicates the component is healthy;falseotherwise.- Returns:
trueif the result indicates the component is healthy
-
getMessage
public String getMessage()
Returns any additional message for the result, ornullif the result has no message.- Returns:
- any additional message for the result, or
null
-
getError
public Throwable getError()
Returns any exception for the result, ornullif the result has no exception.- Returns:
- any exception for the result, or
null
-
getTimestamp
public String getTimestamp()
Returns the timestamp when the result was created as a formatted String.- Returns:
- a formatted timestamp
-
getTime
public long getTime()
Returns the time when the result was created, in milliseconds since Epoch- Returns:
- the time when the result was created
-
getDuration
public long getDuration()
Returns the duration in milliseconds that the healthcheck took to run- Returns:
- the duration
-
setDuration
public void setDuration(long duration)
Sets the duration in milliseconds. This will indicate the time it took to run the individual healthcheck- Parameters:
duration- The duration in milliseconds
-
-