netflix.karyon.transport.KaryonTransport Maven / Gradle / Ivy
package netflix.karyon.transport;
import io.reactivex.netty.contexts.RxContexts;
import io.reactivex.netty.protocol.http.server.HttpServer;
import io.reactivex.netty.protocol.http.server.HttpServerBuilder;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import netflix.karyon.transport.http.HttpRequestHandler;
/**
* A factory class for creating karyon transport servers which are created using
* RxNetty
*
* @author Nitesh Kant
*/
public final class KaryonTransport {
public static final String DEFAULT_REQUEST_ID_CTX_KEY = "X-Karyon-REQUEST_ID";
static {
RxContexts.useRequestIdContextKey(DEFAULT_REQUEST_ID_CTX_KEY);
}
private KaryonTransport() {
}
public static HttpServerBuilder newHttpServerBuilder(int port, RequestHandler router) {
return RxContexts.newHttpServerBuilder(port, new HttpRequestHandler(router), RxContexts.DEFAULT_CORRELATOR);
}
public static HttpServerBuilder newHttpServerBuilder(int port, HttpRequestHandler requestHandler) {
return RxContexts.newHttpServerBuilder(port, requestHandler, RxContexts.DEFAULT_CORRELATOR);
}
public static HttpServer newHttpServer(int port, RequestHandler router) {
return newHttpServerBuilder(port, router).build();
}
public static HttpServer newHttpServer(int port, HttpRequestHandler requestHandler) {
return newHttpServerBuilder(port, requestHandler).build();
}
/**
* Karyon
*
* @param name The name of the context key to be used as default.
*/
public static void useRequestIdContextKey(String name) {
RxContexts.useRequestIdContextKey(name);
}
}