code: public void lockAndSwitchMaster(Protocol newMasterProtocol)
        throws ReconnectDuringTransactionException {
      if (masterProtocol != null && !masterProtocol.isClosed()) {
        masterProtocol.close();
      }
  
      if (!currentReadOnlyAsked || isSecondaryHostFail()) {
        //actually on a secondary read-only because master was unknown.
        //So select master as currentConnection
        if (currentProtocol != null) {
          try {
            syncConnection(currentProtocol, newMasterProtocol);
          } catch (Exception e) {
            //Some error append during connection parameter synchronisation
          }
        }
        //switching current connection to master connection
        currentProtocol = newMasterProtocol;
      }
  
      boolean inTransaction = this.masterProtocol != null && this.masterProtocol.inTransaction();
      this.masterProtocol = newMasterProtocol;
      resetMasterFailoverData();
      if (inTransaction) {
        //master connection was down, so has been change for a new active connection
        //problem was there was an active connection -> must throw exception so client known it
        throw new ReconnectDuringTransactionException(
            "Connection reconnect automatically during an active transaction", 1401, "25S03");
      }
    }
docs: Use the parameter newMasterProtocol as new current master connection.
  
  <i>Lock must be set</i>
  
  @param newMasterProtocol new master connection
  @throws ReconnectDuringTransactionException if there was an active transaction.