super.open(); } catch (RuntimeException e) { log.log(Level.SEVERE, "failed org.eclipse.jetty.server.Server open() with port " + getPort()); throw e; channelOpenedByActivator.socket().setReuseAddress(getReuseAddress()); int localPort = channelOpenedByActivator.socket().getLocalPort(); try { uglySetLocalPort(localPort); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException("Could not set local port.", e); throw new IOException("Server channel not bound"); addBean(channelOpenedByActivator); channelOpenedByActivator.configureBlocking(true); addBean(channelOpenedByActivator); uglySetChannel(channelOpenedByActivator); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException("Could not set server channel.", e);
public Metric.Context getRequestMetricContext(HttpServletRequest request) { String method = request.getMethod(); return requestMetricContextCache.computeIfAbsent(method, ignored -> { Map<String, Object> dimensions = createConnectorDimensions(listenPort, connectorName); dimensions.put(JettyHttpServer.Metrics.METHOD_DIMENSION, method); return metric.createContext(dimensions); }); }
private static Metric.Context getMetricContext(HttpServletRequest request) { return JDiscServerConnector.fromRequest(request).getRequestMetricContext(request); }
private void setConnectorMetrics(JDiscServerConnector connector) { ServerConnectionStatistics statistics = connector.getStatistics(); metric.set(Metrics.NUM_CONNECTIONS, statistics.getConnectionsTotal(), connector.getConnectorMetricContext()); metric.set(Metrics.NUM_OPEN_CONNECTIONS, statistics.getConnections(), connector.getConnectorMetricContext()); metric.set(Metrics.NUM_CONNECTIONS_OPEN_MAX, statistics.getConnectionsMax(), connector.getConnectorMetricContext()); metric.set(Metrics.CONNECTION_DURATION_MAX, statistics.getConnectionDurationMax(), connector.getConnectorMetricContext()); metric.set(Metrics.CONNECTION_DURATION_MEAN, statistics.getConnectionDurationMean(), connector.getConnectorMetricContext()); metric.set(Metrics.CONNECTION_DURATION_STD_DEV, statistics.getConnectionDurationStdDev(), connector.getConnectorMetricContext()); }
JDiscServerConnector(ConnectorConfig config, Metric metric, Server server, ServerSocketChannel channelOpenedByActivator, ConnectionFactory... factories) { super(server, factories); this.channelOpenedByActivator = channelOpenedByActivator; this.tcpKeepAlive = config.tcpKeepAliveEnabled(); this.tcpNoDelay = config.tcpNoDelay(); this.metric = metric; this.connectorName = config.name(); this.listenPort = config.listenPort(); this.metricCtx = metric.createContext(createConnectorDimensions(listenPort, connectorName)); this.statistics = new ServerConnectionStatistics(); addBean(statistics); ConnectorConfig.Throttling throttlingConfig = config.throttling(); if (throttlingConfig.enabled()) { new ConnectionThrottler(this, throttlingConfig).registerWithConnector(); } }
private HttpRequestDispatch createRequestDispatch(HttpServletRequest request, HttpServletResponse response) { try { final AccessLogEntry accessLogEntry = null; // Not used in this context. return new HttpRequestDispatch(jDiscContext, accessLogEntry, getConnector(request).getRequestMetricContext(request), request, response); } catch (IOException e) { throw throwUnchecked(e); } }
public ServerConnector createConnector(final Metric metric, final Server server, final ServerSocketChannel ch) { ServerConnector connector; if (connectorConfig.ssl().enabled()) { connector = new JDiscServerConnector(connectorConfig, metric, server, ch, newSslConnectionFactory(), newHttpConnectionFactory()); } else { connector = new JDiscServerConnector(connectorConfig, metric, server, ch, newHttpConnectionFactory()); } connector.setPort(connectorConfig.listenPort()); connector.setName(connectorConfig.name()); connector.setAcceptQueueSize(connectorConfig.acceptQueueSize()); connector.setReuseAddress(connectorConfig.reuseAddress()); connector.setIdleTimeout((long)(connectorConfig.idleTimeout() * 1000.0)); connector.setStopTimeout((long)(connectorConfig.stopTimeout() * 1000.0)); return connector; }