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); } }
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; }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
public void setTimeout(int timeout) { if (this.timeout != timeout) { socket.setTimeout(timeout); this.timeout = timeout; } }
public void setTimeout(int timeout) { if (this.timeout != timeout) { socket.setTimeout(timeout); this.timeout = timeout; } }
private void setSocketTimeout(int timeout) { if (socket != null) { socket.setTimeout(timeout); } }
public Connection(String host, int port) throws TTransportException { TSocket socket = new TSocket(host, port); socket.setTimeout(10 * SECONDS); TProtocol protocol = new TBinaryProtocol(socket); client = new Classifier.Client(protocol); this.transport = socket; this.transport.open(); }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
/** * {@inheritDoc} */ @Override public void setup() throws TException { final TSocket socket = new TSocket(host, port); socket.setTimeout(timeout); transport = new TFramedTransport(socket); final TProtocol protocol = new TBinaryProtocol(transport); client = new Client(protocol); transport.open(); }
public synchronized boolean connect(String bgpHost, int bgpPort) { String msgPiece = "BGP config server at "+bgpHost+":"+bgpPort; disconnect(); try { TSocket ts = new TSocket(bgpHost, bgpPort, CONNECTION_TIMEOUT); transport = ts; transport.open(); ts.setTimeout(0); } catch (TTransportException tte) { LOGGER.error("Failed connecting to "+msgPiece+ "; Exception: "+tte); return false; } protocol = new TBinaryProtocol(transport); bgpClient = new BgpConfigurator.Client(protocol); LOGGER.info("Connected to "+msgPiece); return true; }
public boolean isValid(int timeout) throws SQLTimeoutException { if (timeout < 0) throw new SQLTimeoutException(BAD_TIMEOUT); // set timeout socket.setTimeout(timeout * 1000); try { if (isClosed()) { return false; } if (isAlive == null) { isAlive = prepareStatement(currentCqlVersion == "2.0.0" ? IS_VALID_CQLQUERY_2_0_0 : IS_VALID_CQLQUERY_3_0_0); } // the result is not important isAlive.executeQuery().close(); } catch (SQLException e) { return false; } finally { // reset timeout socket.setTimeout(0); } return true; }
public synchronized boolean connect(String bgpHost, int bgpPort) { String msgPiece = "BGP config server at "+bgpHost+":"+bgpPort; this.bgpHost = bgpHost; this.bgpHostPort = bgpPort; disconnect(); setConnectTS(System.currentTimeMillis()); try { TSocket ts = new TSocket(bgpHost, bgpPort, CONNECTION_TIMEOUT); transport = ts; transport.open(); ts.setTimeout(0); isConnected = true; setLastConnectedTS(System.currentTimeMillis()); } catch (TTransportException tte) { LOGGER.info("Failed connecting to " + msgPiece + "; Exception: " + tte); isConnected = false; return false; } protocol = new TBinaryProtocol(transport); bgpClient = new BgpConfigurator.Client(protocol); LOGGER.info("Connected to "+msgPiece); return true; }
/** * <p> * Constructor for DefaultThriftConnectionPoolImpl. * </p> * * @param config a * {@link org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig} * object. */ public DefaultThriftConnectionPoolImpl(GenericKeyedObjectPoolConfig config) { this(config, info -> { TSocket tsocket = new TSocket(info.getHost(), info.getPort()); tsocket.setTimeout(TIMEOUT); return new TFramedTransport(tsocket); }); }
public TestProxyClient(String host, int port, TProtocolFactory protoFactory) throws TTransportException { final TSocket socket = new TSocket(host, port); socket.setTimeout(600000); transport = new TFramedTransport(socket); final TProtocol protocol = protoFactory.getProtocol(transport); proxy = new AccumuloProxy.Client(protocol); transport.open(); }
static Cassandra.Client getClientInternal(String host, int port, boolean isSsl) throws TTransportException { TSocket tSocket = new TSocket(host, port, CassandraConstants.CONNECTION_TIMEOUT_MILLIS); tSocket.open(); tSocket.setTimeout(CassandraConstants.SOCKET_TIMEOUT_MILLIS); if (isSsl) { boolean success = false; try { SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket socket = (SSLSocket) factory.createSocket(tSocket.getSocket(), host, port, true); tSocket = new TSocket(socket); success = true; } catch (IOException e) { throw new TTransportException(e); } finally { if (!success) { tSocket.close(); } } } TTransport tFramedTransport = new TFramedTransport(tSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES); TProtocol protocol = new TBinaryProtocol(tFramedTransport); Cassandra.Client client = new Cassandra.Client(protocol); return client; } @Override
/** * 这个地方创建连接的时候,如果创建失败,重试一次,还不行则抛出异常,把该节点暂时移除 * * @return * @throws Exception */ @Override public PooledObject<TTransport> makeObject() throws Exception { TTransport transport = null; Exception ex = null; int retryConn = 1; do { try { transport = new TSocket(providerInfo.getIp(), providerInfo.getPort(), timeout); transport.open(); ((TSocket) transport).setTimeout(timeout); return new DefaultPooledObject<TTransport>(transport); } catch (Exception e) { ex = e; } } while (retryConn-- > 0); LOGGER.error("make transport object fail.e:", ex); throw new OureaConnCreateException("make transport object fail." + ex.getMessage()); }
transport.setTimeout(999999999); TBinaryProtocol protocol = new TBinaryProtocol(transport); TCLIService.Client client = new TCLIService.Client(protocol);
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; }