Java Code Examples for org.apache.thrift.transport.TSocket

The following examples show how to use org.apache.thrift.transport.TSocket. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-specialagent   Source File: ThriftTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test(final MockTracer tracer) throws Exception {
  startNewThreadPoolServer();

  final TTransport transport = new TSocket("localhost", port);
  transport.open();

  final TProtocol protocol = new TBinaryProtocol(transport);

  final CustomService.Client client = new CustomService.Client(protocol);
  assertEquals("Say Good bye World", client.say("Good bye", "World"));

  await().atMost(5, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2));

  final List<MockSpan> mockSpans = tracer.finishedSpans();
  assertEquals(2, mockSpans.size());

  assertTrue(mockSpans.get(0).parentId() != 0 || mockSpans.get(1).parentId() != 0);
  assertNull(tracer.activeSpan());
}
 
Example 2
Source Project: java-specialagent   Source File: ThriftITest.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2);
  final TServerTransport serverTransport = new TServerSocket(port);
  final TServer server = startNewThreadPoolServer(serverTransport);

  final TTransport transport = new TSocket("localhost", port);
  transport.open();

  final TProtocol protocol = new TBinaryProtocol(transport);

  final CustomService.Client client = new CustomService.Client(protocol);
  final String res = client.say("one", "two");
  if (!"Say one two".equals(res))
    throw new AssertionError("ERROR: wrong result");

  TestUtil.checkSpan(latch, new ComponentSpanCount("java-thrift", 2, true));

  server.stop();
  transport.close();
}
 
Example 3
Source Project: jigsaw-payment   Source File: AbstractTransportPool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据rc的设置来确定创建什么类型的transport;
 *
 * @param instance
 * @return
 */
protected TTransport createNativeTransport(
        ServiceInstance<RpcPayload> instance) {
    TSocket socket = new TSocket(instance.getAddress(), instance.getPort());
    socket.setTimeout(socketTimeout);

    RpcPayload server = instance.getPayload();
    if ((server == null) || (server.getTransport() == null)
            || (server.getTransport().equals("socket"))) {
        return socket;
    } else if ("framed-transport".equals(server.getTransport())) {
        return new TFramedTransport(socket);
    }

    // for default, use TSocket;
    return socket;
}
 
Example 4
Source Project: drift   Source File: TestApacheThriftMethodInvoker.java    License: Apache License 2.0 6 votes vote down vote up
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
    try {
        TSocket socket = new TSocket(address.getHost(), address.getPort());
        socket.open();
        try {
            TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
            assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
        }
        finally {
            socket.close();
        }
    }
    catch (TException e) {
        throw new RuntimeException(e);
    }
    return 1;
}
 
Example 5
Source Project: RDFS   Source File: ClusterManagerAvailabilityChecker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Used for getting a client to the CoronaProxyJobTracker
 * @param conf
 * @return Returns a client to the CPJT
 * @throws IOException
 */
public static CoronaProxyJobTrackerService.Client
  getPJTClient(CoronaConf conf) throws IOException {
  InetSocketAddress address =
    NetUtils.createSocketAddr(conf.getProxyJobTrackerThriftAddress());
  TFramedTransport transport = new TFramedTransport(
    new TSocket(address.getHostName(), address.getPort()));
  CoronaProxyJobTrackerService.Client client =
    new CoronaProxyJobTrackerService.Client(new TBinaryProtocol(transport));
  try {
    transport.open();
  } catch (TException e) {
    LOG.info("Transport Exception: ", e);
  }
  return client;
}
 
