code: @Override
    public boolean isValid(int timeout) throws SQLException {
  
      int initialTimeout = -1;
      try {
        initialTimeout = socket.getSoTimeout();
        if (initialTimeout == 0) {
          socket.setSoTimeout(timeout);
        }
        if (isMasterConnection() && !galeraAllowedStates.isEmpty()) {
          //this is a galera node.
          //checking not only that node is responding, but that galera state is allowed.
          Results results = new Results();
          executeQuery(true, results, CHECK_GALERA_STATE_QUERY);
          results.commandEnd();
          ResultSet rs = results.getResultSet();
  
          return rs != null && rs.next() && galeraAllowedStates.contains(rs.getString(2));
        }
  
        return ping();
  
      } catch (SocketException socketException) {
        logger.trace("Connection is not valid", socketException);
        connected = false;
        return false;
      } finally {
  
        //set back initial socket timeout
        try {
          if (initialTimeout != -1) {
            socket.setSoTimeout(initialTimeout);
          }
        } catch (SocketException socketException) {
          logger.warn("Could not set socket timeout back to " + initialTimeout, socketException);
          connected = false;
          //eat
        }
      }
    }
docs: Check that connection is valid. !! careful, timeout is in milliseconds,
  connection.isValid(timeout) is in seconds !!
  
  @param timeout timeout in milliseconds
  @return true is valid
  @throws SQLException if any error occur