com.netflix.karyon.transport.http.health.HealthCheckEndpoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karyon-governator Show documentation
Show all versions of karyon-governator Show documentation
karyon-governator developed by Netflix
The newest version!
package com.netflix.karyon.transport.http.health;
import com.netflix.karyon.health.HealthCheckHandler;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.reactivex.netty.protocol.http.server.HttpServerRequest;
import io.reactivex.netty.protocol.http.server.HttpServerResponse;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import rx.Observable;
import javax.inject.Inject;
/**
* An implementation of {@link RequestHandler} to provide health status over HTTP.
*
* This endpoint does NOT validate whether the passed request URI is actually of healthcheck or not. It assumes
* that it is used by a higher level router that makes appropriate decisions of which handler to call based on the URI.
*
* @author Nitesh Kant
*/
public class HealthCheckEndpoint implements RequestHandler {
private final HealthCheckHandler healthCheckHandler;
@Inject
public HealthCheckEndpoint(HealthCheckHandler healthCheckHandler) {
this.healthCheckHandler = healthCheckHandler;
}
@Override
public Observable handle(HttpServerRequest request, HttpServerResponse response) {
int httpStatus = healthCheckHandler.getStatus();
response.setStatus(HttpResponseStatus.valueOf(httpStatus));
return response.close();
}
}