Example 6
Source Project: jstorm   Source File: SaslTransportPlugin.java    License: Apache License 2.0 6 votes vote down vote up
public boolean process(final TProtocol inProt, final TProtocol outProt) throws TException {
    // populating request context
    ReqContext req_context = ReqContext.context();

    TTransport trans = inProt.getTransport();
    // Sasl transport
    TSaslServerTransport saslTrans = (TSaslServerTransport) trans;
    // remote address
    TSocket tsocket = (TSocket) saslTrans.getUnderlyingTransport();
    Socket socket = tsocket.getSocket();
    req_context.setRemoteAddress(socket.getInetAddress());

    // remote subject
    SaslServer saslServer = saslTrans.getSaslServer();
    String authId = saslServer.getAuthorizationID();
    Subject remoteUser = new Subject();
    remoteUser.getPrincipals().add(new User(authId));
    req_context.setSubject(remoteUser);

    // invoke service handler
    return wrapped.process(inProt, outProt);
}
 
Example 7
Source Project: RDFS   Source File: CoronaAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Turns on the Safe Mode if safeMode is true. Turns off the Safe Mode if
 * safeMode is false.
 * @param safeMode Is true if we want the Safe Mode to be on. false
 *                 otherwise.
 * @return 0 if successful.
 * @throws IOException
 */
private int setSafeMode(boolean safeMode) throws IOException {
  // Get the current configuration
  CoronaConf conf = new CoronaConf(getConf());

  InetSocketAddress address = NetUtils.createSocketAddr(conf
    .getClusterManagerAddress());
  TFramedTransport transport = new TFramedTransport(
    new TSocket(address.getHostName(), address.getPort()));
  ClusterManagerService.Client client = new ClusterManagerService.Client(
    new TBinaryProtocol(transport));

  try {
    transport.open();
    if (client.setSafeMode(safeMode)) {
      System.out.println("The safeMode is: " +
                          (safeMode ? "ON" : "OFF"));
    } else {
      System.err.println("Could not set the safeMode flag");
    }
  } catch (TException e) {
    throw new IOException(e);
  }

  return 0;
}
 
Example 8
@Override
public TProcessor getProcessor(TTransport transport) {
  try {
    if (transport instanceof TSocket) {
      Socket socket = ((TSocket) transport).getSocket();
      log.debug("Received a connection from ip: {}", socket.getInetAddress().getHostAddress());
    }
    CloseableIHMSHandler baseHandler = federatedHMSHandlerFactory.create();
    IHMSHandler handler = newRetryingHMSHandler(ExceptionWrappingHMSHandler.newProxyInstance(baseHandler), hiveConf,
        false);
    transportMonitor.monitor(transport, baseHandler);
    return new TSetIpAddressProcessor<>(handler);
  } catch (MetaException | ReflectiveOperationException | RuntimeException e) {
    throw new RuntimeException("Error creating TProcessor", e);
  }
}
 
Example 9
Source Project: rpcx-benchmark   Source File: AppClient.java    License: Apache License 2.0 6 votes vote down vote up
public static Greeter.Client[] createClients(String host, int n, BenchmarkMessage msg) throws TException {
    TTransport[] transport = new TTransport[n];
    Greeter.Client[] clients = new Greeter.Client[n];

    //warmup
    for (int i = 0; i < n; i++) {
        transport[i] = new TFramedTransport(new TSocket(host, 8972));
        transport[i].open();

        TProtocol protocol = new TBinaryProtocol(transport[i]);
        clients[i] =  new Greeter.Client(protocol);
        clients[i].say(msg);
    }

    return clients;
}
 
Example 10
Source Project: leaf-snowflake   Source File: rpcClient.java    License: Apache License 2.0 6 votes vote down vote up
public static void startClient(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TSocket(ip,port,timeout);
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	int i = 0;
	while(i < 2000000)
	{
		 client.getID("");
		 ++i;
	}

	transport.close();
}
 
Example 11
Source Project: suro   Source File: ConnectionPool.java    License: Apache License 2.0 6 votes vote down vote up
public void connect() throws Exception {
    TSocket socket = new TSocket(server.getHost(), server.getPort(), config.getConnectionTimeout());
    socket.getSocket().setTcpNoDelay(true);
    socket.getSocket().setKeepAlive(true);
    socket.getSocket().setSoLinger(true, 0);
    transport = new TFramedTransport(socket);
    transport.open();

    TProtocol protocol = new TBinaryProtocol(transport);

    client = new SuroServer.Client(protocol);
    ServiceStatus status = client.getStatus();
    if (status != ServiceStatus.ALIVE) {
        transport.close();
        throw new RuntimeException(server + " IS NOT ALIVE!!!");
    }
}
 
