public ThriftHiveMetastoreClient(TTransport transport) { this.transport = requireNonNull(transport, "transport is null"); this.client = new ThriftHiveMetastore.Client(new TBinaryProtocol(transport)); }
protected static TProtocol newProtocol(URL url, ChannelBuffer buffer) throws IOException { String protocol = url.getParameter(ThriftConstants.THRIFT_PROTOCOL_KEY, ThriftConstants.DEFAULT_PROTOCOL); if (ThriftConstants.BINARY_THRIFT_PROTOCOL.equals(protocol)) { return new TBinaryProtocol(new TIOStreamTransport(new ChannelBufferOutputStream(buffer))); } throw new IOException("Unsupported protocol type " + protocol); }
protected static TProtocol newProtocol(URL url, ChannelBuffer buffer) throws IOException { String protocol = url.getParameter(ThriftConstants.THRIFT_PROTOCOL_KEY, ThriftConstants.DEFAULT_PROTOCOL); if (ThriftConstants.BINARY_THRIFT_PROTOCOL.equals(protocol)) { return new TBinaryProtocol(new TIOStreamTransport(new ChannelBufferOutputStream(buffer))); } throw new IOException("Unsupported protocol type " + protocol); }
@Override public void rewind() throws IOException { _bufferIn = RecordReaderUtils.getFileBufferStream(_dataFile); _binaryIn = new TBinaryProtocol(new TIOStreamTransport(_bufferIn)); }
protected TProtocol createThriftProtocol(TTransport transport) { switch(this.protocol) { case BINARY: return new TBinaryProtocol(transport); case JSON: return new TJSONProtocol(transport); case SIMPLE_JSON: return new TSimpleJSONProtocol(transport); default: throw new IllegalArgumentException("Unknown Thrift Protocol."); } } }
public ThriftRecordReader(File dataFile, Schema schema, ThriftRecordReaderConfig recordReaderConfig) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { this._schema = schema; this._dataFile = dataFile; this._recordReaderConfig = recordReaderConfig; this._thriftClass = initThriftInstanceCreator(); this._bufferIn = RecordReaderUtils.getFileBufferStream(dataFile); this._binaryIn = new TBinaryProtocol(new TIOStreamTransport(_bufferIn)); this._fieldNameToIndexMap = new HashMap(); TBase t = this._thriftClass.newInstance(); int index = 1; TFieldIdEnum fieldIdEnum = null; do { fieldIdEnum = t.fieldForId(index); if (fieldIdEnum != null) { _fieldNameToIndexMap.put(fieldIdEnum.getFieldName(), index); } index = index + 1; } while (fieldIdEnum != null); }
public static Message parseMessage(byte[] data) throws TException { Message msg = new Message(); TMemoryInputTransport transport = new TMemoryInputTransport(data); TBinaryProtocol protocol = new TBinaryProtocol(transport); msg.read(protocol); return msg; }
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
@Override public Iface apply(TTransport transport) { TProtocol protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mprotocol = new TMultiplexedProtocol( protocol, KaaThriftService.OPERATIONS_SERVICE.getServiceName() ); return new OperationsThriftService.Client(mprotocol); } }).build(backends);
public synchronized void reconnect() { close(); try { TSocket socket = new TSocket(host, port); if (timeout != null) { socket.setTimeout(timeout); } else { // @@@ Todo // set the socket default Timeout as xxxx } // 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, asUser); } catch (IOException ex) { throw new RuntimeException(ex); } _protocol = null; if (_transport != null) { _protocol = new TBinaryProtocol(_transport); } }
/** * Connect to Thrift Server. * * @throws TException the t exception */ public void connect() throws TException { transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, KaaThriftService.KAA_NODE_SERVICE.getServiceName()); client = new CliClient(mp); transport.open(); remoteServerName = client.serverName(); remoteMode = true; }
@Override public Pair<THBaseService.Client, TTransport> getClient() throws IOException { Preconditions.checkArgument(connection.getHost().startsWith("http"), "http client host must start with http or https"); String url = connection.getHost() + ":" + connection.getPort(); try { THttpClient httpClient = new THttpClient(url, connection.getHttpClient()); for (Map.Entry<String, String> header : customHeader.entrySet()) { httpClient.setCustomHeader(header.getKey(), header.getValue()); } httpClient.open(); TProtocol prot = new TBinaryProtocol(httpClient); THBaseService.Client client = new THBaseService.Client(prot); return new Pair<>(client, httpClient); } catch (TTransportException e) { throw new IOException(e); } } }
public String toBinaryString() throws IOException { org.apache.hadoop.hive.ql.plan.api.Query q = getQueryPlan(); TMemoryBuffer tmb = new TMemoryBuffer(q.toString().length() * 5); TBinaryProtocol oprot = new TBinaryProtocol(tmb); try { q.write(oprot); } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); return q.toString(); } byte[] buf = new byte[tmb.length()]; tmb.read(buf, 0, tmb.length()); return new String(buf); // return getQueryPlan().toString(); }
public String toBinaryString() throws IOException { org.apache.hadoop.hive.ql.plan.api.Query q = getQueryPlan(); TMemoryBuffer tmb = new TMemoryBuffer(q.toString().length() * 5); TBinaryProtocol oprot = new TBinaryProtocol(tmb); try { q.write(oprot); } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); return q.toString(); } byte[] buf = new byte[tmb.length()]; tmb.read(buf, 0, tmb.length()); return new String(buf); // return getQueryPlan().toString(); }
@Override public Pair<THBaseService.Client, TTransport> getClient() throws IOException { TSocket sock = new TSocket(connection.getHost(), connection.getPort()); sock.setSocketTimeout(connection.getOperationTimeout()); sock.setConnectTimeout(connection.getConnectTimeout()); TTransport tTransport = sock; if (connection.isFramed()) { tTransport = new TFramedTransport(tTransport); } try { sock.open(); } catch (TTransportException e) { throw new IOException(e); } TProtocol prot; if (connection.isCompact()) { prot = new TCompactProtocol(tTransport); } else { prot = new TBinaryProtocol(tTransport); } THBaseService.Client client = new THBaseService.Client(prot); return new Pair<>(client, tTransport); }
protected void talkToThriftServer() throws Exception { TSocket sock = new TSocket(InetAddress.getLocalHost().getHostName(), port); TTransport transport = sock; if (specifyFramed || implType.isAlwaysFramed) { transport = new TFramedTransport(transport); } sock.open(); try { TProtocol prot; if (specifyCompact) { prot = new TCompactProtocol(transport); } else { prot = new TBinaryProtocol(transport); } Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { sock.close(); } }
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
@Override protected void talkToThriftServer(String url, int customHeaderSize) throws Exception { // Close httpClient and THttpClient automatically on any failures try ( CloseableHttpClient httpClient = createHttpClient(); THttpClient tHttpClient = new THttpClient(url, httpClient) ) { tHttpClient.open(); if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString()); } TProtocol prot = new TBinaryProtocol(tHttpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated) { TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } }