@Override
  public String connect(InetSocketAddress address, int sendBufferSize, int receiveBufferSize, PortType portType)
      throws IOException {
    SocketChannel channel = SocketChannel.open();
    channel.configureBlocking(false);
    Socket socket = channel.socket();
    socket.setKeepAlive(true);
    socket.setSendBufferSize(sendBufferSize);
    socket.setReceiveBufferSize(receiveBufferSize);
    socket.setTcpNoDelay(true);
    try {
      channel.connect(address);
    } catch (UnresolvedAddressException e) {
      channel.close();
      throw new IOException("Can't resolve address: " + address, e);
    } catch (IOException e) {
      channel.close();
      throw e;
    }
    String connectionId = generateConnectionId(channel);
    SelectionKey key = channel.register(this.nioSelector, SelectionKey.OP_CONNECT);
    Transmission transmission;
    try {
      transmission = createTransmission(connectionId, key, address.getHostName(), address.getPort(), portType,
          SSLFactory.Mode.CLIENT);
    } catch (IOException e) {
      logger.error("IOException on transmission creation {}", e);
      channel.socket().close();
      channel.close();
      throw e;
    }
    key.attach(transmission);
    this.keyMap.put(connectionId, key);
    numActiveConnections.set(this.keyMap.size());
    return connectionId;
  }
Begin connecting to the given address and add the connection to this selector and returns an id that identifies
the connection
<p>
Note that this call only initiates the connection, which will be completed on a future {@link #poll(long)}
call. Check {@link #connected()} to see which (if any) connections have completed after a given poll call.
@param address The address to connect to
@param sendBufferSize The networkSend buffer size for the new connection
@param receiveBufferSize The receive buffer size for the new connection
@param portType {@link PortType} which represents the type of connection to establish
@return The id for the connection that was created
@throws IllegalStateException if there is already a connection for that id
@throws IOException if DNS resolution fails on the hostname or if the server is down
ambry-network/src/main/java/com/github/ambry/network/Selector.java