com.palantir.atlasdb.timelock.paxos.api.NamespaceLeadershipTakeoverServiceEndpoints Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timelock-api-undertow Show documentation
Show all versions of timelock-api-undertow Show documentation
Palantir open source project
package com.palantir.atlasdb.timelock.paxos.api;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
import com.palantir.conjure.java.undertow.lib.Deserializer;
import com.palantir.conjure.java.undertow.lib.Endpoint;
import com.palantir.conjure.java.undertow.lib.ReturnValueWriter;
import com.palantir.conjure.java.undertow.lib.Serializer;
import com.palantir.conjure.java.undertow.lib.TypeMarker;
import com.palantir.conjure.java.undertow.lib.UndertowRuntime;
import com.palantir.conjure.java.undertow.lib.UndertowService;
import com.palantir.tokens.auth.AuthHeader;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;
import io.undertow.util.Methods;
import io.undertow.util.PathTemplateMatch;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Generated;
@Generated("com.palantir.conjure.java.services.UndertowServiceHandlerGenerator")
public final class NamespaceLeadershipTakeoverServiceEndpoints implements UndertowService {
private final UndertowNamespaceLeadershipTakeoverService delegate;
private NamespaceLeadershipTakeoverServiceEndpoints(UndertowNamespaceLeadershipTakeoverService delegate) {
this.delegate = delegate;
}
public static UndertowService of(UndertowNamespaceLeadershipTakeoverService delegate) {
return new NamespaceLeadershipTakeoverServiceEndpoints(delegate);
}
@Override
public List endpoints(UndertowRuntime runtime) {
return ImmutableList.of(
new TakeoverEndpoint(runtime, delegate), new TakeoverNamespacesEndpoint(runtime, delegate));
}
private static final class TakeoverEndpoint implements HttpHandler, Endpoint, ReturnValueWriter {
private final UndertowRuntime runtime;
private final UndertowNamespaceLeadershipTakeoverService delegate;
private final Serializer serializer;
TakeoverEndpoint(UndertowRuntime runtime, UndertowNamespaceLeadershipTakeoverService delegate) {
this.runtime = runtime;
this.delegate = delegate;
this.serializer = runtime.bodySerDe().serializer(new TypeMarker() {}, this);
}
@Override
public void handleRequest(HttpServerExchange exchange) throws IOException {
AuthHeader authHeader = runtime.auth().header(exchange);
Map pathParams =
exchange.getAttachment(PathTemplateMatch.ATTACHMENT_KEY).getParameters();
String namespace = runtime.plainSerDe().deserializeString(pathParams.get("namespace"));
ListenableFuture result = delegate.takeover(authHeader, namespace);
runtime.async().register(result, this, exchange);
}
@Override
public void write(Boolean result, HttpServerExchange exchange) throws IOException {
serializer.serialize(result, exchange);
}
@Override
public HttpString method() {
return Methods.POST;
}
@Override
public String template() {
return "/tl/paxos/takeover/{namespace}";
}
@Override
public String serviceName() {
return "NamespaceLeadershipTakeoverService";
}
@Override
public String name() {
return "takeover";
}
@Override
public HttpHandler handler() {
return this;
}
}
private static final class TakeoverNamespacesEndpoint
implements HttpHandler, Endpoint, ReturnValueWriter> {
private final UndertowRuntime runtime;
private final UndertowNamespaceLeadershipTakeoverService delegate;
private final Deserializer> deserializer;
private final Serializer> serializer;
TakeoverNamespacesEndpoint(UndertowRuntime runtime, UndertowNamespaceLeadershipTakeoverService delegate) {
this.runtime = runtime;
this.delegate = delegate;
this.deserializer = runtime.bodySerDe().deserializer(new TypeMarker>() {}, this);
this.serializer = runtime.bodySerDe().serializer(new TypeMarker>() {}, this);
}
@Override
public void handleRequest(HttpServerExchange exchange) throws IOException {
AuthHeader authHeader = runtime.auth().header(exchange);
Set namespaces = deserializer.deserialize(exchange);
ListenableFuture> result = delegate.takeoverNamespaces(authHeader, namespaces);
runtime.async().register(result, this, exchange);
}
@Override
public void write(Set result, HttpServerExchange exchange) throws IOException {
serializer.serialize(result, exchange);
}
@Override
public HttpString method() {
return Methods.POST;
}
@Override
public String template() {
return "/tl/paxos/takeoverNamespaces";
}
@Override
public String serviceName() {
return "NamespaceLeadershipTakeoverService";
}
@Override
public String name() {
return "takeoverNamespaces";
}
@Override
public HttpHandler handler() {
return this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy