code: public HandleErrorResult handleFailover(SQLException qe, Method method, Object[] args,
        Protocol protocol) throws Throwable {
      if (isExplicitClosed()) {
        throw new SQLException("Connection has been closed !");
      }
  
      //check that failover is due to kill command
      boolean killCmd = qe != null
          && qe.getSQLState() != null
          && qe.getSQLState().equals("70100")
          && 1927 == qe.getErrorCode();
  
      if (protocol != null) {
        if (protocol.mustBeMasterConnection()) {
          if (!protocol.isMasterConnection()) {
            logger.warn("SQL Primary node [{}, conn={}] is now in read-only mode. Exception : {}",
                this.currentProtocol.getHostAddress().toString(),
                this.currentProtocol.getServerThreadId(),
                qe.getMessage());
          } else if (setMasterHostFail()) {
            logger.warn("SQL Primary node [{}, conn={}] connection fail. Reason : {}",
                this.currentProtocol.getHostAddress().toString(),
                this.currentProtocol.getServerThreadId(),
                qe.getMessage());
  
            addToBlacklist(protocol.getHostAddress());
          }
          return primaryFail(method, args, killCmd);
        } else {
          if (setSecondaryHostFail()) {
            logger.warn("SQL secondary node [{}, conn={}] connection fail. Reason : {}",
                this.currentProtocol.getHostAddress().toString(),
                this.currentProtocol.getServerThreadId(),
                qe.getMessage());
            addToBlacklist(protocol.getHostAddress());
          }
          return secondaryFail(method, args, killCmd);
        }
      } else {
        return primaryFail(method, args, killCmd);
      }
    }
docs: Handle failover on master or slave connection.
  
  @param method   called method
  @param args     methods parameters
  @param protocol current protocol
  @return HandleErrorResult object to indicate if query has finally been relaunched or exception
  if not.
  @throws Throwable if method with parameters doesn't exist