Example 12
Source Project: metacat   Source File: CatalogThriftEventHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ServerContext createContext(final TProtocol input, final TProtocol output) {
    final String userName = "metacat-thrift-interface";
    String clientHost = null; //requestContext.getHeaderString("X-Forwarded-For");
    final long requestThreadId = Thread.currentThread().getId();

    final TTransport transport = input.getTransport();
    if (transport instanceof TSocket) {
        final TSocket thriftSocket = (TSocket) transport;
        clientHost = thriftSocket.getSocket().getInetAddress().getHostAddress();
    }

    final CatalogServerRequestContext context = new CatalogServerRequestContext(
        userName,
        null,
        clientHost,
        null,
        "hive",
        requestThreadId
    );
    MetacatContextManager.setContext(context);
    return context;
}
 
Example 13
/**
 * 创建原始连接的方法
 * 
 * @throws ThriftConnectionPoolException
 *             创建连接出现问题时抛出该异常
 */
@SuppressWarnings("unchecked")
private void createConnection() throws ThriftConnectionPoolException {
	try {
		transport = new TSocket(host, port, connectionTimeOut);
		transport.open();
		TProtocol protocol = createTProtocol(transport);
		// 反射实例化客户端对象
		Constructor<? extends TServiceClient> clientConstructor = clientClass.getConstructor(TProtocol.class);
		client = (T) clientConstructor.newInstance(protocol);
		if (logger.isDebugEnabled()) {
			logger.debug("创建新连接成功:" + host + " 端口:" + port);
		}
	} catch (Exception e) {
		throw new ThriftConnectionPoolException("无法连接服务器:" + host + " 端口:" + port);
	}
}
 
Example 14
Source Project: zeppelin   Source File: RemoteInterpreterProcess.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteInterpreterProcess(int connectTimeout,
                                String intpEventServerHost,
                                int intpEventServerPort) {
  this.connectTimeout = connectTimeout;
  this.intpEventServerHost = intpEventServerHost;
  this.intpEventServerPort = intpEventServerPort;
  this.remoteClient = new PooledRemoteClient<Client>(() -> {
    TSocket transport = new TSocket(getHost(), getPort());
    try {
      transport.open();
    } catch (TTransportException e) {
      throw new IOException(e);
    }
    TProtocol protocol = new  TBinaryProtocol(transport);
    return new Client(protocol);
  });
}
 
Example 15
Source Project: RDFS   Source File: CoronaAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Persists the state of the ClusterManager
 * @return 0 if successful.
 * @throws IOException
 */
private int persistState() throws IOException {
  // Get the current configuration
  CoronaConf conf = new CoronaConf(getConf());

  InetSocketAddress address = NetUtils.createSocketAddr(conf
    .getClusterManagerAddress());
  TFramedTransport transport = new TFramedTransport(
    new TSocket(address.getHostName(), address.getPort()));
  ClusterManagerService.Client client = new ClusterManagerService.Client(
    new TBinaryProtocol(transport));

  try {
    transport.open();
    if (!client.persistState())  {
      System.err.println("Persisting Cluster Manager state failed. ");
    }
  } catch (TException e) {
    throw new IOException(e);
  }

  return 0;
}
 
Example 16
Source Project: learning-hadoop   Source File: CassandraConnection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Construct an CassandaraConnection with optional authentication.
 * 
 * @param host the host to connect to
 * @param port the port to use
 * @param username the username to authenticate with (may be null
 * for no authentication)
 * @param password the password to authenticate with (may be null
 * for no authentication)
 * @throws Exception if the connection fails
 */
