private static void shutdownConnectionGracefullyIfThresholdReached(JDiscServerConnector connector, Request jettyRequest) {
        ConnectorConfig connectorConfig = connector.connectorConfig();
        int maxRequestsPerConnection = connectorConfig.maxRequestsPerConnection();
        Connection connection = RequestUtils.getConnection(jettyRequest);
        if (maxRequestsPerConnection > 0) {
            if (connection.getMessagesIn() >= maxRequestsPerConnection) {
                gracefulShutdown(connection);
            }
        }
        double maxConnectionLifeInSeconds = connectorConfig.maxConnectionLife();
        if (maxConnectionLifeInSeconds > 0) {
            long createdAt = connection.getCreatedTimeStamp();
            long tenPctVariance = connection.hashCode() % 10; // should be random enough, and must be consistent for a given connection
            Instant expiredAt = Instant.ofEpochMilli((long) (createdAt + maxConnectionLifeInSeconds * 10 * (100 - tenPctVariance)));
            boolean isExpired = Instant.now().isAfter(expiredAt);
            if (isExpired) {
                gracefulShutdown(connection);
            }
        }
    }
Implementation of a Jetty {@link Handler} that dispatches requests to JDisc's {@link com.yahoo.jdisc.handler.RequestHandler}.

@author bjorncs
container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JdiscDispatchingHandler.java