package io.dropwizard.metrics.jetty9;

import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.util.component.ContainerLifeCycle;

import io.dropwizard.metrics.Timer;

public class InstrumentedConnectionFactory extends ContainerLifeCycle implements ConnectionFactory {
    private final ConnectionFactory connectionFactory;
    private final Timer timer;

    public InstrumentedConnectionFactory(ConnectionFactory connectionFactory, Timer timer) {
        this.connectionFactory = connectionFactory;
        this.timer = timer;
        addBean(connectionFactory);
    }

    @Override
    public String getProtocol() {
        return connectionFactory.getProtocol();
    }

    @Override
    public Connection newConnection(Connector connector, EndPoint endPoint) {
        final Connection connection = connectionFactory.newConnection(connector, endPoint);
        connection.addListener(new Connection.Listener() {
            private Timer.Context context;

            @Override
            public void onOpened(Connection connection) {
                this.context = timer.time();
            }

            @Override
            public void onClosed(Connection connection) {
                context.stop();
            }
        });
        return connection;
    }
}

@@ -302,16 +302,155 @@
 Timer;%0A%0A
+import java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A
 public c
@@ -627,16 +627,49 @@
 r timer;
+%0A    private Method getProtocols;
 %0A%0A    pu
@@ -879,106 +879,747 @@
     
-%7D%0A%0A    @Override%0A    public String getProtocol() %7B%0A        return connectionFactory.getProtocol();
+    try %7B%0A            getProtocols = connectionFactory.getClass().getMethod(%22getProtocols%22);%0A        %7D catch (NoSuchMethodException ignore) %7B%0A            getProtocols = null;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public String getProtocol() %7B%0A        return connectionFactory.getProtocol();%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    public List%3CString%3E getProtocols() %7B%0A        try %7B%0A            return getProtocols != null ?%0A                    (List%3CString%3E) getProtocols.invoke(connectionFactory) :%0A                    Collections.%3CString%3EemptyList();%0A        %7D catch (IllegalAccessException %7C InvocationTargetException e) %7B%0A            throw new IllegalStateException(%22Unable to invoke %60connectionFactory#getProtocols%60%22, e);%0A        %7D
 %0A   

Add `getProtocols` method