List of usage examples for org.apache.thrift.transport TSocket close
public void close()
From source file:client.controller.ThriftClient.java
public static void ProcessClientRequest(String host, int port, String request, String path, int version, byte[] data) { try {/*from w ww . j ava 2s .c o m*/ TSocket transport = new TSocket(host, port); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); ByteBuffer newData = ByteBuffer.wrap(data); // List<String> partiotionedPath = new ArrayList<>(Arrays.asList(path.split("/"))); // if (partiotionedPath.isEmpty()) { // partiotionedPath.add("/"); // } else { // partiotionedPath.set(0, "/"); // } FileSystem.Client client = new FileSystem.Client(protocol); String result = ""; switch (request) { case "ADD": result = client.addFile(path, newData); break; case "GET": result = client.getFile(path); break; case "LIST": result = client.listChildren(path); break; case "UPDATE": result = client.updateFile(path, newData, false, version); break; case "DELETE": result = client.deleteFile(path, false, version); if (result == null) { result = "The file " + path + " does not exist!"; } break; case "DELETE+VERSION": result = client.deleteFile(path, true, version); if (result == null) { result = "The file " + path + " does not exist or it has a different version!"; } break; case "UPDATE+VERSION": result = client.updateFile(path, newData, true, version); if (result == null) { result = "The file " + path + " does not exist or it has a different version!"; } break; default: result = "Error!"; break; } //result = client.hi(); String[] a = null; new ClientResultsView("").show(result); //System.out.println("Return from server: " + result); transport.close(); } catch (TException e) { e.printStackTrace(); } }
From source file:cn.lhfei.spark.hive.HiveThriftClient.java
License:Apache License
public static void main(String[] args) { try {/*from ww 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 {//from w w w. j a v a 2 s. c om 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.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 ww. j a v a 2 s. com 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();/*www . j a va 2 s. c om*/ 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.facebook.swift.service.TestThriftService.java
License:Apache License
private ResultCode logThrift(int port, List<LogEntry> messages) throws TException { TSocket socket = new TSocket("localhost", port); socket.open();//w ww.j a v a2s.com try { TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket)); return new scribe.Client(tp).Log(messages); } finally { socket.close(); } }
From source file:com.facebook.swift.service.TestThriftSslService.java
License:Apache License
private ResultCode logThrift(int port, List<LogEntry> messages) throws TException, IOException, NoSuchAlgorithmException, KeyManagementException { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null); Socket sslSocket = ctx.getSocketFactory().createSocket("localhost", port); TSocket socket = new TSocket(sslSocket); try {/*from www. jav a 2 s . c o m*/ TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket)); return new scribe.Client(tp).Log(messages); } finally { socket.close(); } }
From source file:com.flaptor.indextank.rpc.FrontendManagerClient.java
License:Apache License
public void saveInsight(String indexCode, String insightCode, String jsonValue) { TSocket transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); FrontendManager.Client client = new FrontendManager.Client(protocol); try {/*from w w w . ja va 2 s. com*/ transport.open(); client.save_insight(indexCode, insightCode, jsonValue); transport.close(); } catch (TTransportException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } }
From source file:com.flaptor.indextank.rpc.FrontendManagerClient.java
License:Apache License
public List<IndexInfo> listIndexes() { TSocket transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); FrontendManager.Client client = new FrontendManager.Client(protocol); try {// ww w . java2 s.c o m transport.open(); List<IndexInfo> indexes = client.list_indexes(); transport.close(); return indexes; } catch (TTransportException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } }
From source file:com.flaptor.indextank.rpc.IndexerClient.java
License:Apache License
@Override public void promoteResult(String docid, String query) { TSocket transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); Indexer.Client client = new Indexer.Client(protocol); try {/*from w w w . ja v a2 s . c o m*/ transport.open(); client.promoteResult(docid, query); transport.close(); } catch (IndextankException e) { throw new RuntimeException(e); } catch (TTransportException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } }