本文整理匯總了Java中org.apache.thrift.transport.TSocket.setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java TSocket.setTimeout方法的具體用法?Java TSocket.setTimeout怎麽用?Java TSocket.setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.thrift.transport.TSocket
的用法示例。
在下文中一共展示了TSocket.setTimeout方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNativeTransport
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
* 根據rc的設置來確定創建什麽類型的transport;
*
* @param instance
* @return
*/
protected TTransport createNativeTransport(
ServiceInstance<RpcPayload> instance) {
TSocket socket = new TSocket(instance.getAddress(), instance.getPort());
socket.setTimeout(socketTimeout);
RpcPayload server = instance.getPayload();
if ((server == null) || (server.getTransport() == null)
|| (server.getTransport().equals("socket"))) {
return socket;
} else if ("framed-transport".equals(server.getTransport())) {
return new TFramedTransport(socket);
}
// for default, use TSocket;
return socket;
}
示例2: CassandraConnection
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
* Construct an CassandaraConnection with optional authentication.
*
* @param host the host to connect to
* @param port the port to use
* @param username the username to authenticate with (may be null
* for no authentication)
* @param password the password to authenticate with (may be null
* for no authentication)
* @throws Exception if the connection fails
*/
public CassandraConnection(String host, int port,
String username, String password, int timeout) throws Exception {
TSocket socket = new TSocket(host, port);
if (timeout > 0) {
socket.setTimeout(timeout);
}
m_transport = new TFramedTransport(socket);
TProtocol protocol = new TBinaryProtocol(m_transport);
m_client = new Cassandra.Client(protocol);
m_transport.open();
if (!Const.isEmpty(username) && !Const.isEmpty(password)) {
Map<String, String> creds = new HashMap<String, String>();
creds.put("username", username);
creds.put("password", password);
m_client.login(new AuthenticationRequest(creds));
}
}
示例3: makeObject
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
@Override
public PooledObject<TTransport> makeObject(ThriftServer thriftServer) throws Exception {
TSocket tsocket = new TSocket(thriftServer.getHost(), thriftServer.getPort());
tsocket.setTimeout(timeout);
TFramedTransport transport = new TFramedTransport(tsocket);
transport.open();
DefaultPooledObject<TTransport> result = new DefaultPooledObject<TTransport>(transport);
logger.trace("Make new thrift connection: {}:{}", thriftServer.getHost(), thriftServer.getPort());
return result;
}
示例4: NaviScribeDriver
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public NaviScribeDriver(ServerUrlUtil.ServerUrl server, String auth, NaviPoolConfig poolConfig) throws TTransportException,
UnknownHostException, IOException {
super(server, auth, poolConfig);
TSocket sock = new TSocket(new Socket(server.getHost(),
server.getPort()));
sock.setTimeout(poolConfig.getConnectTimeout());
TFramedTransport transport = new TFramedTransport(sock);
TBinaryProtocol protocol = new TBinaryProtocol(transport, false, false);
client = new Client(protocol, protocol);
}
示例5: reconnect
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
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);
}
}
示例6: waitAndReconnect
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
* 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.
*/
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;
}
}
示例7: ThriftClient
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public ThriftClient(Map storm_conf, String host, int port, Integer timeout) throws TTransportException {
try {
//locate login configuration
Configuration login_conf = AuthUtils.GetConfiguration(storm_conf);
//construct a transport plugin
ITransportPlugin transportPlugin = AuthUtils.GetTransportPlugin(storm_conf, login_conf);
//create a socket with server
if(host==null) {
throw new IllegalArgumentException("host is not set");
}
if(port<=0) {
throw new IllegalArgumentException("invalid port: "+port);
}
TSocket socket = new TSocket(host, port);
if(timeout!=null) {
socket.setTimeout(timeout);
}
final TTransport underlyingTransport = socket;
//establish client-server transport via plugin
_transport = transportPlugin.connect(underlyingTransport, host);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
_protocol = null;
if (_transport != null)
_protocol = new TBinaryProtocol(_transport);
}
示例8: connect
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
private void connect() throws TException {
TSocket socket = new TSocket(host, port);
if(timeout!=null) {
socket.setTimeout(timeout);
}
conn = new TFramedTransport(socket);
client = new DistributedRPC.Client(new TBinaryProtocol(conn));
conn.open();
}
示例9: initializeClientFields
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
protected void initializeClientFields() throws TTransportException {
final TSocket sock = new TSocket("localhost", LISTEN_PORT);
// arbitrary
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;
}
示例10: connect
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public synchronized boolean connect(String bgpHost, int bgpPort) {
String msgPiece = "BGP config server at " + bgpHost + ":" + bgpPort;
if (!BgpConfigurationManager.isValidConfigBgpHostPort(bgpHost, bgpPort)) {
LOG.error("Invalid config server host: {}, port: {}", bgpHost, bgpPort);
return false;
}
final int numberOfConnectRetries = 180;
configServerUpdated = false;
RetryOnException connectRetry = new RetryOnException(numberOfConnectRetries);
disconnect();
setConnectTS(System.currentTimeMillis());
do {
if (!isBGPEntityOwner.getAsBoolean()) {
LOG.error("Non Entity BGP owner trying to connect to thrift. Returning");
isConnected = false;
return false;
}
if (configServerUpdated) {
LOG.error("Config server updated while connecting to server {} {}", bgpHost, bgpPort);
isConnected = false;
return false;
}
try {
LOG.error("Trying to connect BGP config server at {} : {}", bgpHost, bgpPort);
TSocket ts = new TSocket(bgpHost, bgpPort, CONNECTION_TIMEOUT);
transport = ts;
transport.open();
ts.setTimeout(THRIFT_TIMEOUT_MILLI);
isConnected = true;
setLastConnectedTS(System.currentTimeMillis());
LOG.error("Connected to BGP config server at {} : {}", bgpHost, bgpPort);
break;
} catch (TTransportException tte) {
LOG.debug("Failed connecting to BGP config server at {} : {}. msg: {}; Exception :",
bgpHost, bgpPort, msgPiece, tte);
if (tte.getCause() instanceof ConnectException) {
LOG.debug("Connect exception. Failed connecting to BGP config server at {} : {}. "
+ "msg: {}; Exception :", bgpHost, bgpPort, msgPiece, tte);
connectRetry.errorOccured();
} else {
//In Case of other exceptions we try only 3 times
connectRetry.errorOccured(60);
}
}
} while (connectRetry.shouldRetry());
if (!connectRetry.shouldRetry()) {
isConnected = false;
return false;
}
bgpClient = new BgpConfigurator.Client(new TBinaryProtocol(transport));
LOG.info("Connected to " + msgPiece);
return true;
}
示例11: DefaultThriftConnectionPoolImpl
import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
* <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);
});
}