code: public void lockAndSwitchSecondary(Protocol newSecondaryProtocol) throws SQLException {
      if (secondaryProtocol != null && !secondaryProtocol.isClosed()) {
        secondaryProtocol.close();
      }
  
      //if asked to be on read only connection, switching to this new connection
      if (currentReadOnlyAsked || (urlParser.getOptions().failOnReadOnly && !currentReadOnlyAsked
          && isMasterHostFail())) {
        if (currentProtocol == null) {
          try {
            syncConnection(currentProtocol, newSecondaryProtocol);
          } catch (Exception e) {
            //Some error append during connection parameter synchronisation
          }
        }
        currentProtocol = newSecondaryProtocol;
      }
  
      //set new found connection as slave connection.
      this.secondaryProtocol = newSecondaryProtocol;
      if (urlParser.getOptions().assureReadOnly) {
        setSessionReadOnly(true, this.secondaryProtocol);
      }
  
      resetSecondaryFailoverData();
    }
docs: Use the parameter newSecondaryProtocol as new current secondary connection.
  
  @param newSecondaryProtocol new secondary connection
  @throws SQLException if an error occur during setting session read-only