public CassandraConnection(String host, int port,
    String username, String password, int timeout) throws Exception {
  TSocket socket = new TSocket(host, port);
  if (timeout > 0) {
    socket.setTimeout(timeout);
  }
  
  m_transport = new TFramedTransport(socket);
  TProtocol protocol = new TBinaryProtocol(m_transport);
  m_client = new Cassandra.Client(protocol);      
  m_transport.open();
  
  if (!Const.isEmpty(username) && !Const.isEmpty(password)) {
    Map<String, String> creds = new HashMap<String, String>();
    creds.put("username", username);
    creds.put("password", password);
    m_client.login(new AuthenticationRequest(creds));
  }
}
 
Example 17
Source Project: hbase   Source File: TestThriftHBaseServiceHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify that thrift2 client calling thrift server can get the thrift server type correctly.
 */
@Test
public void testGetThriftServerOneType() throws Exception {

  // start a thrift server
  HBaseThriftTestingUtility THRIFT_TEST_UTIL = new HBaseThriftTestingUtility();

  LOG.info("Starting HBase Thrift server One");
  THRIFT_TEST_UTIL.startThriftServer(UTIL.getConfiguration(), ThriftServerType.ONE);
  try (TTransport transport = new TSocket(InetAddress.getLocalHost().getHostName(),
      THRIFT_TEST_UTIL.getServerPort())){
    TProtocol protocol = new TBinaryProtocol(transport);
    // This is our thrift2 client.
    THBaseService.Iface client = new THBaseService.Client(protocol);
    // open the transport
    transport.open();
    assertEquals(TThriftServerType.ONE.name(), client.getThriftServerType().name());
  } finally {
    THRIFT_TEST_UTIL.stopThriftServer();
  }
}
 
Example 18
Source Project: hbase   Source File: TestThriftServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify that thrift client calling thrift2 server can get the thrift2 server type correctly.
 */
@Test
public void testGetThriftServerOneType() throws Exception {
  // start a thrift2 server
  HBaseThriftTestingUtility THRIFT_TEST_UTIL = new HBaseThriftTestingUtility();

  LOG.info("Starting HBase Thrift Server Two");
  THRIFT_TEST_UTIL.startThriftServer(UTIL.getConfiguration(), ThriftServerType.TWO);
  try (TTransport transport = new TSocket(InetAddress.getLocalHost().getHostName(),
      THRIFT_TEST_UTIL.getServerPort())){
    TProtocol protocol = new TBinaryProtocol(transport);
    // This is our thrift client.
    Hbase.Client client = new Hbase.Client(protocol);
    // open the transport
    transport.open();
    assertEquals(TThriftServerType.TWO.name(), client.getThriftServerType().name());
  } finally {
    THRIFT_TEST_UTIL.stopThriftServer();
  }
}
 
Example 19
Source Project: ThriftBook   Source File: MultiServiceClient.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws TException {
    TTransport trans = new TFramedTransport(new TSocket("localhost", 9090));
    TProtocol proto = new TJSONProtocol(trans);

    TMultiplexedProtocol proto_msg = new TMultiplexedProtocol(proto, "Message");
    Message.Client client_msg = new Message.Client(proto_msg);
    TMultiplexedProtocol proto_time = new TMultiplexedProtocol(proto, "ServerTime");
    ServerTime.Client client_time = new ServerTime.Client(proto_time);

    trans.open();
    String line;
    do {
        System.out.println("Message from server: " + client_msg.motd());
        System.out.println("Time at server: " + client_time.time_at_server((short)-1));
        System.out.println("Enter to continue, 'q' to quit: ");
        line = System.console().readLine();
    } while (0 != line.compareToIgnoreCase("q"));   
}
 
