当前位置: 首页>>代码示例>>Java>>正文


Java TSocket.setTimeout方法代码示例

本文整理汇总了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;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:23,代码来源:AbstractTransportPool.java

示例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));
  }
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:31,代码来源:CassandraConnection.java

示例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;
}
 
开发者ID:cyfonly,项目名称:ThriftJ,代码行数:13,代码来源:ThriftConnectionFactory.java

示例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);
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:12,代码来源:NaviScribeDriver.java

示例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);
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:35,代码来源:ThriftClient.java

示例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;
  }
}
 
开发者ID:cloudera,项目名称:RecordServiceClient,代码行数:19,代码来源:RecordServiceWorkerClient.java

示例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);
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:31,代码来源:ThriftClient.java

示例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();
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:10,代码来源:DRPCClient.java

示例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;
}
 
开发者ID:hltcoe,项目名称:concrete-java,代码行数:12,代码来源:AbstractServiceTest.java

示例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;
}
 
开发者ID:opendaylight,项目名称:netvirt,代码行数:59,代码来源:BgpRouter.java

示例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);
    });
}
 
开发者ID:ngayngo9x,项目名称:q-thrift,代码行数:17,代码来源:DefaultThriftConnectionPoolImpl.java


注:本文中的org.apache.thrift.transport.TSocket.setTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。