List of usage examples for org.apache.thrift.transport TSocket setTimeout
public void setTimeout(int timeout)
From source file:backtype.storm.security.auth.ThriftClient.java
License:Apache License
public synchronized void reconnect() { close();/*from w ww. jav a 2s .com*/ try { TSocket socket = new TSocket(_host, _port); if (_timeout != null) { socket.setTimeout(_timeout); } //locate login configuration Configuration login_conf = AuthUtils.GetConfiguration(_conf); //construct a transport plugin ITransportPlugin transportPlugin = AuthUtils.GetTransportPlugin(_type, _conf, login_conf); final TTransport underlyingTransport = socket; //TODO get this from type instead of hardcoding to Nimbus. //establish client-server transport via plugin //do retries if the connect fails TBackoffConnect connectionRetry = new TBackoffConnect( Utils.getInt(_conf.get(Config.STORM_NIMBUS_RETRY_TIMES)), Utils.getInt(_conf.get(Config.STORM_NIMBUS_RETRY_INTERVAL)), Utils.getInt(_conf.get(Config.STORM_NIMBUS_RETRY_INTERVAL_CEILING))); _transport = connectionRetry.doConnectWithRetry(transportPlugin, underlyingTransport, _host); } catch (IOException ex) { throw new RuntimeException(ex); } _protocol = null; if (_transport != null) { _protocol = new TBinaryProtocol(_transport); } }
From source file:cn.lhfei.spark.hive.HiveThriftClient.java
License:Apache License
public static void main(String[] args) { try {// w w w . j a v a2 s . co m TSocket transport = new TSocket("10.58.62.142", 10003); transport.setTimeout(999999999); TBinaryProtocol protocol = new TBinaryProtocol(transport); Client client = new ThriftHive.Client(protocol); transport.open(); String hql = "select c.dt,sum(c.num),count(distinct c.imei) from (select count(1) as num,imei,dt from data_sum.sum_sdk_phone_event_day where dt='20151022' and app_name='Wallpaper' and widget_id='YL' and event_id='expose' group by dt,imei union all select count(1) as num,props['imei'] as imei,dt from data_sum.sum_sdk_phone_event_day where dt=20151022 and app_name='Wallpaper' and widget_id='YL' and event_id='expose' and imei='-' group by dt,props['imei']) c join (select a.dt,a.imei from (select dt,imei,cast(from_unixtime(cast(substr(activation_halfhour_time,0,10) as bigint),'yyyyMMdd') as string) time from data_sum.sum_phone_source_day where dt='20151022') a where a.time<=a.dt group by a.dt,a.imei) d on c.imei=d.imei where c.dt=d.dt group by c.dt"; client.execute(hql); List<String> result = client.fetchAll(); for (String row : result) { log.info(row); } /*client.execute("select count(*) from data_sum.sum_sdk_phone_app_day where dt='20151022'"); String length = client.fetchOne(); log.info("Count: [{}]", length);*/ transport.close(); } catch (TTransportException e) { e.printStackTrace(); } catch (HiveServerException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } }
From source file:cn.lhfei.spark.hive.ThriftSocketClient.java
License:Apache License
public static void main(String[] args) { try {// w w w. j a va 2 s . com TSocket transport = new TSocket("10.154.29.150", 10002); transport.setTimeout(999999999); TBinaryProtocol protocol = new TBinaryProtocol(transport); TCLIService.Client client = new TCLIService.Client(protocol); transport.open(); TOpenSessionReq openReq = new TOpenSessionReq(); TOpenSessionResp openResp = client.OpenSession(openReq); TSessionHandle sessHandle = openResp.getSessionHandle(); TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, "SELECT * FROM temp.uuid_count limit 10;"); TExecuteStatementResp execResp = client.ExecuteStatement(execReq); TOperationHandle stmtHandle = execResp.getOperationHandle(); TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle, TFetchOrientation.FETCH_FIRST, 1); TFetchResultsResp resultsResp = client.FetchResults(fetchReq); TRowSet resultsSet = resultsResp.getResults(); List<TRow> resultRows = resultsSet.getRows(); for (TRow resultRow : resultRows) { resultRow.toString(); } TCloseOperationReq closeReq = new TCloseOperationReq(); closeReq.setOperationHandle(stmtHandle); client.CloseOperation(closeReq); TCloseSessionReq closeConnectionReq = new TCloseSessionReq(sessHandle); client.CloseSession(closeConnectionReq); transport.close(); } catch (TException e) { e.printStackTrace(); } }
From source file:com.cloudera.recordservice.core.RecordServiceWorkerClient.java
License:Apache License
/** * Sleeps for retrySleepMs_ and reconnects to the worker. Returns * true if the connection was established. * TODO: why does this behave so differently than the Planner implementation. *///from w w w .j av a 2 s .co m private boolean waitAndReconnect() { sleepForRetry(); try { protocol_.getTransport().open(); TSocket socket = ThriftUtils.getSocketTransport(protocol_.getTransport()); socket.setTimeout(connectionTimeoutMs_); workerClient_ = new RecordServiceWorker.Client(protocol_); socket.setTimeout(rpcTimeoutMs_); return true; } catch (TTransportException e) { return false; } }
From source file:com.facebook.nifty.server.TestPlainClient.java
License:Apache License
@Test public void testPlainUnframedClient() throws Exception { try (ScopedNiftyServer server = makeServer()) { TSocket socket = new TSocket("localhost", server.getPort()); socket.open();/*from w w w .java 2s .c om*/ socket.setTimeout(1000); TBinaryProtocol protocol = new TBinaryProtocol(socket); scribe.Client client = new scribe.Client(protocol); LogEntry entry = new LogEntry("TestLog", "Test message from plain unframed client"); client.Log(Arrays.asList(entry)); socket.close(); } }
From source file:com.facebook.nifty.server.TestPlainClient.java
License:Apache License
@Test public void testPlainFramedClient() throws Exception { try (ScopedNiftyServer server = makeServer()) { TSocket socket = new TSocket("localhost", server.getPort()); socket.open();// w ww .j a v a 2s. c o m socket.setTimeout(1000); TFramedTransport framedTransport = new TFramedTransport(socket); TBinaryProtocol protocol = new TBinaryProtocol(framedTransport); scribe.Client client = new scribe.Client(protocol); LogEntry entry = new LogEntry("TestLog", "Test message from plain framed client"); client.Log(Arrays.asList(entry)); socket.close(); } }
From source file:com.tna.cep.service.thrift.flume.TSaneServerSocket.java
License:Apache License
protected TTransport acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying com.tna.cep.service.thrift.flume.server socket."); }// w ww.j a v a 2s . c o m try { Socket result = serverSocket_.accept(); TSocket result2 = new TBufferedSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
From source file:com.twitter.common.thrift.ThriftConnectionFactory.java
License:Apache License
private void setSocketTimeout(TSocket socket) { if (socketTimeout != null) { socket.setTimeout(socketTimeout.as(Time.MILLISECONDS).intValue()); }//from w w w. j a va2s.c om }
From source file:concrete.server.AbstractServiceTest.java
License:Open Source License
protected void initializeClientFields() throws TTransportException { final TSocket sock = new TSocket("localhost", LISTEN_PORT); // arbitrary//from ww w. j av a 2 s .c om sock.setTimeout(100 * 1000); this.xport = new TFramedTransport(sock); this.xport.open(); // no idea if below is best - stolen from accumulo // when my old method didn't work. final TProtocol protocol = new TCompactProtocol.Factory().getProtocol(this.xport); this.protocol = protocol; }
From source file:ezbake.intent.query.processor.IntentImpalaClient.java
License:Apache License
public List<TRow> queryImpala(String qryString) throws TException { List<TRow> resultRows;/*from w w w .j ava2 s.c o m*/ TSocket transport = new TSocket(host, port); transport.setTimeout(60000); TBinaryProtocol protocol = new TBinaryProtocol(transport); ImpalaHiveServer2Service.Client client = new ImpalaHiveServer2Service.Client.Factory().getClient(protocol); try { transport.open(); } catch (TTransportException e) { appLog.error("open transport exception: ", e); transport.close(); throw new TException(e); } TOpenSessionReq openReq = new TOpenSessionReq(); openReq.setClient_protocol(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1); //openReq.setUsername(username); //openReq.setPassword(password); TOpenSessionResp openResp; org.apache.hive.service.cli.thrift.TStatus status; try { openResp = client.OpenSession(openReq); status = openResp.getStatus(); if (status.getStatusCode() == org.apache.hive.service.cli.thrift.TStatusCode.ERROR_STATUS) { throw new TException("failed open session: " + status.toString()); } } catch (TException e) { appLog.error("open session error: ", e); closeConnection(transport, client, null, null); throw e; } TSessionHandle sessHandle = openResp.getSessionHandle(); TOperationHandle stmtHandle = null; TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, qryString); try { TExecuteStatementResp execResp = client.ExecuteStatement(execReq); status = execResp.getStatus(); if (status.getStatusCode() == org.apache.hive.service.cli.thrift.TStatusCode.ERROR_STATUS) { throw new TException("failed execute statement: " + status.toString()); } stmtHandle = execResp.getOperationHandle(); if (stmtHandle == null) { throw new TException("failed get operation handle"); } } catch (TException e) { appLog.error("ExecuteStatement exception: ", e); closeConnection(transport, client, stmtHandle, sessHandle); throw e; } TFetchResultsReq fetchReq = new TFetchResultsReq(); fetchReq.setOperationHandle(stmtHandle); // fetchReq.setMaxRows(100); // fetchReq.setOrientation(org.apache.hive.service.cli.thrift.TFetchOrientation.FETCH_NEXT); try { TFetchResultsResp resultsResp = client.FetchResults(fetchReq); status = resultsResp.getStatus(); if (status.getStatusCode() == org.apache.hive.service.cli.thrift.TStatusCode.ERROR_STATUS) { throw new TException("failed fetch results: " + status.toString()); } TRowSet resultsSet = resultsResp.getResults(); resultRows = resultsSet.getRows(); appLog.info(String.format("Total rows returned = %d", resultRows.size())); closeConnection(transport, client, stmtHandle, sessHandle); } catch (TException e) { appLog.error("FetchResults exception: ", e); closeConnection(transport, client, stmtHandle, sessHandle); throw e; } return resultRows; }