private static OverthereConnection buildConnection(String protocol, ConnectionOptions options, AddressPortMapper mapper) {
final Class<? extends OverthereConnectionBuilder> connectionBuilderClass = protocols.get().get(protocol);
try {
final Constructor<? extends OverthereConnectionBuilder> constructor = connectionBuilderClass.getConstructor(String.class, ConnectionOptions.class, AddressPortMapper.class);
OverthereConnectionBuilder connectionBuilder = constructor.newInstance(protocol, options, mapper);
if (!(connectionBuilder instanceof LocalConnection)) {
logger.info("Connecting to {}", connectionBuilder);
} else {
logger.debug("Connecting to {}", connectionBuilder);
}
OverthereConnection connection = connectionBuilder.connect();
logger.trace("Connected to {}", connection);
return connection;
} catch (NoSuchMethodException exc) {
throw new IllegalStateException(connectionBuilderClass + " does not have a constructor that takes in a String and ConnectionOptions.", exc);