code: @SuppressWarnings("unchecked")
    private void setupConnection(Address address, Connection connection, CompletableFuture<Connection> future) {
      LOGGER.debug("{} - Setting up connection to {}", id, address);
  
      this.connection = connection;
  
      connection.onClose(c -> {
        if (c.equals(this.connection)) {
          LOGGER.debug("{} - Connection closed", id);
          this.connection = null;
        }
      });
      connection.onException(c -> {
        if (c.equals(this.connection)) {
          LOGGER.debug("{} - Connection lost", id);
          this.connection = null;
        }
      });
  
      for (Map.Entry<Class<?>, Function> entry : handlers.entrySet()) {
        connection.handler(entry.getKey(), entry.getValue());
      }
  
      // When we first connect to a new server, first send a ConnectRequest to the server to establish
      // the connection with the server-side state machine.
      ConnectRequest request = ConnectRequest.builder()
        .withClientId(id)
        .build();
  
      LOGGER.trace("{} - Sending {}", id, request);
      connection.<ConnectRequest, ConnectResponse>sendAndReceive(request).whenComplete((r, e) -> handleConnectResponse(r, e, future));
    }
docs: Sets up the given connection.