package io.vertx.ext.dropwizard.impl;
import com.codahale.metrics.MetricRegistry;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.ServerWebSocket;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.spi.metrics.HttpServerMetrics;
import io.vertx.core.spi.observability.HttpRequest;
import io.vertx.core.spi.observability.HttpResponse;
import io.vertx.ext.dropwizard.Match;
import java.util.List;
class HttpServerMetricsImpl extends HttpMetricsImpl implements HttpServerMetrics<HttpRequestMetric, WebSocketMetric, Long> {
private final Matcher uriMatcher;
HttpServerMetricsImpl(MetricRegistry registry, String baseName, List<Match> monitoredUris, SocketAddress localAddress) {
super(registry, baseName, localAddress);
uriMatcher = new Matcher(monitoredUris);
}
@Override
public HttpRequestMetric requestBegin(Long socketMetric, HttpRequest request) {
return new HttpRequestMetric(request.method(), request.uri());
}
@Override
public void responseBegin(HttpRequestMetric requestMetric, HttpResponse response) {
requestMetric.response = response;
}
@Override
public WebSocketMetric connected(Long socketMetric, HttpRequestMetric requestMetric, ServerWebSocket serverWebSocket) {
return createWebSocketMetric();
}
@Override
public void responseEnd(HttpRequestMetric requestMetric, long bytesWritten) {
end(requestMetric, requestMetric.response.statusCode(), uriMatcher);
}
@Override
public void requestReset(HttpRequestMetric requestMetric) {
}
@Override
public HttpRequestMetric responsePushed(Long socketMetric, HttpMethod method, String uri, HttpResponse response) {
return new HttpRequestMetric(method, uri);
}
@Override
public void disconnected(WebSocketMetric serverWebSocketMetric) {
disconnect(serverWebSocketMetric);
}
}