Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Add getProtocols method" #1038

Merged
merged 2 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,21 @@
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.util.component.ContainerLifeCycle;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

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

public InstrumentedConnectionFactory(ConnectionFactory connectionFactory, Timer timer) {
this.connectionFactory = connectionFactory;
this.timer = timer;
addBean(connectionFactory);
try {
getProtocols = connectionFactory.getClass().getMethod("getProtocols");
} catch (NoSuchMethodException ignore) {
getProtocols = null;
}
}

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

@SuppressWarnings("unchecked")
public List<String> getProtocols() {
try {
return getProtocols != null ?
(List<String>) getProtocols.invoke(connectionFactory) :
Collections.<String>emptyList();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Unable to invoke `connectionFactory#getProtocols`", e);
}
}

@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
final Connection connection = connectionFactory.newConnection(connector, endPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,43 @@
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.util.component.ContainerLifeCycle;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

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

public InstrumentedConnectionFactory(ConnectionFactory connectionFactory, Timer timer) {
this.connectionFactory = connectionFactory;
this.timer = timer;
addBean(connectionFactory);
try {
getProtocols = connectionFactory.getClass().getMethod("getProtocols");
} catch (NoSuchMethodException ignore) {
getProtocols = null;
}
}

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

@SuppressWarnings("unchecked")
public List<String> getProtocols() {
try {
return getProtocols != null ?
(List<String>) getProtocols.invoke(connectionFactory) :
Collections.<String>emptyList();
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Unable to invoke `connectionFactory#getProtocols`", e);
}
}

@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
final Connection connection = connectionFactory.newConnection(connector, endPoint);
Expand Down