in protonj2-client/src/main/java/org/apache/qpid/protonj2/client/transport/netty4/TcpTransport.java [108:160]
public TcpTransport connect(String host, int port, TransportListener listener) throws IOException {
if (closed.get()) {
throw new IllegalStateException("Transport has already been closed");
}
if (listener == null) {
throw new IllegalArgumentException("A transport listener must be set before connection attempts.");
}
if (host == null || host.isEmpty()) {
throw new IllegalArgumentException("Transport host value cannot be null");
}
if (port < 0 && options.defaultTcpPort() < 0 && (sslOptions.sslEnabled() && sslOptions.defaultSslPort() < 0)) {
throw new IllegalArgumentException("Transport port value must be a non-negative int value or a default port configured");
}
this.host = host;
this.listener = listener;
if (port > 0) {
this.port = port;
} else {
if (sslOptions.sslEnabled()) {
this.port = sslOptions.defaultSslPort();
} else {
this.port = options.defaultTcpPort();
}
}
bootstrap.handler(new ChannelInitializer<>() {
@Override
public void initChannel(Channel transportChannel) throws Exception {
channel = transportChannel;
nettyAllocator = new Netty4ProtonBufferAllocator(channel.alloc());
configureChannel(transportChannel);
try {
listener.transportInitialized(TcpTransport.this);
} catch (Throwable initError) {
LOG.warn("Error during initialization of channel from Transport Listener");
handleTransportFailure(transportChannel, IOExceptionSupport.create(initError));
throw initError;
}
}
});
configureNetty(bootstrap, options);
bootstrap.connect(getHost(), getPort()).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
return this;
}