@Override
public AttributeList getAttributes(final String[] attributes) {
final AttributeList result = new AttributeList();
if ( attributes != null ) {
HealthCheckExecutionResult hcResult = null;
for(final String key : attributes) {
final Object defaultValue = this.defaultAttributes.get(key);
if ( defaultValue != null ) {
result.add(new Attribute(key, defaultValue));
} else {
// we assume that a valid attribute name is used
// which is requesting a hc result
if ( hcResult == null ) {
hcResult = this.getHealthCheckResult();
}
if ( HC_OK_ATTRIBUTE_NAME.equals(key) ) {
result.add(new Attribute(key, hcResult.getHealthCheckResult().isOk()));
} else if ( HC_LOG_ATTRIBUTE_NAME.equals(key) ) {
try {
result.add(new Attribute(key, logData(hcResult.getHealthCheckResult())));
} catch ( final OpenDataException ignore ) {
// we ignore this and simply don't add the attribute
}
} else if ( HC_STATUS_ATTRIBUTE_NAME.equals(key) ) {
result.add(new Attribute(key, hcResult.getHealthCheckResult().getStatus().toString()));
} else if ( HC_ELAPSED_TIMED_ATTRIBUTE_NAME.equals(key) ) {
result.add(new Attribute(key, hcResult.getElapsedTimeInMs()));
} else if ( HC_FINISHED_AT_ATTRIBUTE_NAME.equals(key) ) {
result.add(new Attribute(key, hcResult.getFinishedAt()));
} else if ( HC_TIMED_OUT_ATTRIBUTE_NAME.equals(key) ) {
result.add(new Attribute(key, hcResult.hasTimedOut()));
}
}
}
}