All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.karyon.transport.http.health.HealthCheckEndpoint Maven / Gradle / Ivy

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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy