protected synchronized TTransport connect(HiveConf conf) throws HiveSQLException, TTransportException {
    if (transport != null && transport.isOpen()) {
      transport.close();
    }

    String host = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST);
    int port = conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT);
    int maxThriftMessageSize = (int) conf.getSizeVar(HiveConf.ConfVars.HIVE_THRIFT_CLIENT_MAX_MESSAGE_SIZE);
    LOG.info("Connecting to {}:{} using a thrift max message of size: {}",
        host, port, maxThriftMessageSize);

    transport = HiveAuthUtils.getSocketTransport(host, port, 0, maxThriftMessageSize);
    ((TSocket) transport).setTimeout((int) conf.getTimeVar(HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT,
      TimeUnit.SECONDS) * 1000);
    try {
      ((TSocket) transport).getSocket().setKeepAlive(conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE));
    } catch (SocketException e) {
      LOG.error("Error setting keep alive to " + conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE), e);
    }

    String userName = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_USER);
    String passwd = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_PASSWORD);

    try {
      transport = PlainSaslHelper.getPlainTransport(userName, passwd, transport);
    } catch (SaslException e) {
      LOG.error("Error creating plain SASL transport", e);
    }

    TProtocol protocol = new TBinaryProtocol(transport);
    transport.open();
    base = new ThriftCLIServiceClient(new TCLIService.Client(protocol), conf);
    LOG.info("Connected!");
    return transport;
  }
RetryingThriftCLIServiceClient. Creates a proxy for a CLIServiceClient
implementation and retries calls to it on failure.
service/src/java/org/apache/hive/service/cli/thrift/RetryingThriftCLIServiceClient.java