Example 20
Source Project: stratio-cassandra   Source File: TestRingCache.java    License: Apache License 2.0 6 votes vote down vote up
private void setup(String server, int port) throws Exception
{
    /* Establish a thrift connection to the cassandra instance */
    TSocket socket = new TSocket(server, port);
    System.out.println(" connected to " + server + ":" + port + ".");
    TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
    Cassandra.Client cassandraClient = new Cassandra.Client(binaryProtocol);
    socket.open();
    thriftClient = cassandraClient;
    String seed = DatabaseDescriptor.getSeeds().iterator().next().getHostAddress();
    conf = new Configuration();
    ConfigHelper.setOutputPartitioner(conf, DatabaseDescriptor.getPartitioner().getClass().getName());
    ConfigHelper.setOutputInitialAddress(conf, seed);
    ConfigHelper.setOutputRpcPort(conf, Integer.toString(DatabaseDescriptor.getRpcPort()));

}
 
Example 21
Source Project: onos   Source File: Bmv2PreControllerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private boolean doCreateClient(DeviceId deviceId, String thriftServerIp, Integer thriftServerPort) {
    SafeThriftClient.Options options = new SafeThriftClient.Options(numConnectionRetries, timeBetweenRetries);

    try {
        // Make the expensive call
        TTransport transport = new TSocket(thriftServerIp, thriftServerPort);

        TProtocol protocol = new TBinaryProtocol(transport);
        // Create a client for simple_pre service.
        SimplePreLAG.Client simplePreClient = new SimplePreLAG.Client(
                new TMultiplexedProtocol(protocol, THRIFT_SERVICE_NAME));

        SimplePreLAG.Iface safeSimplePreClient = SafeThriftClient.wrap(simplePreClient,
                                                                       SimplePreLAG.Iface.class,
                                                                       options);

        Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId, safeSimplePreClient);
        clients.put(deviceId, Pair.of(transport, client));
        return true;

    } catch (RuntimeException e) {
        log.warn("Failed to create Thrift client for BMv2 device. deviceId={}, cause={}", deviceId, e);
        return false;
    }
}
 
Example 22
Source Project: das   Source File: ServerSelector.java    License: Apache License 2.0 5 votes vote down vote up
static ClientObject getClientObject(String host, int port) throws TTransportException {
    TSocket transport = new TSocket(host, port);
    TFramedTransport ft = new TFramedTransport(transport);
    TBinaryProtocol protocol = new TBinaryProtocol(ft);
    transport.open();
    return new ClientObject(new DasService.Client(protocol), transport);
}
 
Example 23
Source Project: suro   Source File: HealthCheck.java    License: Apache License 2.0 5 votes vote down vote up
private SuroServer.Client getClient(String host, int port, int timeout) throws SocketException, TTransportException {
    TSocket socket = new TSocket(host, port, timeout);
    socket.getSocket().setTcpNoDelay(true);
    socket.getSocket().setKeepAlive(true);
    socket.getSocket().setSoLinger(true, 0);
    TTransport transport = new TFramedTransport(socket);
    transport.open();

    TProtocol protocol = new TBinaryProtocol(transport);

    return new SuroServer.Client(protocol);
}
 
Example 24
Source Project: luxun   Source File: AbstractClient.java    License: Apache License 2.0 5 votes vote down vote up
protected void connect() {
	long connectBackoffMs = 1;
	long beginTimeMs = System.currentTimeMillis();
	while(luxunClient == null && !shutdown) {
		try {
			TSocket socket = new TSocket(host, port, soTimeoutMs);
			transport = new TFramedTransport(socket);
			TProtocol protocol = new TBinaryProtocol(transport);
			luxunClient = new QueueService.Client(protocol);
			transport.open();
            logger.info("Connected to " + host + ":" + port + " for operating");
		} catch (TTransportException e) {
			disconnect();
			long endTimeMs = System.currentTimeMillis();
               if ((endTimeMs - beginTimeMs + connectBackoffMs) > connectTimeoutMs) {
                   logger.error(
                           "Connection attempt to " + host + ":" + port + " timing out after " + connectTimeoutMs + " ms",
                           e);
                   throw new ConnectionRefusedException(host + ":" + port, e);
               }
               logger.error(
                       "Connection attempt to " + host+ ":" + port + " failed, next attempt in " + connectBackoffMs + " ms",
                       e);
               try {
                   Thread.sleep(connectBackoffMs);
               } catch (InterruptedException e1) {
                   logger.warn(e1.getMessage());
                   Thread.currentThread().interrupt();
               }
               connectBackoffMs = Math.min(10 * connectBackoffMs, MaxConnectBackoffMs);
		}
	}
}
 
