*
* @param onConnect
* @throws Exception
*/
void createTransport(AmqpConnectOptions options, final Callback<Void> onConnect) throws Exception {
final TcpTransport transport;
if( options.getSslContext() !=null ) {
SslTransport ssl = new SslTransport();
ssl.setSSLContext(options.getSslContext());
transport = ssl;
} else {
transport = new TcpTransport();
}
URI host = options.getHost();
if( host.getPort() == -1 ) {
if( options.getSslContext()!=null ) {
host = new URI(host.getScheme()+"://"+host.getHost()+":5672");
} else {
host = new URI(host.getScheme()+"://"+host.getHost()+":5671");
}
}
transport.setBlockingExecutor(options.getBlockingExecutor());
transport.setDispatchQueue(options.getDispatchQueue());
transport.setMaxReadRate(options.getMaxReadRate());
transport.setMaxWriteRate(options.getMaxWriteRate());
transport.setReceiveBufferSize(options.getReceiveBufferSize());
transport.setSendBufferSize(options.getSendBufferSize());
transport.setTrafficClass(options.getTrafficClass());
transport.setUseLocalHost(options.isUseLocalHost());
transport.connecting(host, options.getLocalAddress());
transport.setTransportListener(new DefaultTransportListener(){
public void onTransportConnected() {
if(state==CONNECTING) {
state = CONNECTED;
onConnect.onSuccess(null);
transport.resumeRead();
}
}
public void onTransportFailure(final IOException error) {
if(state==CONNECTING) {
onConnect.onFailure(error);
}
}
});
transport.connecting(host, options.getLocalAddress());
bind(transport);
transport.start(NOOP);
}