includeProtocols, excludeCipherSuites, includeCipherSuites); } else { tsocket = new TSocket(hostname, port); if (!transport.isOpen()) { transport.open(); client = new ThriftSourceProtocol.Client(new TBinaryProtocol(transport)); } else { LOGGER.info("Using TCompactProtocol");
TBinaryProtocol protocol = new TBinaryProtocol(transport); protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeString(inv.getAttachment(Constants.PATH_KEY)); protocol.writeI64(request.getId()); protocol.getTransport().flush(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally {
TIOStreamTransport transport = new TIOStreamTransport(new ChannelBufferInputStream(buffer)); TBinaryProtocol protocol = new TBinaryProtocol(transport); transport.read(bytes, 0, 4); magic = protocol.readI16(); messageLength = protocol.readI32(); throw new IOException(e.getMessage(), e);
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 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(); } }
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); LOG.info("Connecting to " + host + ":" + port); transport = new TSocket(host, port); ((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; }
private static Cassandra.Client getRawClient(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws TException { TSocket thriftSocket = new TSocket(addr.getHostString(), addr.getPort(), config.socketTimeoutMillis()); thriftSocket.open(); try { thriftSocket.getSocket().setKeepAlive(true); thriftSocket.getSocket().setSoTimeout(config.socketQueryTimeoutMillis()); } catch (SocketException e) { new TFramedTransport(thriftSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES); TProtocol protocol = new TBinaryProtocol(thriftFramedTransport); Cassandra.Client client = new Cassandra.Client(protocol); login(client, config.credentials().get()); } catch (TException e) { client.getOutputProtocol().getTransport().close(); log.error("Exception thrown attempting to authenticate with config provided credentials", e); throw e;
/** * 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 { 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); }
public byte[] createPayload(final List<ThriftField> thriftFieldList) throws TException { final ByteArrayOutputStream payloadOutputStream = new ByteArrayOutputStream(); final TProtocol payloadProtocol = new TBinaryProtocol(new TIOStreamTransport(payloadOutputStream)); serialize(payloadProtocol, thriftFieldList); payloadProtocol.getTransport().close(); return payloadOutputStream.toByteArray(); }
this.endpointPort = endpointPort; constructorT = classT.getConstructor(TProtocol.class, TProtocol.class); transport = new TSocket(endpointHost, endpointPort); LOG.debug("ThriftClient sokcet to " + endpointHost + ":" + endpointPort + " created."); TProtocol protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, kaaThriftService.getServiceName()); client = constructorT.newInstance(mp, mp);
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); } }
public void sendRequest() throws IOException, TException { TProtocol out = new TBinaryProtocol(new TIOStreamTransport(socketToServer.getOutputStream())); out.writeMessageBegin(new TMessage("dummy", TMessageType.CALL, 0)); out.writeStructBegin(new TStruct("dummy_args")); out.writeFieldStop(); out.writeStructEnd(); out.writeMessageEnd(); out.getTransport().flush(); }
public ThriftHiveMetastoreClient(TTransport transport) { this.transport = requireNonNull(transport, "transport is null"); this.client = new ThriftHiveMetastore.Client(new TBinaryProtocol(transport)); }
private void reloadClient() { transport = new TSocket(readerHost, readerPort); protocol = new TBinaryProtocol(transport); client = new LogReader.Client(protocol); try { transport.open(); } catch (TTransportException e) { } }
public String readString() throws TException { int size = readI32(); checkStringReadLength(size); if (trans_.getBytesRemainingInBuffer() >= size) { try { String s = new String(trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8"); trans_.consumeBuffer(size); return s; } catch (UnsupportedEncodingException e) { throw new TException("JVM DOES NOT SUPPORT UTF-8"); } } return readStringBody(size); }
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 void writeString(String str) throws TException { try { byte[] dat = str.getBytes("UTF-8"); writeI32(dat.length); trans_.write(dat, 0, dat.length); } catch (UnsupportedEncodingException uex) { throw new TException("JVM DOES NOT SUPPORT UTF-8"); } }
public ByteBuffer readBinary() throws TException { int size = readI32(); checkReadLength(size); if (trans_.getBytesRemainingInBuffer() >= size) { ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size); trans_.consumeBuffer(size); return bb; } byte[] buf = new byte[size]; trans_.readAll(buf, 0, size); return ByteBuffer.wrap(buf); }
public ByteBuffer readBinary() throws TException { int size = readI32(); checkStringReadLength(size); if (trans_.getBytesRemainingInBuffer() >= size) { ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size); trans_.consumeBuffer(size); return bb; } byte[] buf = new byte[size]; trans_.readAll(buf, 0, size); return ByteBuffer.wrap(buf); }