private void reportRequestBegin() { if (conn.metrics != null) { metric = conn.metrics.requestBegin(conn.metric(), this); } }
private void reportResponseComplete() { if (metrics != null) { reportBytesWritten(bytesWritten); if (requestFailed) { metrics.requestReset(responseInProgress.metric()); requestFailed = false; } else { metrics.responseEnd(responseInProgress.metric(), responseInProgress.response()); } bytesWritten = 0; } }
private void reportResponseBegin() { if (conn.metrics != null) { conn.metrics.responseBegin(requestMetric, this); } }
ServerWebSocketImpl createWebSocket(HttpServerRequestImpl request) { if (ws != null) { return ws; } if (!(request.getRequest() instanceof FullHttpRequest)) { throw new IllegalStateException(); } FullHttpRequest nettyReq = (FullHttpRequest) request.getRequest(); WebSocketServerHandshaker handshaker = createHandshaker(nettyReq); if (handshaker == null) { return null; } Function<ServerWebSocketImpl, String> f = ws -> { handshaker.handshake(chctx.channel(), nettyReq); // remove compressor as its not needed anymore once connection was upgraded to websockets ChannelHandler handler = chctx.pipeline().get(HttpChunkContentCompressor.class); if (handler != null) { chctx.pipeline().remove(handler); } ws.registerHandler(vertx.eventBus()); return handshaker.selectedSubprotocol(); }; ws = new ServerWebSocketImpl(vertx, request.uri(), request.path(), request.query(), request.headers(), this, handshaker.version() != WebSocketVersion.V00, f, options.getMaxWebsocketFrameSize(), options.getMaxWebsocketMessageSize()); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(metric(), request.metric(), ws)); } return ws; }
private void reportRequestReset() { if (conn.metrics != null) { conn.metrics.requestReset(metric); } }
@Override protected void handleClosed() { if (metrics != null) { metrics.responseEnd(responseInProgress.metric(), responseInProgress.response()); } connectionMap.remove(chctx.channel()); super.handleClosed(); }
void complete() { synchronized (Http2ServerConnection.this) { response = new Http2ServerResponseImpl(Http2ServerConnection.this, this, method, true, contentEncoding, null); if (METRICS_ENABLED && metrics != null) { response.metric(metrics.responsePushed(conn.metric(), method, uri, response)); } completionHandler.complete(response); } } }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
protected void handleClosed() { HttpServerRequestImpl responseInProgress; HttpServerRequestImpl requestInProgress; ServerWebSocketImpl ws; synchronized (this) { ws = this.ws; requestInProgress = this.requestInProgress; responseInProgress = this.responseInProgress; if (METRICS_ENABLED && metrics != null && ws != null) { metrics.disconnected(ws.getMetric()); ws.setMetric(null); } } if (requestInProgress != null) { requestInProgress.handleException(CLOSED_EXCEPTION); } if (responseInProgress != null && responseInProgress != requestInProgress) { responseInProgress.handleException(CLOSED_EXCEPTION); } if (ws != null) { ws.handleClosed(); } super.handleClosed(); }
metrics); if (metrics != null) { holder2.context.executeFromIO(v -> conn.metric(metrics.connected(conn.remoteAddress(), conn.remoteName())));
private void reportRequestReset() { if (conn.metrics != null) { conn.metrics.requestReset(metric); } }
@Override protected void handleClosed() { if (metrics != null) { metrics.responseEnd(responseInProgress.metric(), responseInProgress.response()); } connectionMap.remove(chctx.channel()); super.handleClosed(); }
void complete() { synchronized (Http2ServerConnection.this) { response = new Http2ServerResponseImpl(Http2ServerConnection.this, this, method, true, contentEncoding, null); if (METRICS_ENABLED && metrics != null) { response.metric(metrics.responsePushed(conn.metric(), method, uri, response)); } completionHandler.complete(response); } } }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
protected void handleClosed() { HttpServerRequestImpl responseInProgress; HttpServerRequestImpl requestInProgress; ServerWebSocketImpl ws; synchronized (this) { ws = this.ws; requestInProgress = this.requestInProgress; responseInProgress = this.responseInProgress; if (METRICS_ENABLED && metrics != null && ws != null) { metrics.disconnected(ws.getMetric()); ws.setMetric(null); } } if (requestInProgress != null) { requestInProgress.handleException(CLOSED_EXCEPTION); } if (responseInProgress != null && responseInProgress != requestInProgress) { responseInProgress.handleException(CLOSED_EXCEPTION); } if (ws != null) { ws.handleClosed(); } super.handleClosed(); }
void handleClose() { Handler<Throwable> exceptionHandler; Handler<Void> endHandler; Handler<Void> closeHandler; synchronized (conn) { boolean failed = !ended; ended = true; if (METRICS_ENABLED && metric != null) { // Null in case of push response : handle this case conn.reportBytesWritten(bytesWritten); if (failed) { conn.metrics().requestReset(metric); } else { conn.metrics().responseEnd(metric, this); } } exceptionHandler = failed ? this.exceptionHandler : null; endHandler = failed ? this.endHandler : null; closeHandler = this.closeHandler; } if (exceptionHandler != null) { exceptionHandler.handle(ConnectionBase.CLOSED_EXCEPTION); } if (endHandler != null) { endHandler.handle(null); } if (closeHandler != null) { closeHandler.handle(null); } }
VertxHttp2ConnectionHandler<Http2ServerConnection> buildHttp2ConnectionHandler(HandlerHolder<HttpHandlers> holder) { VertxHttp2ConnectionHandler<Http2ServerConnection> handler = new VertxHttp2ConnectionHandlerBuilder<Http2ServerConnection>() .server(true) .useCompression(options.isCompressionSupported()) .useDecompression(options.isDecompressionSupported()) .compressionLevel(options.getCompressionLevel()) .initialSettings(options.getInitialSettings()) .connectionFactory(connHandler -> new Http2ServerConnection(holder.context, serverOrigin, connHandler, options, holder.handler.requestHandler, metrics)) .logEnabled(logEnabled) .build(); handler.addHandler(conn -> { connectionMap.put(conn.channel(), conn); if (metrics != null) { conn.metric(metrics.connected(conn.remoteAddress(), conn.remoteName())); } if (options.getHttp2ConnectionWindowSize() > 0) { conn.setWindowSize(options.getHttp2ConnectionWindowSize()); } if (holder.handler.connectionHandler != null) { holder.context.executeFromIO(v -> { holder.handler.connectionHandler.handle(conn); }); } }); handler.removeHandler(conn -> { connectionMap.remove(conn.channel()); }); return handler; }
public Http2ServerRequestImpl(Http2ServerConnection conn, Http2Stream stream, HttpServerMetrics metrics, String serverOrigin, Http2Headers headers, String contentEncoding, boolean writable, boolean streamEnded) { super(conn, stream, writable); this.serverOrigin = serverOrigin; this.headers = headers; this.streamEnded = streamEnded; String host = host(); if (host == null) { int idx = serverOrigin.indexOf("://"); host = serverOrigin.substring(idx + 3); } this.response = new Http2ServerResponseImpl(conn, this, method(), false, contentEncoding, host); if (METRICS_ENABLED && metrics != null) { response.metric(metrics.requestBegin(conn.metric(), this)); } }
private boolean checkSendHeaders(boolean end) { if (!headWritten) { if (headersEndHandler != null) { headersEndHandler.handle(null); } sanitizeHeaders(); if (Metrics.METRICS_ENABLED && metric != null) { conn.metrics().responseBegin(metric, this); } headWritten = true; headers.status(Integer.toString(status.code())); // Could be optimized for usual case ? stream.writeHeaders(headers, end); if (end) { ctx.flush(); } return true; } else { return false; } }
private void reportResponseComplete() { if (metrics != null) { reportBytesWritten(bytesWritten); if (requestFailed) { metrics.requestReset(responseInProgress.metric()); requestFailed = false; } else { metrics.responseEnd(responseInProgress.metric(), responseInProgress.response()); } bytesWritten = 0; } }