Example 25
Source Project: octo-rpc   Source File: OriginThriftTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Twitter.Iface getOriginThriftClient() throws TTransportException {
    transport = new TFramedTransport(new TSocket("localhost", serverPort));
    transport.open();
    TProtocol protocol = new TBinaryProtocol(transport);
    Twitter.Iface client = new Twitter.Client(protocol);
    return client;
}
 
Example 26
Source Project: incubator-iotdb   Source File: IoTDBConnection.java    License: Apache License 2.0 5 votes vote down vote up
private void openTransport() throws TTransportException {
  transport = new TFastFramedTransport(new TSocket(params.getHost(), params.getPort(),
      Config.connectionTimeoutInMs));
  if (!transport.isOpen()) {
    transport.open();
  }
}
 
Example 27
Source Project: incubator-iotdb   Source File: SyncClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void establishConnection(String serverIp, int serverPort) throws SyncConnectionException {
  transport = new TSocket(serverIp, serverPort, TIMEOUT_MS);
  TProtocol protocol = new TBinaryProtocol(transport);
  serviceClient = new SyncService.Client(protocol);
  try {
    if (!transport.isOpen()) {
      transport.open();
    }
  } catch (TTransportException e) {
    logger.error("Cannot connect to the receiver.");
    throw new SyncConnectionException(e);
  }
}
 
Example 28
Source Project: java-specialagent   Source File: ThriftTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void withError() throws Exception {
  TestUtil.setGlobalTracer(tracer);

  startNewThreadPoolServer();

  final TTransport transport = new TSocket("localhost", port);
  transport.open();

  final TProtocol protocol = new TBinaryProtocol(transport);
  CustomService.Client client = new CustomService.Client(protocol);

  try {
    assertEquals("Say Good bye", client.withError());
    fail();
  }
  catch (final Exception ignore) {
  }

  await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2));

  final List<MockSpan> mockSpans = tracer.finishedSpans();
  assertEquals(2, mockSpans.size());

  assertTrue(mockSpans.get(0).parentId() != 0 || mockSpans.get(1).parentId() != 0);

  assertNull(tracer.activeSpan());

  verify(tracer, times(2)).buildSpan(anyString());
  verify(tracer, times(1)).inject(any(SpanContext.class), any(Format.class), any());
}
 
Example 29
Source Project: jigsaw-payment   Source File: TProtobufProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private String getInetAddress(TProtocol in) {
	TTransport transport = in.getTransport();
	if (transport != null && transport instanceof TSocket) {
		Socket socket = ((TSocket) in.getTransport()).getSocket();
		return socket.getInetAddress().getHostAddress().replace('.', ':');
	} else {
		return UN_KNOWN_IP;
	}
}
 
Example 30
Source Project: iceberg   Source File: HiveTables.java    License: Apache License 2.0 5 votes vote down vote up
private ThriftHiveMetastore.Client getClient() {
  final URI metastoreUri = URI.create(MetastoreConf.getAsString(conf, THRIFT_URIS));
  final int socketTimeOut = (int) MetastoreConf.getTimeVar(conf, CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
  TTransport transport = new TSocket(metastoreUri.getHost(), metastoreUri.getPort(), socketTimeOut);
  try {
    transport.open();
  } catch (TTransportException e) {
    throw new RuntimeException("failed to open socket for " + metastoreUri + " with timeoutMillis " + socketTimeOut);
  }
  return new ThriftHiveMetastore.Client(new TBinaryProtocol(transport));
}